From 57539b8c0e90565a2ab8b32d08cc6b8f367a64a2 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 14:10:45 +0200 Subject: [PATCH 01/25] Moving file into folder as __init__ and take two copies --- adafruit_pm25.py => adafruit_pm25/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename adafruit_pm25.py => adafruit_pm25/__init__.py (100%) diff --git a/adafruit_pm25.py b/adafruit_pm25/__init__.py similarity index 100% rename from adafruit_pm25.py rename to adafruit_pm25/__init__.py From 9e6107bd6a82fd5cc846b152708156e12a427bf7 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 14:13:43 +0200 Subject: [PATCH 02/25] Add duplication of __init__.py (history lost) --- adafruit_pm25/i2c.py | 188 ++++++++++++++++++++++++++++++++++++++++++ adafruit_pm25/uart.py | 188 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 376 insertions(+) create mode 100644 adafruit_pm25/i2c.py create mode 100644 adafruit_pm25/uart.py diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py new file mode 100644 index 0000000..7ee24a4 --- /dev/null +++ b/adafruit_pm25/i2c.py @@ -0,0 +1,188 @@ +# 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` +================================================================================ + +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. + +**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 +import struct +from adafruit_bus_device.i2c_device import I2CDevice +from digitalio import Direction + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PM25.git" + + +class PM25: + """Super-class for generic PM2.5 sensors. Subclasses must implement + _read_into_buffer to fill self._buffer with a packet of data""" + + def __init__(self): + # rad, ok make our internal buffer! + self._buffer = bytearray(32) + self.aqi_reading = { + "pm10 standard": None, + "pm25 standard": None, + "pm100 standard": None, + "pm10 env": None, + "pm25 env": None, + "pm100 env": None, + "particles 03um": None, + "particles 05um": None, + "particles 10um": None, + "particles 25um": None, + "particles 50um": None, + "particles 100um": None, + } + + def _read_into_buffer(self): + """Low level buffer filling function, to be overridden""" + raise NotImplementedError() + + def read(self): + """Read any available data from the air quality sensor and + return a dictionary with available particulate/quality data""" + self._read_into_buffer() + # print([hex(i) for i in self._buffer]) + + # check packet header + if (self._buffer[0] != 0x42) or (self._buffer[1] != 0x4D): + raise RuntimeError("Invalid PM2.5 header") + + # check frame length + frame_len = struct.unpack(">H", self._buffer[2:4])[0] + if frame_len != 28: + raise RuntimeError("Invalid PM2.5 frame length") + + checksum = struct.unpack(">H", self._buffer[30:32])[0] + check = sum(self._buffer[0:30]) + if check != checksum: + raise RuntimeError("Invalid PM2.5 checksum") + + # unpack data + frame = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28]) + ( + self.aqi_reading["pm10 standard"], + self.aqi_reading["pm25 standard"], + self.aqi_reading["pm100 standard"], + self.aqi_reading["pm10 env"], + self.aqi_reading["pm25 env"], + self.aqi_reading["pm100 env"], + self.aqi_reading["particles 03um"], + self.aqi_reading["particles 05um"], + self.aqi_reading["particles 10um"], + self.aqi_reading["particles 25um"], + self.aqi_reading["particles 50um"], + self.aqi_reading["particles 100um"], + ) = frame + + return self.aqi_reading + + +class PM25_I2C(PM25): + """ + A driver for 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: + raise RuntimeError("Unable to read from PM2.5 over I2C") + + +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]) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py new file mode 100644 index 0000000..7ee24a4 --- /dev/null +++ b/adafruit_pm25/uart.py @@ -0,0 +1,188 @@ +# 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` +================================================================================ + +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. + +**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 +import struct +from adafruit_bus_device.i2c_device import I2CDevice +from digitalio import Direction + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PM25.git" + + +class PM25: + """Super-class for generic PM2.5 sensors. Subclasses must implement + _read_into_buffer to fill self._buffer with a packet of data""" + + def __init__(self): + # rad, ok make our internal buffer! + self._buffer = bytearray(32) + self.aqi_reading = { + "pm10 standard": None, + "pm25 standard": None, + "pm100 standard": None, + "pm10 env": None, + "pm25 env": None, + "pm100 env": None, + "particles 03um": None, + "particles 05um": None, + "particles 10um": None, + "particles 25um": None, + "particles 50um": None, + "particles 100um": None, + } + + def _read_into_buffer(self): + """Low level buffer filling function, to be overridden""" + raise NotImplementedError() + + def read(self): + """Read any available data from the air quality sensor and + return a dictionary with available particulate/quality data""" + self._read_into_buffer() + # print([hex(i) for i in self._buffer]) + + # check packet header + if (self._buffer[0] != 0x42) or (self._buffer[1] != 0x4D): + raise RuntimeError("Invalid PM2.5 header") + + # check frame length + frame_len = struct.unpack(">H", self._buffer[2:4])[0] + if frame_len != 28: + raise RuntimeError("Invalid PM2.5 frame length") + + checksum = struct.unpack(">H", self._buffer[30:32])[0] + check = sum(self._buffer[0:30]) + if check != checksum: + raise RuntimeError("Invalid PM2.5 checksum") + + # unpack data + frame = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28]) + ( + self.aqi_reading["pm10 standard"], + self.aqi_reading["pm25 standard"], + self.aqi_reading["pm100 standard"], + self.aqi_reading["pm10 env"], + self.aqi_reading["pm25 env"], + self.aqi_reading["pm100 env"], + self.aqi_reading["particles 03um"], + self.aqi_reading["particles 05um"], + self.aqi_reading["particles 10um"], + self.aqi_reading["particles 25um"], + self.aqi_reading["particles 50um"], + self.aqi_reading["particles 100um"], + ) = frame + + return self.aqi_reading + + +class PM25_I2C(PM25): + """ + A driver for 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: + raise RuntimeError("Unable to read from PM2.5 over I2C") + + +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]) From 583195beadc42f00982daefcc6072d9cf81dc2f9 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 14:28:09 +0200 Subject: [PATCH 03/25] Splitting into file per connectivity --- adafruit_pm25/__init__.py | 70 ------------------------ adafruit_pm25/i2c.py | 109 +------------------------------------ adafruit_pm25/uart.py | 110 +------------------------------------- 3 files changed, 3 insertions(+), 286 deletions(-) diff --git a/adafruit_pm25/__init__.py b/adafruit_pm25/__init__.py index 7ee24a4..e327705 100644 --- a/adafruit_pm25/__init__.py +++ b/adafruit_pm25/__init__.py @@ -46,7 +46,6 @@ # imports import time import struct -from adafruit_bus_device.i2c_device import I2CDevice from digitalio import Direction __version__ = "0.0.0-auto.0" @@ -117,72 +116,3 @@ def read(self): ) = frame return self.aqi_reading - - -class PM25_I2C(PM25): - """ - A driver for 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: - raise RuntimeError("Unable to read from PM2.5 over I2C") - - -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]) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 7ee24a4..e7c39a8 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -44,80 +44,8 @@ """ # imports -import time -import struct +from . import PM25 from adafruit_bus_device.i2c_device import I2CDevice -from digitalio import Direction - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PM25.git" - - -class PM25: - """Super-class for generic PM2.5 sensors. Subclasses must implement - _read_into_buffer to fill self._buffer with a packet of data""" - - def __init__(self): - # rad, ok make our internal buffer! - self._buffer = bytearray(32) - self.aqi_reading = { - "pm10 standard": None, - "pm25 standard": None, - "pm100 standard": None, - "pm10 env": None, - "pm25 env": None, - "pm100 env": None, - "particles 03um": None, - "particles 05um": None, - "particles 10um": None, - "particles 25um": None, - "particles 50um": None, - "particles 100um": None, - } - - def _read_into_buffer(self): - """Low level buffer filling function, to be overridden""" - raise NotImplementedError() - - def read(self): - """Read any available data from the air quality sensor and - return a dictionary with available particulate/quality data""" - self._read_into_buffer() - # print([hex(i) for i in self._buffer]) - - # check packet header - if (self._buffer[0] != 0x42) or (self._buffer[1] != 0x4D): - raise RuntimeError("Invalid PM2.5 header") - - # check frame length - frame_len = struct.unpack(">H", self._buffer[2:4])[0] - if frame_len != 28: - raise RuntimeError("Invalid PM2.5 frame length") - - checksum = struct.unpack(">H", self._buffer[30:32])[0] - check = sum(self._buffer[0:30]) - if check != checksum: - raise RuntimeError("Invalid PM2.5 checksum") - - # unpack data - frame = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28]) - ( - self.aqi_reading["pm10 standard"], - self.aqi_reading["pm25 standard"], - self.aqi_reading["pm100 standard"], - self.aqi_reading["pm10 env"], - self.aqi_reading["pm25 env"], - self.aqi_reading["pm100 env"], - self.aqi_reading["particles 03um"], - self.aqi_reading["particles 05um"], - self.aqi_reading["particles 10um"], - self.aqi_reading["particles 25um"], - self.aqi_reading["particles 50um"], - self.aqi_reading["particles 100um"], - ) = frame - - return self.aqi_reading - class PM25_I2C(PM25): """ @@ -151,38 +79,3 @@ def _read_into_buffer(self): i2c.readinto(self._buffer) except OSError: raise RuntimeError("Unable to read from PM2.5 over I2C") - - -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]) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 7ee24a4..5ecb676 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -44,114 +44,7 @@ """ # imports -import time -import struct -from adafruit_bus_device.i2c_device import I2CDevice -from digitalio import Direction - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PM25.git" - - -class PM25: - """Super-class for generic PM2.5 sensors. Subclasses must implement - _read_into_buffer to fill self._buffer with a packet of data""" - - def __init__(self): - # rad, ok make our internal buffer! - self._buffer = bytearray(32) - self.aqi_reading = { - "pm10 standard": None, - "pm25 standard": None, - "pm100 standard": None, - "pm10 env": None, - "pm25 env": None, - "pm100 env": None, - "particles 03um": None, - "particles 05um": None, - "particles 10um": None, - "particles 25um": None, - "particles 50um": None, - "particles 100um": None, - } - - def _read_into_buffer(self): - """Low level buffer filling function, to be overridden""" - raise NotImplementedError() - - def read(self): - """Read any available data from the air quality sensor and - return a dictionary with available particulate/quality data""" - self._read_into_buffer() - # print([hex(i) for i in self._buffer]) - - # check packet header - if (self._buffer[0] != 0x42) or (self._buffer[1] != 0x4D): - raise RuntimeError("Invalid PM2.5 header") - - # check frame length - frame_len = struct.unpack(">H", self._buffer[2:4])[0] - if frame_len != 28: - raise RuntimeError("Invalid PM2.5 frame length") - - checksum = struct.unpack(">H", self._buffer[30:32])[0] - check = sum(self._buffer[0:30]) - if check != checksum: - raise RuntimeError("Invalid PM2.5 checksum") - - # unpack data - frame = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28]) - ( - self.aqi_reading["pm10 standard"], - self.aqi_reading["pm25 standard"], - self.aqi_reading["pm100 standard"], - self.aqi_reading["pm10 env"], - self.aqi_reading["pm25 env"], - self.aqi_reading["pm100 env"], - self.aqi_reading["particles 03um"], - self.aqi_reading["particles 05um"], - self.aqi_reading["particles 10um"], - self.aqi_reading["particles 25um"], - self.aqi_reading["particles 50um"], - self.aqi_reading["particles 100um"], - ) = frame - - return self.aqi_reading - - -class PM25_I2C(PM25): - """ - A driver for 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: - raise RuntimeError("Unable to read from PM2.5 over I2C") - +from . import PM25 class PM25_UART(PM25): """ @@ -175,6 +68,7 @@ def _read_into_buffer(self): while True: b = self._uart.read(1) if not b: + print(b) ### <<< debug raise RuntimeError("Unable to read from PM2.5 (no start of frame)") if b[0] == 0x42: break From d369fb5b7d412961f7064b071523ff00109e5373 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 14:52:42 +0200 Subject: [PATCH 04/25] Separate simpletest for uart and i2c + fix time import in I2C --- adafruit_pm25/i2c.py | 3 +- ...5_simpletest.py => pm25_simpletest_i2c.py} | 6 +- examples/pm25_simpletest_uart.py | 75 +++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) rename examples/{pm25_simpletest.py => pm25_simpletest_i2c.py} (94%) create mode 100644 examples/pm25_simpletest_uart.py diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index e7c39a8..6446022 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -44,6 +44,7 @@ """ # imports +import time from . import PM25 from adafruit_bus_device.i2c_device import I2CDevice @@ -78,4 +79,4 @@ def _read_into_buffer(self): try: i2c.readinto(self._buffer) except OSError: - raise RuntimeError("Unable to read from PM2.5 over I2C") + raise RuntimeError("Unable to read from PM2.5 over I2C") \ No newline at end of file diff --git a/examples/pm25_simpletest.py b/examples/pm25_simpletest_i2c.py similarity index 94% rename from examples/pm25_simpletest.py rename to examples/pm25_simpletest_i2c.py index 7faf202..8def2ea 100644 --- a/examples/pm25_simpletest.py +++ b/examples/pm25_simpletest_i2c.py @@ -1,5 +1,5 @@ """ -Example sketch to connect to PM2.5 sensor with either I2C or UART. +Example sketch to connect to PM2.5 sensor with I2C. """ # pylint: disable=unused-import @@ -7,7 +7,7 @@ import board import busio from digitalio import DigitalInOut, Direction, Pull -import adafruit_pm25 +from adafruit_pm25.i2c import PM25_I2C reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin @@ -38,7 +38,7 @@ # Create library object, use 'slow' 100KHz frequency! i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C -pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) +pm25 = PM25_I2C(i2c, reset_pin) print("Found PM2.5 sensor, reading data...") diff --git a/examples/pm25_simpletest_uart.py b/examples/pm25_simpletest_uart.py new file mode 100644 index 0000000..965e53c --- /dev/null +++ b/examples/pm25_simpletest_uart.py @@ -0,0 +1,75 @@ +""" +Example sketch to connect to PM2.5 sensor with UART. +""" + +# pylint: disable=unused-import +import time +import board +import busio +from digitalio import DigitalInOut, Direction, Pull +from adafruit_pm25.uart import PM25_UART + +reset_pin = None +# If you have a GPIO, its not a bad idea to connect it to the RESET pin +# reset_pin = DigitalInOut(board.G0) +# reset_pin.direction = Direction.OUTPUT +# reset_pin.value = False + + +# For use with a computer running Windows: +# import serial +# uart = serial.Serial("COM30", baudrate=9600, timeout=1) + +# For use with microcontroller board: +# (Connect the sensor TX pin to the board/computer RX pin) +uart = busio.UART(board.TX, board.RX, baudrate=9600) + +# For use with Raspberry Pi/Linux: +# import serial +# uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25) + +# For use with USB-to-serial cable: +# import serial +# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) + +# Connect to a PM2.5 sensor over UART +pm25 = PM25_UART(uart, reset_pin) + +# Create library object, use 'slow' 100KHz frequency! +#i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) +# Connect to a PM2.5 sensor over I2C +#pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) + +print("Checking PM2.5 sensor, reading data...") + +while True: + time.sleep(1) + + try: + aqdata = pm25.read() + # print(aqdata) + except RuntimeError: + print("Unable to read from sensor, retrying...") + continue + + print() + print("Concentration Units (standard)") + print("---------------------------------------") + print( + "PM 1.0: %d\tPM2.5: %d\tPM10: %d" + % (aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"]) + ) + print("Concentration Units (environmental)") + print("---------------------------------------") + print( + "PM 1.0: %d\tPM2.5: %d\tPM10: %d" + % (aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"]) + ) + print("---------------------------------------") + print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"]) + print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"]) + print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"]) + print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"]) + print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"]) + print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"]) + print("---------------------------------------") From 2800315894b195d788d74d05ccb5a1700561b433 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 14:58:12 +0200 Subject: [PATCH 05/25] Black cleaning --- adafruit_pm25/i2c.py | 3 ++- adafruit_pm25/uart.py | 3 ++- examples/pm25_simpletest_uart.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 6446022..ea49f66 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -48,6 +48,7 @@ from . import PM25 from adafruit_bus_device.i2c_device import I2CDevice + class PM25_I2C(PM25): """ A driver for the PM2.5 Air quality sensor over I2C @@ -79,4 +80,4 @@ def _read_into_buffer(self): try: i2c.readinto(self._buffer) except OSError: - raise RuntimeError("Unable to read from PM2.5 over I2C") \ No newline at end of file + raise RuntimeError("Unable to read from PM2.5 over I2C") diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 5ecb676..77721b2 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -46,6 +46,7 @@ # imports from . import PM25 + class PM25_UART(PM25): """ A driver for the PM2.5 Air quality sensor over UART @@ -68,7 +69,7 @@ def _read_into_buffer(self): while True: b = self._uart.read(1) if not b: - print(b) ### <<< debug + print(b) ### <<< debug raise RuntimeError("Unable to read from PM2.5 (no start of frame)") if b[0] == 0x42: break diff --git a/examples/pm25_simpletest_uart.py b/examples/pm25_simpletest_uart.py index 965e53c..28a36ec 100644 --- a/examples/pm25_simpletest_uart.py +++ b/examples/pm25_simpletest_uart.py @@ -36,9 +36,9 @@ pm25 = PM25_UART(uart, reset_pin) # Create library object, use 'slow' 100KHz frequency! -#i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) +# i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C -#pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) +# pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) print("Checking PM2.5 sensor, reading data...") From 55bc3d92ff67de431e9d52e0710bc2f96b43496b Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 15:05:09 +0200 Subject: [PATCH 06/25] Pylint on import and what should be where --- adafruit_pm25/__init__.py | 2 -- adafruit_pm25/i2c.py | 3 ++- adafruit_pm25/uart.py | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_pm25/__init__.py b/adafruit_pm25/__init__.py index e327705..4c9fdaa 100644 --- a/adafruit_pm25/__init__.py +++ b/adafruit_pm25/__init__.py @@ -44,9 +44,7 @@ """ # imports -import time import struct -from digitalio import Direction __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PM25.git" diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index ea49f66..0ae4c07 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -45,8 +45,9 @@ # imports import time -from . import PM25 +from digitalio import Direction from adafruit_bus_device.i2c_device import I2CDevice +from . import PM25 class PM25_I2C(PM25): diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 77721b2..08180fd 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -44,6 +44,8 @@ """ # imports +import time +from digitalio import Direction from . import PM25 From ae2a64b3a5dddc155d5b87b4678443fa9f9c2e68 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 15 Aug 2020 15:15:59 +0200 Subject: [PATCH 07/25] Merge back I2C and UART simpletest to avoid changing the docs --- ...5_simpletest_i2c.py => pm25_simpletest.py} | 4 +- examples/pm25_simpletest_uart.py | 75 ------------------- 2 files changed, 3 insertions(+), 76 deletions(-) rename examples/{pm25_simpletest_i2c.py => pm25_simpletest.py} (96%) delete mode 100644 examples/pm25_simpletest_uart.py diff --git a/examples/pm25_simpletest_i2c.py b/examples/pm25_simpletest.py similarity index 96% rename from examples/pm25_simpletest_i2c.py rename to examples/pm25_simpletest.py index 8def2ea..88073bf 100644 --- a/examples/pm25_simpletest_i2c.py +++ b/examples/pm25_simpletest.py @@ -9,6 +9,8 @@ from digitalio import DigitalInOut, Direction, Pull from adafruit_pm25.i2c import PM25_I2C +# from adafruit_pm25.uart import PM25_UART + reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin # reset_pin = DigitalInOut(board.G0) @@ -33,7 +35,7 @@ # uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) # Connect to a PM2.5 sensor over UART -# pm25 = adafruit_pm25.PM25_UART(uart, reset_pin) +# pm25 = PM25_UART(uart, reset_pin) # Create library object, use 'slow' 100KHz frequency! i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) diff --git a/examples/pm25_simpletest_uart.py b/examples/pm25_simpletest_uart.py deleted file mode 100644 index 28a36ec..0000000 --- a/examples/pm25_simpletest_uart.py +++ /dev/null @@ -1,75 +0,0 @@ -""" -Example sketch to connect to PM2.5 sensor with UART. -""" - -# pylint: disable=unused-import -import time -import board -import busio -from digitalio import DigitalInOut, Direction, Pull -from adafruit_pm25.uart import PM25_UART - -reset_pin = None -# If you have a GPIO, its not a bad idea to connect it to the RESET pin -# reset_pin = DigitalInOut(board.G0) -# reset_pin.direction = Direction.OUTPUT -# reset_pin.value = False - - -# For use with a computer running Windows: -# import serial -# uart = serial.Serial("COM30", baudrate=9600, timeout=1) - -# For use with microcontroller board: -# (Connect the sensor TX pin to the board/computer RX pin) -uart = busio.UART(board.TX, board.RX, baudrate=9600) - -# For use with Raspberry Pi/Linux: -# import serial -# uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25) - -# For use with USB-to-serial cable: -# import serial -# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) - -# Connect to a PM2.5 sensor over UART -pm25 = PM25_UART(uart, reset_pin) - -# Create library object, use 'slow' 100KHz frequency! -# i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) -# Connect to a PM2.5 sensor over I2C -# pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) - -print("Checking PM2.5 sensor, reading data...") - -while True: - time.sleep(1) - - try: - aqdata = pm25.read() - # print(aqdata) - except RuntimeError: - print("Unable to read from sensor, retrying...") - continue - - print() - print("Concentration Units (standard)") - print("---------------------------------------") - print( - "PM 1.0: %d\tPM2.5: %d\tPM10: %d" - % (aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"]) - ) - print("Concentration Units (environmental)") - print("---------------------------------------") - print( - "PM 1.0: %d\tPM2.5: %d\tPM10: %d" - % (aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"]) - ) - print("---------------------------------------") - print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"]) - print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"]) - print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"]) - print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"]) - print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"]) - print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"]) - print("---------------------------------------") From 9d0c95c2eb5d0465c4956074da260e26b4e58b3f Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:18:01 +0200 Subject: [PATCH 08/25] Update adafruit_pm25/i2c.py Co-authored-by: Kattni --- adafruit_pm25/i2c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 0ae4c07..35543e8 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -23,7 +23,7 @@ `adafruit_pm25` ================================================================================ -CircuitPython library for PM2.5 Air Quality Sensors +I2C module for CircuitPython library for PM2.5 Air Quality Sensors * Author(s): ladyada From 483b58814525a6496ac0d82b686c30f4a7c2429a Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:18:11 +0200 Subject: [PATCH 09/25] Update adafruit_pm25/i2c.py Co-authored-by: Kattni --- adafruit_pm25/i2c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 35543e8..0f5cdbc 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_pm25` +`adafruit_pm25.i2c` ================================================================================ I2C module for CircuitPython library for PM2.5 Air Quality Sensors From 8d4b126551807b959e1e01d22f9d9bb6007c3514 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:18:30 +0200 Subject: [PATCH 10/25] Update adafruit_pm25/i2c.py Co-authored-by: Kattni --- adafruit_pm25/i2c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 0f5cdbc..2fbf83d 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -52,7 +52,7 @@ class PM25_I2C(PM25): """ - A driver for the PM2.5 Air quality sensor over I2C + A module for using the PM2.5 Air quality sensor over I2C """ def __init__(self, i2c_bus, reset_pin=None, address=0x12): From 64ecd8180e2d7802d4b57c036e53cea3e7f4724b Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:21:21 +0200 Subject: [PATCH 11/25] Update adafruit_pm25/uart.py Co-authored-by: Kattni --- adafruit_pm25/uart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 08180fd..43292f2 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_pm25` +`adafruit_pm25.uart` ================================================================================ CircuitPython library for PM2.5 Air Quality Sensors From 21906e910f30201861649c92a6033c63c464e645 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:22:08 +0200 Subject: [PATCH 12/25] Update adafruit_pm25/uart.py Co-authored-by: Kattni --- adafruit_pm25/uart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 43292f2..822e4f7 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -23,7 +23,7 @@ `adafruit_pm25.uart` ================================================================================ -CircuitPython library for PM2.5 Air Quality Sensors +UART module for CircuitPython library for PM2.5 Air Quality Sensors * Author(s): ladyada From fc851a1524574a38112021e0621b54a273791c01 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:23:44 +0200 Subject: [PATCH 13/25] Update uart.py Does not require busio, that was the whole point of separating. --- adafruit_pm25/uart.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 822e4f7..b6cbc8a 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -39,7 +39,6 @@ * 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 """ From d13b66fbf62ec7e3c3c04d9f2131f19853e5db0c Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:26:32 +0200 Subject: [PATCH 14/25] Update uart.py Remove print/debug code. --- adafruit_pm25/uart.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index b6cbc8a..1aeb5b4 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -70,7 +70,6 @@ def _read_into_buffer(self): while True: b = self._uart.read(1) if not b: - print(b) ### <<< debug raise RuntimeError("Unable to read from PM2.5 (no start of frame)") if b[0] == 0x42: break From cbafdd09d58e3f44dcc49032935088fb33aca2e7 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:33:42 +0200 Subject: [PATCH 15/25] Update pm25_simpletest.py Moving UART import near the part about UART. --- examples/pm25_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pm25_simpletest.py b/examples/pm25_simpletest.py index 88073bf..189e1aa 100644 --- a/examples/pm25_simpletest.py +++ b/examples/pm25_simpletest.py @@ -9,7 +9,6 @@ from digitalio import DigitalInOut, Direction, Pull from adafruit_pm25.i2c import PM25_I2C -# from adafruit_pm25.uart import PM25_UART reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin @@ -35,6 +34,7 @@ # uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) # Connect to a PM2.5 sensor over UART +# from adafruit_pm25.uart import PM25_UART # pm25 = PM25_UART(uart, reset_pin) # Create library object, use 'slow' 100KHz frequency! From acdd32e4c643eaf2c21b55b61e394bd8995a5007 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:39:57 +0200 Subject: [PATCH 16/25] Update __init__.py --- adafruit_pm25/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_pm25/__init__.py b/adafruit_pm25/__init__.py index 4c9fdaa..1a9ca45 100644 --- a/adafruit_pm25/__init__.py +++ b/adafruit_pm25/__init__.py @@ -43,7 +43,6 @@ """ -# imports import struct __version__ = "0.0.0-auto.0" From 4f320c6d36454b68a1e88bc62904e49264253bc8 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:40:13 +0200 Subject: [PATCH 17/25] Update __init__.py From c691261e4495106469c4b3a07375575e2757ebc0 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:42:31 +0200 Subject: [PATCH 18/25] Update i2c.py --- adafruit_pm25/i2c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index 2fbf83d..f4fda92 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -33,7 +33,7 @@ **Hardware:** -Works with most (any?) Plantower UART or I2C interfaced PM2.5 sensor. +Works with most (any?) Plantower I2C interfaced PM2.5 sensor. **Software and Dependencies:** From dfea3ae86d975e41128380bf6cf0640454fcd3cd Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:46:15 +0200 Subject: [PATCH 19/25] Update uart.py --- adafruit_pm25/uart.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_pm25/uart.py b/adafruit_pm25/uart.py index 1aeb5b4..1b91e05 100644 --- a/adafruit_pm25/uart.py +++ b/adafruit_pm25/uart.py @@ -42,7 +42,6 @@ """ -# imports import time from digitalio import Direction from . import PM25 From 58561904dc134ce35a3ed22f30a2d847a8cfb937 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 00:59:04 +0200 Subject: [PATCH 20/25] Update pm25_simpletest.py --- examples/pm25_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pm25_simpletest.py b/examples/pm25_simpletest.py index 189e1aa..bb53d27 100644 --- a/examples/pm25_simpletest.py +++ b/examples/pm25_simpletest.py @@ -1,5 +1,5 @@ """ -Example sketch to connect to PM2.5 sensor with I2C. +Example sketch to connect to PM2.5 sensor with either I2C or UART. """ # pylint: disable=unused-import From 1915594971c08263600f87a59b79e9b83da22b4f Mon Sep 17 00:00:00 2001 From: David Glaude Date: Thu, 20 Aug 2020 01:08:33 +0200 Subject: [PATCH 21/25] Update api.rst List all the module --- docs/api.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 21a29ed..e38e9c0 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -6,3 +6,9 @@ .. automodule:: adafruit_pm25 :members: + +.. automodule:: adafruit_pm25.i2c + :members: + +.. automodule:: adafruit_pm25.uart + :members: From e1560c9dc5fe4398ee132202e41ece75df7172f5 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 23 Aug 2020 10:26:34 +0200 Subject: [PATCH 22/25] Update setup.py This might make PyPi more happy (as seen in Adafruit_CircuitPython_LSM6DS). --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 776c3ea..0d8f285 100644 --- a/setup.py +++ b/setup.py @@ -49,5 +49,5 @@ # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["adafruit_pm25"], + packages=["adafruit_pm25"], ) From 29dad18f66617e83fb2d2b45ced0b046fb1f22e1 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 23 Aug 2020 12:37:55 +0200 Subject: [PATCH 23/25] Temporary fix for pylint 2.6.0 upgrade on GitHub New version of pylint (2.6.0) on GitHub raise this kind of message: adafruit_pm25/i2c.py:84:16: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from) --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index d8f0ee8..4b9740d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,raise-missing-from # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From b22bf69a2d33d7a66f89f777f340f19fc6c79ead Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 23 Aug 2020 17:25:19 +0200 Subject: [PATCH 24/25] Adapting to W0707 pylint message W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from): > 2020-08-23T08:28:02.9225541Z ************* Module adafruit_pm25.i2c > 2020-08-23T08:28:02.9226318Z adafruit_pm25/i2c.py:84:16: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from) --- adafruit_pm25/i2c.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pm25/i2c.py b/adafruit_pm25/i2c.py index f4fda92..d4b191b 100644 --- a/adafruit_pm25/i2c.py +++ b/adafruit_pm25/i2c.py @@ -80,5 +80,5 @@ def _read_into_buffer(self): with self.i2c_device as i2c: try: i2c.readinto(self._buffer) - except OSError: - raise RuntimeError("Unable to read from PM2.5 over I2C") + except OSError as err: + raise RuntimeError("Unable to read from PM2.5 over I2C") from err From 4c71550991f25bf439186e171c37dce3fe26179e Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 23 Aug 2020 17:27:34 +0200 Subject: [PATCH 25/25] Undo hiding the pylint issue This was hiding W0707: "Consider explicitly re-raising using the 'from' keyword (raise-missing-from)" --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 4b9740d..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,raise-missing-from +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option