adafruit / Adafruit_CircuitPython_DHT

CircuitPython support for DHT11 and DHT22 type temperature/humidity devices
MIT License
179 stars 62 forks source link

Immediately pause pulse_in after initialization #47

Closed michaellass closed 3 years ago

michaellass commented 3 years ago

Right now, pulse_in is active until the first reading and only paused after that. Let's immediately pause it to free up the CPU.

This problem was reported by @lane-maxwell at https://github.com/adafruit/Adafruit_Blinka/issues/210#issuecomment-669623485.

This is only mildly tested right now, so please do not merge immediately.

lane-maxwell commented 3 years ago

Impressive turnaround, thank you.

michaellass commented 3 years ago

@lane-maxwell Could you confirm that this fixes the problem for you?

kattni commented 3 years ago

@michaellass @lane-maxwell Please feel free to tag me directly once you've gotten this tested, and I'll request a review from our review group.

baddonkey commented 3 years ago

@lane-maxwell Could you confirm that this fixes the problem for you?

Had pretty much the same problem with 100% CPU of libgpiod_pulsein on Raspberry Pi 3. Patching my local environment with this commit fixed it.

lane-maxwell commented 3 years ago

I can also confirm, this resolved the issue for me. Thank you

git clone git@github.com:michaellass/Adafruit_CircuitPython_DHT.git
cd Adafruit_CircuitPython_DHT/
git checkout -b start_paused
git branch --set-upstream-to=origin/start_paused start_paused
git pull
pip3 install .
michaellass commented 3 years ago

I also had this in use now for a while, so @kattni, I think this is ready for review from your side.

hkeown commented 3 years ago

Been experiencing erratic hanging of RPi-4 Buster (RPi) since migrating to Circuit Python.

Executed: pip3 install --upgrade --force-reinstall adafruit-blinka.

RPi still hangs/crashes.

Using PTTY via ethernet (ping to router to see when link goes down) and serial port for extra debugging (running HTOP).

When executing my_py script, RPi will either:

  1. Hang and Ethernet connection is dropped, HTOP on the serial port is still running. 2) Hang, kill Ethernet and hang the serial port/HTOP - RPi requires a power cycle.

See below a screen shot of HTOP: Annotation 2020-08-26 123912

Observation: After a power-up, the py script is stuck in a long wait process, and recovers. But subsequent execution of the script waits for a shorter time period, and continues, no problem.

Pls advise any other information that I can provide from my side to assist resolving this issue.

michaellass commented 3 years ago

@hkeown Do you use this DHT library or some other part of Blinka that uses pulseio? To update this library, you would need to run pip3 install --upgrade --force-reinstall adafruit-circuitpython-dht

However, this change has just been merged and the change is not included yet in the version you get via pip. You can however edit /usr/local/lib/python3.7/dist-packages/adafruit_dht.py (I guess that is the location) manually as shown here: https://github.com/adafruit/Adafruit_CircuitPython_DHT/pull/47/files#diff-3cb2b6ae0f442877839768eb1ea0386d

That all said, I find it very surprising that this library has any influence on the functionality of ethernet or serial connections.

darton commented 3 years ago

The problem with 100% usage of libgpiod_pulsein CPU on Raspberry Pi with DHT22 still exists.

However, sometimes you have to wait several hours for it to appear and permanently prevent reading data from the DHT22 sensor.

After today's update to the version below, the script runs 8 hours without any problems.

Raspbian GNU/Linux 10 (buster) Raspberry Pi 3 Model B Plus Rev 1.3 Python 3.7.3 Adafruit-Blinka-5.3.4 Adafruit-PlatformDetect-2.16 Adafruit-PureIO-1.1.5 RPi.GPIO-0.7.0 adafruit-circuitpython-dht-3.5.1 pyftdi-0.51.2 pyserial-3.4 pyusb-1.0.2 rpi-ws281x-4.2.4 sysv-ipc-1.0.1

darton commented 3 years ago

But after 8 hours, the problem came back.