0

I have RPI Zero with DHT11 connected as recommended (diagram) and I was reading data from it with ~90 % success rate every 5 minutes using the old Adafruit library. But today morning it stopped receiving data so I tried to troubleshoot it using new Adafruit library and it seems like there is connection issue:

DHT sensor not found, check wiring

Notes:

  • I am using 10K resistor.
  • DHT11 is connected to GPIO4 (pin 7)
  • I was able to measure voltage changes on the sensor, so I believe the wiring is OK

When running joans DHT.py, I was able to read the values for the first time, but then error appered:

pi@raspberrypi:~/Teplomer $ ./DHT.py 4
1583582364.035  4 0 24.0 57.0
1583582366.112  4 2 24.0 57.0
^Ccancelling 4
pi@raspberrypi:~/Teplomer $ ./DHT.py 4
1583582386.131  4 2 0.0 0.0
1583582388.205  4 2 0.0 0.0
1583582390.279  4 2 0.0 0.0
^Ccancelling 4
pi@raspberrypi:~/Teplomer $
pi@raspberrypi:~/Teplomer $ ./DHT.py 4
1583582738.135  4 3 0.0 0.0
1583582740.407  4 0 23.0 53.0
1583582742.480  4 2 23.0 53.0
^Ccancelling 4
pi@raspberrypi:~/Teplomer $ ./DHT.py 4
1583582746.751  4 0 23.0 53.0
1583582748.825  4 2 23.0 53.0
1583582750.899  4 2 23.0 53.0
^Ccancelling 4
pi@raspberrypi:~/Teplomer $ ./DHT.py 4
1583582779.302  4 2 0.0 0.0
1583582781.376  4 0 23.0 53.0

However, I did not move any parts so it seems like the sensor is dead?
How can I troubleshoot it?

Thank you!

Wiring

FN_
  • 103
  • 1
  • 3
  • You are feeding 5V into the Pi GPIO (you have a pull-up between 5V and the GPIO). That might destroy the GPIO/Pi. – joan Mar 07 '20 at 17:00
  • I have found both 3 and 5V diagrams, does this mean RPi's GPIO is only 3V tolerant and I should use only 3V? https://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-the-raspberry-pi/ – FN_ Mar 07 '20 at 18:43
  • You should not feed more than 3V3 into a Pi GPIO. I use a resistor divider to drop a 5V output to a Pi safe 3V3. So if you use 5V use something like a resistor divider on the output to the GPIO. – joan Mar 07 '20 at 20:36
  • It is hardly surprising it is unreliable! Just sticking du-pont cables through header holes is hit or miss. Also DO NOT put 5V on the GPIO. – Milliways Mar 07 '20 at 23:31
  • @joan OK, taking note about the right voltage for Pi. So what should I do now? Get another Pi for testing? Is there a way how to check what is the issue? – FN_ Mar 09 '20 at 11:06
  • @Milliways I have soldered those dupont cables, to make good contact. – FN_ Mar 09 '20 at 11:06
  • To comment on your question to Joan - connecting 5V to a GPIO through a 10kΩ resistor is unlikely to have caused damage (because the resistor limits current) but is still not recommended. – Milliways Mar 09 '20 at 11:12
  • Remove the DHT and anything else from the expansion header then run gpiotest from the command line. – joan Mar 09 '20 at 11:17
  • @joan Test passed fine, so I suspect faulty DHT sensor now... 'Failed user gpios: None' – FN_ Mar 09 '20 at 13:25
  • Possibly faulty. However it's not really clear how secure the connections between the Pi and the sensor are. If they are loose you will get erroneous responses. – joan Mar 09 '20 at 14:28
  • @joan I soldered dupont cables and I can measure voltage changes (will check later using oscilloscope), let me think about better solution how to ensure the connection is more secure and I will let you know with the update, thank you for the help btw – FN_ Mar 09 '20 at 14:52
  • @joan I have received ordered DHT11 and bought a RPi WH too. With this new setup everything works fine! I will use your code in my future projects, thank you! :) – FN_ Mar 19 '20 at 10:51

2 Answers2

2

Run my DHTXX script.

It requires the pigpio daemon do be running.

sudo pigpiod

It expects the Broadcom number of the GPIO connected to the data line.

E.g. ./DHT.py 4 to read a sensor connected to pin 7.

Refer to https://pinout.xyz/

joan
  • 71,024
  • 5
  • 73
  • 106
  • Thank you for the comment, I receive error code 3 - DHT_TIMEOUT. Is there a way how to test whether is the sensor OK? – FN_ Mar 07 '20 at 11:16
  • @FilipNiko Add a photo to your question. The photo should be clear enough to see the connections between the Pi pins and the DHT11 pins. We can then check that your connections are okay and see which GPIO you are using. – joan Mar 07 '20 at 11:31
  • EDIT: Now I moved from error code 3 to 2, dunno what is going on :( – FN_ Mar 07 '20 at 11:34
1

I had previously used the Adafruit code but found it unreliable and rather restrictive.

I now use Joan's pigpio code, and found it quite reliable.
See https://raspberrypi.stackexchange.com/a/105549/8697

I wrote my own wrapper around the DHT.py module to make things easier (Joan writes great code, but the documentation is very sparse). This has been running for months without trouble, through updates power failures etc.

One advantage is that if no DHT11 found it doesn't lock up like the Adafruit code. The DHT11 is quite critical about timing, and occasionally misses a reading if the Pi is otherwise busy, so it retries 5 times before giving up.

It should be simple to strip out the MQTT code to adapt to your needs.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • Thanks for the comment, I will stick to the original DHT.py for the troubleshoot and maybe later use your wrapped :) – FN_ Mar 07 '20 at 12:49