Giter Site home page Giter Site logo

py-opc's Introduction

status Build Status PyPI version Coverage Status DOI

py-opc

Python library for operating the Alphasense OPC-N2 Optical Particle Counter using a Raspberry Pi (or other linux device). Full documentation can be found here.

Dependencies

One of the following, depending on whether you use GPIO pins or a SPI-USB adapter:

  1. py-spidev - for those using GPIO pins
  2. pyusbiss - for those using a SPI-USB adapter (python3+ only)

Additional Dependencies for Local Development

If you wish to build the local documentation or run unittests, there are a few additional dependencies that are required including:

  • sphinx
  • sphinx_rtd_theme
  • mock

The complete list can be found in requirements-dev.txt.

Installation

For use on the Raspberry Pi (or any other linux device?), install via pip:

$ pip install py-opc [--upgrade]

If you are using the SPI-USB adapter only, you will also need to install pyusbiss. This can be done as follows:

$ pip install pyusbiss

Depending on your python setup, you may need to use pip3 instead of pip to install for python3+:

$ pip3 install pyusbiss

If you are using the GPIO pins to communicate with the OPC-N2, you must download the requirement py-spidev as follows:

$ pip install git+https://github.com/doceme/py-spidev.git

License

This library is licensed under the MIT license. The full text of the license can be found in this repository at LICENSE.txt.

Documentation

Full documentation can be found here.

You can also build the documentation by navigating to the docs directory and issuing the command:

$ make html

Sample Script / Getting Started

To quickly get up and running, follow one of the two examples:

GPIO-connected OPC-N2

Use if you are using the GPIO pins in conjunction with py-spidev

import spidev
import opc
from time import sleep

spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
spi.max_speed_hz = 500000

alphasense = opc.OPCN2(spi)

# Turn the opc ON
alphasense.on()

sleep(1)

# Read the information string
print (alphasense.read_info_string())

# Read the histogram
print (alphasense.histogram())

# Turn the opc OFF
alphasense.off()

SPI-USB Adapter with OPC-N2

Use this approach if you have connected your RPi to the OPC-N2 via a SPI-USB adapter.

NOTE: Currently, this method is only supported on python3+ due to limitations in the pyusbiss library.

from usbiss.spi import SPI
import opc
from time import sleep

# Build the connector
spi = SPI("/dev/ttyACM0")

# Set the SPI mode and clock speed
spi.mode = 1
spi.max_speed_hz = 500000

alpha = opc.OPCN2(spi)

# Turn on the device
alpha.on()

sleep(1)

# read the information string
print (repr(alpha.read_info_string()))

# Read the histogram
alpha.histogram()

# Turn the device off
alpha.off()

py-opc's People

Contributors

dhhagan avatar florentinbulotaq avatar dancingquanta avatar arfon avatar jtrochim avatar gitter-badger avatar rach8cww avatar

Stargazers

Abhijeet Bhatikar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.