pimoroni / pms5003-python Goto Github PK
View Code? Open in Web Editor NEWPython library for the PMS5003 particulate sensor
License: MIT License
Python library for the PMS5003 particulate sensor
License: MIT License
As per pimoroni/enviroplus-python#45 there are cases where the PMS5003 is in "fast mode" and might need to be polled at a ~200ms interval.
This library is very similar to pimoroni/pms5003-circuitpython and a lot of improvements were added to that in
With some luck (and testing) the pms5003-python may be able to be generated from pms5003-circuitpython code with a minor patch. The versions could synchronise at 0.0.6
as a partial indication of their linkage.
Hi, I'm running code to read the sensor continuously (once a second i think), and post to thingspeak every 30s. However the code keeps crashing with the pms5003 library raising the checksummismatch error. It happens roughly every half hour and stops the sensor reading for about half an hour before it goes away from what i can tell. (i've just bypassed it by catching all exceptions in my modified examples/particulates.py
Hi,
I just received my second pms5003 sensor and still can't get any reading from the device. From my understanding both the ARM I2C interface needs to be enabled and the serial port hardware. In addition to that the /etc/boot.txt does list a line dtoverlay=pi3-miniuart-bt
Also I ran the install script several times on a raspberry pi 4.
This code does also not do anything:
import serial
bus = serial.Serial('/dev/ttyAMA0', baudrate=9600, timeout=4)
bus.flushInput()
while True:
value = bus.read(4)
if len(value) > 0:
print(value)
What am I doing wrong. Can I run some checks on interfaces or do you have another idea ?
Thanks for your help,
Alexander
I'm using this with the enviro+, but I keep getting read error.
File "/usr/local/lib/python3.6/dist-packages/pms5003/__init__.py", line 121, in read
raise ReadTimeoutError("PMS5003 Read Timeout")
pms5003.ReadTimeoutError: PMS5003 Read Timeout
/dev/ttyAMA0 exists, but I'm not sure if it's setup properly, since the install script in the enviro+ library had several errors, and did not install everything properly.
I'm using Ubuntu-Mate 18.04.2 (for a Raspberry Pi ARMv8 64-bit system) on a Raspberry Pi 3 B
Hello,
I am encountering an error when running the particulates.py
example.
Traceback (most recent call last):
File "particulates.py", line 26, in <module>
readings = pms5003.read()
File "/usr/local/lib/python3.7/dist-packages/pms5003/__init__.py", line 127, in read
raise SerialTimeoutError("PMS5003 Read Timeout: Failed to read start of frame byte")
pms5003.SerialTimeoutError: PMS5003 Read Timeout: Failed to read start of frame byte
Things I have tried:
install.sh
and verified /boot/config.txt
check-install.py
looks okAll other scripts work fine, it is just when trying to use the PM sensor in particulates.py
.
Context:
I have successfully run this before maybe around 2021? I have since lost that version of the code and recently tried re-using it. Initially i was using the latest OS (Bullseye), now am on Buster and still no luck.
ERROR MESSAGE IS AS BELOW.
sometimes OK, but sometimes FAIL.
sometimes OK at first, then FAIL.
WHAT WRONG?
Is it hardware problems?
============================================
pi@raspberrypi:~/pms5003-python/examples $ sudo python specific.py
specific.py - Continously print a specific data value.
Press Ctrl+C to exit!
Traceback (most recent call last):
File "specific.py", line 17, in
timeout=2
TypeError: init() got an unexpected keyword argument 'timeout'
If installed in a virtual environment the code fails as RPi.GPIO is not listed as a dependency in setup.py.
The code runs as expected once RPi.GPIO is installed.
Hi,
The PMS5003 used to be working well for a while, but recently, after the very first 10 measurements it goes:
{'temperature': '-0.98', 'pressure': '102308.87', 'humidity': '45.13', 'P2': '4', 'P1': '4'}
{'temperature': '-0.97', 'pressure': '102308.83', 'humidity': '45.12', 'P2': '4', 'P1': '4'}
PMS5003 Read Timeout: Failed to read start of frame byte
PMS5003 Read Timeout: Failed to read start of frame byte
What could it be?
Thanks,
Ciprian
Hi,
I'm getting the following error after upgrading pms5003 from 0.0.5 to 1.0.0. I'm running on:
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
I get the following error:
Press Ctrl+C to exit!
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/tijmen/projects/enviroplus_exporter/enviroplus_exporter.py", line 52, in <module>
pms5003 = PMS5003()
File "/home/tijmen/projects/enviroplus_exporter/.env/lib/python3.9/site-packages/pms5003/__init__.py", line 109, in __init__
self._pin_enable, self._pin_reset = gpiodevice.get_pins_for_platform(PLATFORMS)
File "/home/tijmen/projects/enviroplus_exporter/.env/lib/python3.9/site-packages/gpiodevice/__init__.py", line 153, in get_pins_for_platform
result.append(get_pin(pin, user_label, settings))
File "/home/tijmen/projects/enviroplus_exporter/.env/lib/python3.9/site-packages/gpiodevice/__init__.py", line 138, in get_pin
chip = find_chip_by_pins(pin)
File "/home/tijmen/projects/enviroplus_exporter/.env/lib/python3.9/site-packages/gpiodevice/errors.py", line 45, in wrapper
errors.append(next(i))
SystemError: <built-in method close of gpiod._ext.Chip object at 0x7fb1f3a850> returned a result with an error set
Any idea how to resolve this?
I had an Enviro+ running for a year on a Pi ZeroW before I decided to upgrade the OS to latest, and completely broke the operation of the Enviro+.
I did a fresh install of the previous OS version and have almost everything running again except the PMS5003. Pulling down the latest driver from here an running examples/all.py give the following error
Woah there, suitable gpiochip not found!
PIN15: not found - /dev/gpiochip0 (pinctrl-bcm2835)
Re-running install.sh did some magic, got rid of the gpiochip error but then lead to the following error:
File "/usr/local/lib/python3.9/dist-packages/gpiodevice/__init__.py", line 138, in get_pin
chip = find_chip_by_pins(pin)
File "/usr/local/lib/python3.9/dist-packages/gpiodevice/errors.py", line 45, in wrapper
errors.append(next(i))
File "/usr/local/lib/python3.9/dist-packages/gpiodevice/__init__.py", line 108, in find_chip_by_pins
for pin_id in pins:
TypeError: 'int' object is not iterable
The solution seems to be
pip install RPi.GPIO
replace
/usr/local/lib/python3.9/dist-packages/pms5003/__init__.py
with the one from this commit
https://raw.githubusercontent.com/pimoroni/pms5003-python/406801133aaa7489dd4b967890c1cab7a656a4aa/library/pms5003/__init__.py
After that the examples work perfectly.
Why are you using the hard set ttyAMA0 ?
def init(self, device='/dev/ttyAMA0', baudrate=9600, pin_enable=22, pin_reset=27):
If you use /dev/serial0 as per normal RPi serial setups then it should just work on whatever configuration the Pi is set for. The override can then specify an actual port if needed.
Also there seems nothing in the readme to place the enable line and reset line on pins on 22 and 27 as the defaults.
Is there a need to use the full uart for the PMS5003 (there isn't for the similar PM2.5/10 sensor SDS011/SDS021 iirc or for GNSS devices)
There is nothing in the readme saying I have to disable or switch over BlueTooth on the PiZero or 3 series Pi's.
I have version .5 of this library working on an rpi 4 but I'm doing some testing on an rpi 2 zero w and after downloading v1.0 I'm getting this error with the new call gpiod instead of RpiGPIO (using gpio numbers not header numbers to connect pins):
Traceback (most recent call last):
File "/home/weather/pmsTests/pms5003-test.py", line 25, in
pms5003 = PMS5003(
File "/root/.local/lib/python3.9/site-packages/pms5003/init.py", line 106, in init
self._pin_enable = gpiodevice.get_pin(pin_enable, "PMS5003_en", OUTH)
File "/root/.local/lib/python3.9/site-packages/gpiodevice/init.py", line 138, in get_pin
chip = find_chip_by_pins(pin)
File "/root/.local/lib/python3.9/site-packages/gpiodevice/errors.py", line 45, in wrapper
errors.append(next(i))
File "/root/.local/lib/python3.9/site-packages/gpiodevice/init.py", line 108, in find_chip_by_pins
for pin_id in pins:
TypeError: 'int' object is not iterable
Is it possible to get readouts of the individual values instead of one big data clump?
I have what appears to be the common issue. I am running the latest Raspbian OS desktop. I have installed the enviro + software and the examples mostly run fine until the dreaded:
File "/usr/local/lib/python3.6/dist-packages/pms5003/__init__.py", line 121, in read raise ReadTimeoutError("PMS5003 Read Timeout") pms5003.ReadTimeoutError: PMS5003 Read Timeout
I have added: dtoverlay=pi3-miniuart-bt
to my /boot/config.txt
Any ideas on why this would be happening? I can hear the sensor turning on so it does not seem to be a hardware issue.. I have tried re-seating the cable, using a different cable, but nothing works. Any help much appreciated.
How can be set the sleep mode and wake up using the library ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.