-
Notifications
You must be signed in to change notification settings - Fork 18
Library to package #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
57539b8
Moving file into folder as __init__ and take two copies
dglaude 9e6107b
Add duplication of __init__.py (history lost)
dglaude 583195b
Splitting into file per connectivity
dglaude d369fb5
Separate simpletest for uart and i2c + fix time import in I2C
dglaude 2800315
Black cleaning
dglaude 55bc3d9
Pylint on import and what should be where
dglaude ae2a64b
Merge back I2C and UART simpletest to avoid changing the docs
dglaude 9d0c95c
Update adafruit_pm25/i2c.py
dglaude 483b588
Update adafruit_pm25/i2c.py
dglaude 8d4b126
Update adafruit_pm25/i2c.py
dglaude 64ecd81
Update adafruit_pm25/uart.py
dglaude 21906e9
Update adafruit_pm25/uart.py
dglaude fc851a1
Update uart.py
dglaude d13b66f
Update uart.py
dglaude cbafdd0
Update pm25_simpletest.py
dglaude acdd32e
Update __init__.py
dglaude 4f320c6
Update __init__.py
dglaude c691261
Update i2c.py
dglaude dfea3ae
Update uart.py
dglaude 5856190
Update pm25_simpletest.py
dglaude 1915594
Update api.rst
dglaude e1560c9
Update setup.py
dglaude 29dad18
Temporary fix for pylint 2.6.0 upgrade on GitHub
dglaude b22bf69
Adapting to W0707 pylint message
dglaude 4c71550
Undo hiding the pylint issue
dglaude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 ladyada for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_pm25.i2c` | ||
================================================================================ | ||
|
||
I2C module for CircuitPython library for PM2.5 Air Quality Sensors | ||
|
||
|
||
* Author(s): ladyada | ||
|
||
Implementation Notes | ||
-------------------- | ||
|
||
**Hardware:** | ||
|
||
Works with most (any?) Plantower I2C interfaced PM2.5 sensor. | ||
|
||
**Software and Dependencies:** | ||
|
||
* Adafruit CircuitPython firmware for the supported boards: | ||
https://github.com/adafruit/circuitpython/releases | ||
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice | ||
|
||
""" | ||
|
||
# imports | ||
import time | ||
from digitalio import Direction | ||
from adafruit_bus_device.i2c_device import I2CDevice | ||
from . import PM25 | ||
|
||
|
||
class PM25_I2C(PM25): | ||
""" | ||
A module for using the PM2.5 Air quality sensor over I2C | ||
""" | ||
|
||
def __init__(self, i2c_bus, reset_pin=None, address=0x12): | ||
if reset_pin: | ||
# Reset device | ||
reset_pin.direction = Direction.OUTPUT | ||
reset_pin.value = False | ||
time.sleep(0.01) | ||
reset_pin.value = True | ||
# it takes at least a second to start up | ||
time.sleep(1) | ||
|
||
for _ in range(5): # try a few times, it can be sluggish | ||
try: | ||
self.i2c_device = I2CDevice(i2c_bus, address) | ||
break | ||
except ValueError: | ||
time.sleep(1) | ||
continue | ||
else: | ||
raise RuntimeError("Unable to find PM2.5 device") | ||
super().__init__() | ||
|
||
def _read_into_buffer(self): | ||
with self.i2c_device as i2c: | ||
try: | ||
i2c.readinto(self._buffer) | ||
except OSError as err: | ||
raise RuntimeError("Unable to read from PM2.5 over I2C") from err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 ladyada for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_pm25.uart` | ||
================================================================================ | ||
|
||
UART module for CircuitPython library for PM2.5 Air Quality Sensors | ||
|
||
|
||
* Author(s): ladyada | ||
|
||
Implementation Notes | ||
-------------------- | ||
|
||
**Hardware:** | ||
|
||
Works with most (any?) Plantower UART or I2C interfaced PM2.5 sensor. | ||
dglaude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**Software and Dependencies:** | ||
|
||
* Adafruit CircuitPython firmware for the supported boards: | ||
https://github.com/adafruit/circuitpython/releases | ||
|
||
""" | ||
|
||
import time | ||
from digitalio import Direction | ||
from . import PM25 | ||
|
||
|
||
class PM25_UART(PM25): | ||
""" | ||
A driver for the PM2.5 Air quality sensor over UART | ||
""" | ||
|
||
def __init__(self, uart, reset_pin=None): | ||
if reset_pin: | ||
# Reset device | ||
reset_pin.direction = Direction.OUTPUT | ||
reset_pin.value = False | ||
time.sleep(0.01) | ||
reset_pin.value = True | ||
# it takes at least a second to start up | ||
time.sleep(1) | ||
|
||
self._uart = uart | ||
super().__init__() | ||
|
||
def _read_into_buffer(self): | ||
while True: | ||
b = self._uart.read(1) | ||
if not b: | ||
raise RuntimeError("Unable to read from PM2.5 (no start of frame)") | ||
if b[0] == 0x42: | ||
break | ||
self._buffer[0] = b[0] # first byte and start of frame | ||
|
||
remain = self._uart.read(31) | ||
if not remain or len(remain) != 31: | ||
raise RuntimeError("Unable to read from PM2.5 (incomplete frame)") | ||
for i in range(31): | ||
self._buffer[i + 1] = remain[i] | ||
# print([hex(i) for i in self._buffer]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.