adafruit / Adafruit_CircuitPython_DHT

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

DHT22 report null after a while #40

Open beneton2003 opened 4 years ago

beneton2003 commented 4 years ago

BUG DESCRIPTION Hello *. I have a problem with my DHT22. After some time (hours, days) I get null values from sensor. So I attached 2 sensors to my raspberry pi via GPIO2, 27.

The results are confusing: If one sensors show null, one other may keep reporting good values! Reboot of rpi does not help at all. Hard reset (Power off / on) of rpi always works. Power reset (3.3-5V off / on) of a sensor only SOMETIMES works. Data reset (pull cable and replug) of sensor works almost always. If data reset (on ONE sensor) works, other null sensor will start reporting good values as well!

EXPECTED BEHAVIOR Get both values.

THE SAME ISSUES I had found the same issue on github https://github.com/arendst/Tasmota/issues/5619 Those guiys was make some change in reading algorythm, i was try to make the same changes, but i found that i can't make any changes to /usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/libgpiod_pulsein i'm not sure if i am going right way. I think those guys find a way out https://github.com/arendst/Tasmota/pull/7440

beneton2003 commented 4 years ago

If I add a print(pulses) around line 178 (file /usr/local/lib/python3.7/dist-packages/adafruit_dht.py), I see: image

if i make hard reset or data cable reset, everything will works fine for about 12 hours, maybe 10, sometimes more or less

beneton2003 commented 4 years ago

I was also try to uncomment debug flag in /usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py

image

as we can see libgpiod_pulsein return empty value, i am not sure why is this happens, as i see the commands make right ['/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/libgpiod_pulsein', '--pulses', '81', '--queue', '10318', '-i', 'gpiochip0', '2']

['/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/libgpiod_pulsein', '--pulses', '81', '--queue', '20924', '-i', 'gpiochip0', '27']

I was trying to execute them in bash (without brakets and others), but nothing happens

jnt2007 commented 4 years ago

What brand of sensors are you using? Asair or Aosong?

beneton2003 commented 4 years ago

I use both asair and aosong, but asair have a troubles, should i change it with aosong?

jnt2007 commented 4 years ago

I have problems with Asair too. So I changed it to Aosong and problem not reproduced more than one month

kattni commented 4 years ago

@beneton2003 @jnt2007 It appears that Adafruit sells the Aosong branded sensor. Where did you purchase the Asair sensor?

jnt2007 commented 4 years ago

On Ebay or Aliexpress, sent from China. Frequently Asair sensor has a little bit lowest price.

mryshakow commented 4 years ago

I have the same issue with both Asair and Aosong... only reconnecting the sensor will bring it back alive. This is super annoying. Can I provide more information to resolve this issue?

RPi3 DHT22 connected via 1,5m cable DHT22 connected to 5V Pull Up Resistor 10K Read every 5 seconds

// Edit:

I can determine that the false behaviour only occurs (Not every time, not all sensor at that time) when another GPIO is switched... In my case its a relay on a relay board that is controlled via Pi4J in an indipendand micro service.

evaherrada commented 3 years ago

I can determine that the false behaviour only occurs (Not every time, not all sensor at that time) when another GPIO is switched... In my case its a relay on a relay board that is controlled via Pi4J in an indipendand micro service.

@mryshakow Good job noticing that. That should make it much easier to solve this.

evaherrada commented 3 years ago

@mryshakow Are you using the configuration that needs pulseio?

Edit: Looks like both setups need pulseio, which I don't think should be the case

evaherrada commented 3 years ago

@mryshakow I wasn't able to fully reproduce the error, but I think I may have found the culprit.

Can you comment out lines 37-42 of adafruit_dht.py?

It should look something like this when you're done comment

Then, make sure it's setup like this. That way will do bit-banging instead of using pulseio. Basically, just hook up the resistor like in the picture, take the power to 3.3v, the ground to ground, and the data wire to whichever gpio pin you've been using. weather_m0_dht_bb

Let me know if that works.

foarsitter commented 3 years ago

I can determine that the false behaviour only occurs (Not every time, not all sensor at that time) when another GPIO is switched... In my case its a relay on a relay board that is controlled via Pi4J in an indipendand micro service.

Experiencing the same with a relay and an AM2302. Can a "back electromotive force" be the problem: https://raspberrypi.stackexchange.com/questions/44060/dht22-temp-sensor-randomly-dropping/44109#44109?

Update: in my setup I have a refrigerator. When the compressors was turned off by the refrigerator thermostat the AM2302 stopped working. I'm now controlling the refrigerator by a relay and do not experience trouble anymore. So in my situation it was not a software related problem but an electrical one. Consider adding a transistor to you setup so you can toggle the power of the sensor when needed.