Skip to content

Commit

Permalink
Improving docs, adding products to the related products API
Browse files Browse the repository at this point in the history
  • Loading branch information
jposada202020 committed Apr 17, 2021
1 parent 48b57ec commit 5abc81d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
18 changes: 16 additions & 2 deletions adafruit_pm25/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
Works with most (any?) Plantower UART or I2C interfaced PM2.5 sensor.
* `PM2.5 Air Quality Sensor and Breadboard Adapter Kit - PMS5003
<https://www.adafruit.com/product/3686>`_
* `PM2.5 Air Quality Sensor with I2C Interface - PMSA003I
<https://www.adafruit.com/product/4505>`_
* `Adafruit PMSA003I Air Quality Breakout
<https://www.adafruit.com/product/4632>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
Expand All @@ -33,8 +42,13 @@


class PM25:
"""Super-class for generic PM2.5 sensors. Subclasses must implement
_read_into_buffer to fill self._buffer with a packet of data"""
"""
Super-class for generic PM2.5 sensors.
.. note::
Subclasses must implement _read_into_buffer to fill self._buffer with a packet of data
"""

def __init__(self):
# rad, ok make our internal buffer!
Expand Down
39 changes: 39 additions & 0 deletions adafruit_pm25/i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
**Hardware:**
* `PM2.5 Air Quality Sensor with I2C Interface - PMSA003I
<https://www.adafruit.com/product/4505>`_
* `Adafruit PMSA003I Air Quality Breakout
<https://www.adafruit.com/product/4632>`_
Works with most (any?) Plantower I2C interfaced PM2.5 sensor.
**Software and Dependencies:**
Expand All @@ -36,6 +43,38 @@
class PM25_I2C(PM25):
"""
A module for using the PM2.5 Air quality sensor over I2C
:param i2c_bus: The `busio.I2C` object to use.
:param ~microcontroller.Pin reset_pin: Pin use to reset the sensor. Defaults to `None`
:param int address: The I2C address of the device. Defaults to :const:`0x12`
**Quickstart: Importing and using the PMSA003I Air quality sensor**
Here is one way of importing the `PM25_I2C` class so you can use it with the name ``pm25``.
First you will need to import the libraries to use the sensor
.. code-block:: python
import board
import busio
from adafruit_pm25.i2c import PM25_I2C
Once this is done you can define your `busio.I2C` object and define your sensor object
.. code-block:: python
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
reset_pin = None
pm25 = PM25_I2C(i2c, reset_pin)
Now you have access to the air quality data using the class function
`adafruit_pm25.PM25.read`
.. code-block:: python
aqdata = pm25.read()
"""

def __init__(self, i2c_bus, reset_pin=None, address=0x12):
Expand Down
41 changes: 38 additions & 3 deletions adafruit_pm25/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
Works with most (any?) Plantower UART or I2C interfaced PM2.5 sensor.
* `PM2.5 Air Quality Sensor and Breadboard Adapter Kit - PMS5003
<https://www.adafruit.com/product/3686>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
Expand All @@ -33,6 +37,40 @@
class PM25_UART(PM25):
"""
A driver for the PM2.5 Air quality sensor over UART
:param ~busio.UART uart: The `busio.UART` object to use.
:param ~microcontroller.Pin reset_pin: Pin use to reset the sensor.
Defaults to `None`
**Quickstart: Importing and using the PMS5003 Air quality sensor**
Here is one way of importing the `PM25_UART` class so you
can use it with the name ``pm25``.
First you will need to import the libraries to use the sensor
.. code-block:: python
import board
import busio
from adafruit_pm25.uart import PM25_UART
Once this is done you can define your `busio.UART` object and define
your sensor object
.. code-block:: python
uart = busio.UART(board.TX, board.RX, baudrate=9600)
reset_pin = None
pm25 = PM25_UART(uart, reset_pin)
Now you have access to the air quality data using the class function
`adafruit_pm25.PM25.read`
.. code-block:: python
aqdata = pm25.read()
"""

def __init__(self, uart, reset_pin=None):
Expand Down Expand Up @@ -61,6 +99,3 @@ def _read_into_buffer(self):
if not remain or len(remain) != 31:
raise RuntimeError("Unable to read from PM2.5 (incomplete frame)")
self._buffer[1:] = remain


# print([hex(i) for i in self._buffer])
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Table of Contents
.. toctree::
:caption: Related Products

PM2.5 Air Quality Sensor with I2C Interface - PMSA003I <https://www.adafruit.com/product/4505>

Adafruit PMSA003I Air Quality Breakout <https://www.adafruit.com/product/4632>

PM2.5 Air Quality Sensor and Breadboard Adapter Kit - PMS5003 <https://www.adafruit.com/product/3686>

.. toctree::
:caption: Other Links

Expand Down

0 comments on commit 5abc81d

Please sign in to comment.