Skip to content

Commit

Permalink
added support and directions for usb-iss direct connection from Danci…
Browse files Browse the repository at this point in the history
…ngQuanta
  • Loading branch information
dhhagan committed Oct 25, 2016
1 parent e07bdfb commit b971d12
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
52 changes: 46 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Welcome to py-opc's documentation!
==================================

**py-opc** is a python module that enables one to use easily operate the Alphasense
OPC-N2 optical particle counter through a Raspberry Pi over the SPI bus. It was originally
designed using a Rapsberry Pi 2 Model B and Python3.5; however, it should work on other versions
as well.
OPC-N2 optical particle counter through a Raspberry Pi over the SPI bus using either a SPI-USB converter
or directly over the GPIO pins. It was originally designed using a Rapsberry Pi 2 Model B
and Python3.5; however, it should work on other versions as well.

There are a variety of OPC Models and firmware versions from Alphasense; a table documenting which ones
are supported will be added. If you own an OPC-N2 with a firmware version that has not been tested, please
Expand All @@ -18,26 +18,43 @@ do so and submit as an issue on the GitHub repository.
Installation
------------

You can install this package using ``pip``::
You can install this package directly from pypi using ``pip``::

pip install py-opc

You can upgrade by issuing the command::

pip install py-opc --upgrade

If interested in testing a development version, clone (or download) the repository and then install as follows::

python setup.py develop


Requirements
------------

The following packages are required:
One of the following packages is required:

* py-spidev_
* pyusbiss_

.. _py-spidev: https://github.com/doceme/py-spidev
.. _pyusbiss: https://github.com/DancingQuanta/pyusbiss

Use the spidev library if you are planning to connect to OPC to the microcontroller via the GPIO pins. Use
the pyusbiss library if connecting via a SPI-USB adapter.


Setting Up the Raspberry Pi
---------------------------

There are now two simple ways to connect your Alphasense OPC to a Raspberry Pi (or similar device): directly via the GPIO
pins, or using a SPI-USB converter.

Connecting via GPIO
~~~~~~~~~~~~~~~~~~~

If you are not familiar with setting up a Raspberry Pi to be used as a SPI device,
here are a couple of great tutorials: RPi_, Drogon_, and Hensley_. A few important things
to note:
Expand All @@ -64,6 +81,14 @@ are stated below:
.. _Drogon: https://projects.drogon.net/understanding-spi-on-the-raspberry-pi/
.. _Hensley: http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html

Connecting via a USB-SPI Converter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To connect your OPC to the Raspberry Pi directly, you can use a SPI-USB converter. They can be found
fairly inexpensively online or directly from Alphasense.

You will then be able to directly connect the OPC to your Raspberry Pi's USB port.

Getting Help
------------

Expand Down Expand Up @@ -99,6 +124,10 @@ Examples

Setting up the SPI Connection
-----------------------------

Using the SpiDev Library via GPIO Pins
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

import spidev
Expand All @@ -112,6 +141,17 @@ Setting up the SPI Connection
spi.mode = 1
spi.max_speed_hz = 500000

Using the pyusbiss Library via USB Port
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

import usbiss
import opc

# Open a SPI connection
spi = usbiss.USBISS("/dev/ttyACM0", 'spi', spi_mode = 2, freq = 500000)


Initiating the OPCN2
--------------------
Expand Down Expand Up @@ -142,7 +182,7 @@ API Reference
.. module:: opc
.. autoclass:: OPC
:members: _16bit_unsigned, _calculate_float, read_info_string, ping, _calculate_mtof,
_calculate_temp, _calculate_pressure, _calculate_bin_boundary, _calculate_period, ping
_calculate_temp, _calculate_pressure, lookup_bin_boundary _calculate_bin_boundary, _calculate_period, ping
.. autoclass:: OPCN1
:members: on, off, read_gsc_sfr, read_bin_boundaries, write_gsc_sfr, read_bin_particle_density,
write_bin_particle_density, read_histogram
Expand Down
8 changes: 4 additions & 4 deletions opc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
from .lookup_table import OPC_LOOKUP

from time import sleep
import spidev
import struct
import warnings
import re

from .exceptions import firmware_error_msg


__all__ = ['OPCN2', 'OPCN1']
__version__ = get_distribution('py-opc').version

class OPC(object):
"""Generic class for any Alphasense OPC. Provides the common methods and calculations
for each OPC.
:param spi_connection: spidev.SpiDev connection
:param spi_connection: spidev.SpiDev or usbiss.USBISS connection
:param debug: Set true to print data to console while running
:param model: Model number of the OPC ('N1' or 'N2') set by the parent class
:raises: opc.exceptions.SpiConnectionError
:type spi_connection: spidev.SpiDev
:type spi_connection: spidev.SpiDev or usbiss.USBISS
:type debug: boolean
:type model: string
Expand All @@ -48,7 +48,7 @@ def __init__(self, spi_connection, **kwargs):
self.firmware = {'major': None, 'minor': None, 'version': None}
self.model = kwargs.get('model', 'N2')

# Check to make sure the connection is a valid SpiDev instance
# Check to make sure the connection has the xfer attribute
msg = ("The SPI connection must be a valid SPI master with "
"transfer function 'xfer'")
assert hasattr(spi_connection, 'xfer'), msg
Expand Down

0 comments on commit b971d12

Please sign in to comment.