Skip to content

pms5003 timeouts #9

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

Closed
sepulworld opened this issue Jul 4, 2019 · 7 comments
Closed

pms5003 timeouts #9

sepulworld opened this issue Jul 4, 2019 · 7 comments

Comments

@sepulworld
Copy link

Hi,

I keep getting timeouts with the pms5003 particle sensor library

In [5]: readings = pms5003.read()
---------------------------------------------------------------------------
ReadTimeoutError                          Traceback (most recent call last)
<ipython-input-5-dc7f60780eda> in <module>
----> 1 readings = pms5003.read()

/usr/local/lib/python3.7/dist-packages/pms5003-0.0.2-py3.7.egg/pms5003/__init__.py in read(self)
    119             elapsed = time.time() - start
    120             if elapsed > 5:
--> 121                 raise ReadTimeoutError("PMS5003 Read Timeout")
    122
    123             sof = bytearray(self._serial.read(2))

ReadTimeoutError: PMS5003 Read Timeout

It times out every time. I have not gotten a reading from it yet. What are some things I can do to debug? I can hear the fan spinning on the pms5003 sensor, so it appears to be on.

@torarne
Copy link

torarne commented Jul 4, 2019

I have had the same problem - and in my case it was a loose connector in the cable - resetting it while pushing it in helped. Power is applied on a different pin to the comms.

@Gadgetoid
Copy link
Member

This will either be due to intermittent connectivity - as torarne mentions above - or could also be due to the dtoverlay=pi3-miniuart-bt missing from your /boot/config.txt. However from your other issue (seeing: "Adding dtoverlay=pi3-miniuart-bt # for Enviro+ to /boot/config.txt" in your install output) I believe it's more likely the former.

@Gadgetoid
Copy link
Member

Actually, looking back at my above post with a small amount of horror and the benefit of hindsight I do wonder if config.txt even supports inline comments at all. It could easily be that the # for Enviro+ part is breaking that dtoverlay line altogether.

@sepulworld
Copy link
Author

sepulworld commented Jul 4, 2019

Thanks for the quick feedback!

So, I first tried to reset the pms5003 cable connection and still had same issue.

I think removed the trailing comment # for Enviro+ and now instead of a timeout I get...

particulates.py - Print readings from the PMS5003 particulate sensor.

Press Ctrl+C to exit!


Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyAMA0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "particulates.py", line 12, in <module>
    pms5003 = PMS5003()
  File "/usr/local/lib/python3.7/dist-packages/pms5003-0.0.2-py3.7.egg/pms5003/__init__.py", line 93, in __init__
    self.setup()
  File "/usr/local/lib/python3.7/dist-packages/pms5003-0.0.2-py3.7.egg/pms5003/__init__.py", line 104, in setup
    self._serial = serial.Serial(self._device, baudrate=self._baudrate, timeout=4)
  File "/home/pi/.local/lib/python3.7/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/home/pi/.local/lib/python3.7/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyAMA0: [Errno 2] No such file or directory: '/dev/ttyAMA0'

ls of /dev

pi@enviro-pi1:~/enviroplus-python/examples $ ls /dev/
autofs           gpiomem  loop7               ptmx   ram6       stdout  tty2   tty32  tty45  tty58      urandom  vcsa2     vhci
block            hwrng    loop-control        pts    ram7       tty     tty20  tty33  tty46  tty59      v4l      vcsa3     video10
btrfs-control    i2c-1    mapper              ram0   ram8       tty0    tty21  tty34  tty47  tty6       vchiq    vcsa4     video11
bus              initctl  mem                 ram1   ram9       tty1    tty22  tty35  tty48  tty60      vcio     vcsa5     video12
cachefiles       input    memory_bandwidth    ram10  random     tty10   tty23  tty36  tty49  tty61      vc-mem   vcsa6     watchdog
char             kmsg     mmcblk0             ram11  raw        tty11   tty24  tty37  tty5   tty62      vcs      vcsm      watchdog0
console          log      mmcblk0p1           ram12  rfkill     tty12   tty25  tty38  tty50  tty63      vcs1     vcsm-cma  zero
cpu_dma_latency  loop0    mmcblk0p2           ram13  serial1    tty13   tty26  tty39  tty51  tty7       vcs2     vcsu
cuse             loop1    mqueue              ram14  shm        tty14   tty27  tty4   tty52  tty8       vcs3     vcsu1
disk             loop2    net                 ram15  snd        tty15   tty28  tty40  tty53  tty9       vcs4     vcsu2
fd               loop3    network_latency     ram2   spidev0.0  tty16   tty29  tty41  tty54  ttyprintk  vcs5     vcsu3
full             loop4    network_throughput  ram3   spidev0.1  tty17   tty3   tty42  tty55  ttyS0      vcs6     vcsu4
fuse             loop5    null                ram4   stderr     tty18   tty30  tty43  tty56  uhid       vcsa     vcsu5
gpiochip0        loop6    ppp                 ram5   stdin      tty19   tty31  tty44  tty57  uinput     vcsa1    vcsu6

Going to debug further. Perhaps the serial device that needs to be disabled isn't disabled properly?

But it does look like the the trailing comment in config.txt was part of the issue

@sepulworld
Copy link
Author

Here is my config.txt

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=dwc2

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
#dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d
enable_uart=0
dtoverlay=pi3-miniuart-bt

@Gadgetoid
Copy link
Member

That enable_uart=0 in your config should be an enable_uart=1, looks like your whole serial port is disabled rather than just the serial console.

@sepulworld
Copy link
Author

That did the trick! thank you!

JWCook pushed a commit to JWCook/rpi-enviro-monitor that referenced this issue Nov 9, 2021
Initial Commit

Documentation

Fixed badge URLs

Fixes/improvements from pypa/sampleproject

Get lib name automatically for install endpoints

Fixed linting error

Script for setting up git remotes

Synced with bootstrap

Start gas and tests

Clarified pin use, fixed missing setup

Added examples

rename envirophatplus -> enviroplus

README board name change

Updated install/uninstall scripts

Adding a couple of new examples

Update gas.py

Changing references to MICS6812 to MICS6814

Adding new Luftdaten example

Enable i2c and SPI

Tweaking temp compensation value

Fix for PMS5003 ReadTimeoutError

Adding all-in-one example

Improvements to compensated temperature code

flake8 fiddling

Update README.md

Exclude fonts from DoS check

Updated README.rst

Fix in lieu of pimoroni#1

Fix PM10 label unit

Decode fix for pimoroni#3

Switch to v2 installer

Add Raspbian Lite dependencies for pimoroni#6

Update README install instructions

Add links & blurb to README

Recommend OLI install

Back up to /boot to survive OLI rm

Add PIL for pimoroni#6

adding install notes for python-pil, python-setuptools

Add setuptools minimum version trap

config.txt probably doesn't support inline comments pimoroni#9

Packaging fixes from boilerplate

Add pip for pimoroni#6, correct indendation

Bootstrap with python-configparser from apt

Install improvements

Create RESOURCES_DIR early

Ensure required dependencies are installed

Create all-in-one-no-pm.py

Example for all of the sensors built in, omitting the optional particulate matter sensor.

Add ADC channel support into gas module

Add example to demo ADC channel usage

Expand test coverage, bugfix

Adding delay to avoid rate-limiting by Luftdaten

+x

Switch temp comp method for pimoroni#28

Update all-in-one-no-pm.py

added decoding of bytestring to provide Python3 compatibility.

Update all-in-one.py

added decoding of bytestring to provide Python3 compatibility.

Update luftdaten.py

added decoding of bytestring to provide Python3 compatibility.

Merged cipy-master

Dropped obsolete .decode()

testing all examples, with corrections for Python3 support

allow temperature reads to converge a bit faster

use generic variables; handle pms5003.ReadTimeoutError

use generic variables in -no-pm code too

improved logging with timestamps (instead of print)

catching the correct ReadTimeoutError for pms5003

Replaced exception pass with log warning

Fix typo

Transitional fix for new LTR559 library

Added a new combined mode example

This is a modification of all-in-one.py. It adds another mode where all EnviroPlus and PMS5003 sensor readings are combined on one screen.

Each variable that is displayed can have custom warning limits assigned which change the color of the text according to a predefined RGB palette. It allows for a quick glance of all sensor readings at once in order to jugde if everything is OK in the air or to quickly pinpoint a sensor reading that requires attention.

In addition, the new combined mode saves each reading as soon as it is received for graphing later. As in all-in-one.py, moving your finger close to the proximity sensor switches the mode.

Fixed graphing problem for PMS5003 results

The PMS5003 library returns integers. This causes the current formula for color scaling of the graph to not work properly because of integer division instead of float division. Converting the PMS5003 results from int to float solves the problem.

Adding all in one weather and light display example

Adding Python 3 shebang

Python 3-related fixes, moving to pip fonts, fixing Astral errors.

Remove inappropriate sleep between reads

The PMS5003 seems to buffer unread samples. If you are reading at a lower rate than it takes readings, then a progressively larger delay will occur between changes in actual PM levels and indicated PM levels.

To see the issue:
1) run this example with the `time.sleep(1)` *included*
2) wait a few minutes
3) burn a piece of paper near the sensor and wait for the reported PM levels to spike

With the sleep included, there is a delay between introducing smoke and seeing reported levels rise (often a few minutes or longer). With the sleep removed you will see reported levels update almost immediately.

The correct way to use the sensor is to read as fast as the sensor allows, and not make any assumptions about what rate samples will be published at

Noise library and examples for basic FFT and frequency binning

Tidy up noise examples

Add dtoverlay for mic

Add DocStrings and linting

Fix noise-profile example

Add deps for noise measurement

Fix launch bug in all-in-one-no-pm.py

Launching all-in-one-no-pm.py results in an error due to line 57. FontSize should be replaced with the variable font_size, to run line 57 without error.

Sleep before first PMS5003 reading

Prep for v0.0.2

Update README for 0.0.2

Address Issue pimoroni#55

Fix noise_floor bug

Test tweaks and linting

I've re-written the tests to use conftest.py to set up and tear down mock modules via fixtures.

I have also linted the examples, removing redundant linebreaks, commenting out unused variables and attempting to simplify long lines.

Test noise, fix gas

Move package and requires to setup.cfg

Drop Python 2.6

Catch pimoroni#61 with tests and fix

Include python cffi in setup dependencies

Added supported board images and  example

Correcting examples

Adds mqtt example (pimoroni#68)

Adds mqtt example by @robmarkcole - see also: https://github.com/robmarkcole/rpi-enviro-mqtt

Added user projects section to README

Update mqtt-all.py

Fix combined.py indentation for Python 3.x

Experimental fix to communicate Py version reqs for pimoroni#78

Minute instead month in backup file name

Fix for the DATESTAMP variable, to show proper file name.

Added user project: enviroplus_exporter

Add GitHub actions workflow

Remove .travis.yml

Update python versions for CI (pimoroni#96)

* Drop Python 3.4 - GitHub reports it as not found, despite it being in the list it links to!?!?!?
* Fix Coveralls

Add two third party projects to the  README

adds username and password parameters to mqtt-all

adds username and password check

fix checking for username and password

Adding MQTT Username / Password & TLS Config

Signed-off-by: James Sutton <[email protected]>

Tweaking the arguments for MQTT TLS

Signed-off-by: James Sutton <[email protected]>

Adding MQTT Username / Password & TLS Config

Signed-off-by: James Sutton <[email protected]>

Add support for ADS1115

Use the auto-detect feature of the ADS1015 library to support reading the gas sensor via an ADS1115.

Add support for ADS1115

Switch README to markdown (drop dependency on pandoc)

Update luftdaten.py

Add Logging, PMS5003 Checksum exception and Luftdaten exception handling as per Issue pimoroni#81

Update luftdaten.py

Added suggested changes but removed "logging.info('Luftdaten Climate Success', values)", since I found it redundant, given the use of "logging.info("Luftdaten Response: OK")" in Line 215.

Drop Python2 support.

Linting fixes

Add available() method to gas sensor

This change catches an IOError when setting up the gas sensor and provides an `available()` method for determining if a sensor is present.

Trigger tests

Test read_all throws exception when unavailable

Fixup tests for ADC detect.

Update changelog & readme

Drop Python2 from Makefile

Correct README to python3

Direct users toward Python3, install explicitly

Add check-install.py debug script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants