question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DHT11 not working properly

See original GitHub issue

Using version 3.5.8 in a loop it almost never gets a reading with the following code:


import time
import board
import adafruit_dht

dhtDevice = adafruit_dht.DHT11(board.PG6)


for try_number in range(1,200):
  print(f"Try number {try_number}")
  try:
    print(f"Got temp of: {dhtDevice.temperature}")
    print(f"And hum of: {dhtDevice.humidity}")
    break
  except RuntimeError as e:
    print(e)
    time.sleep(2.1)
  else:
    time.sleep(2.1)
  print("\n")

The weird part is that using the version 3.5.5 it actually get the readings correctly.

More data: Python: 3.8.5 SBC: Orange Pi Lite Installed libraries:

Adafruit-Blinka==6.4.1
adafruit-circuitpython-busdevice==5.0.6
adafruit-circuitpython-dht==3.5.5
adafruit-circuitpython-mcp3xxx==1.4.5
Adafruit-PlatformDetect==3.4.0
Adafruit-PureIO==1.1.8
appdirs==1.4.4
attrs==20.3.0
bcrypt==3.2.0
cached-property==1.5.2
certifi==2019.11.28
cffi==1.14.3
chardet==3.0.4
cryptography==3.2.1
dbus-python==1.2.16
distlib==0.3.1
distro==1.5.0
distro-info===0.23ubuntu1
docker==4.3.1
docker-compose==1.27.4
dockerpty==0.4.1
docopt==0.6.2
filelock==3.0.12
idna==2.8
iotop==0.6
jsonschema==3.2.0
mudpi==0.10.0
paho-mqtt==1.5.1
paramiko==2.7.2
pycparser==2.20
pyftdi==0.52.9
PyGObject==3.36.0
PyNaCl==1.4.0
pyrsistent==0.17.3
pyserial==3.5
python-apt==2.0.0+ubuntu0.20.4.4
python-dotenv==0.15.0
pyusb==1.1.1
PyYAML==5.3.1
redis==3.5.3
requests==2.22.0
requests-unixsocket==0.2.0
six==1.14.0
texttable==1.6.3
unattended-upgrades==0.1
urllib3==1.25.8
virtualenv==20.1.0
websocket-client==0.57.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
yeyeto2788commented, Mar 17, 2021

I hope it is a DHT11 because it actually looks like one, my sensor is this one which was bought on other site.

Regarding that datasheet it states the following:

the programme of MCU will set Data Single-bus voltage level from high to low and this processmust take at least 18ms to ensure DHT’s detection of MCU’s signal

So it has to be AT LEAST 18ms and I’m actually getting better results with less than that (1.85ms)🤮

If you need me to test something else just let me know.

P.D: I can also contact me through Discord and probably it would be more faster.

0reactions
olixrcommented, Mar 30, 2021

I wanted to add some testing to help give more data. I have a RPi4 that works fine with both the DHT11 and DHT22. I also have a RPi zero w but it has more trouble getting reads from both the DHT11 and DHT22. I thought I would run tests on the zero and see if it helps reveal more on the timings.

Here are some details:

Installed packaged

Package                          Version
-------------------------------- -------------------
Adafruit-Blinka                  6.4.1
adafruit-circuitpython-74hc595   1.2.4
adafruit-circuitpython-bme680    3.3.2
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-charlcd   3.1.2.dev7+g07007b4
adafruit-circuitpython-debouncer 1.3.10
adafruit-circuitpython-dht       3.5.8
adafruit-circuitpython-mcp230xx  2.4.5
Adafruit-PlatformDetect          3.4.1
Adafruit-PureIO                  1.1.8
asn1crypto                       0.24.0
certifi                          2018.8.24
chardet                          3.0.4
cryptography                     2.6.1
entrypoints                      0.3
idna                             2.6
keyring                          17.1.1
keyrings.alt                     3.1.1
mudpi                            0.10.0
numpy                            1.16.2
paho-mqtt                        1.5.1
pip                              18.1
pycron                           3.0.0
pycrypto                         2.6.1
pyftdi                           0.52.9
PyGObject                        3.30.4
pyserial                         3.5
python-apt                       1.8.4.3
pyusb                            1.1.1
pyxdg                            0.25
PyYAML                           5.4.1
redis                            3.5.3
requests                         2.21.0
rpi-ws281x                       4.2.6
RPi.GPIO                         0.7.0
SecretStorage                    2.3.1
setuptools                       40.8.0
six                              1.12.0
ssh-import-id                    5.7
sysv-ipc                         1.1.0
urllib3                          1.24.1
wheel                            0.32.3

Board: RPi Zero W Python: 3.7.3

Test Script Results

RPi Zero W DHT22 (Range: 500 - 2000) (Increments: 100)
Maximum reads: 10  out of 10 with the following times: 1000, 1900


RPi Zero W DHT11 (Range: 15000 - 24800) (Increments: 100)
Maximum reads: 10  out of 10 with the following times: 15100, 15300, 15400, 15500, 16800, 17000, 17200, 17300, 18900, 19900, 20000, 20200, 20600, 21000, 22200, 22700, 24100
Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] DHT11/DHT22 - Failed to read from DHT sensor
1. Wiring · 2. Power · 3. Bad USB port or USB cable · 4. Power source · 5. Sensor type · 6....
Read more >
Problem with DHT11 on UNO (FIXED) - Arduino Forum
HI, I have used dht11 sensors before without problem, but now can't get it to work. I have two of them and same...
Read more >
[SOLVED] "Failed to read from DHT sensor!" - Losant Forums
You'll need to increase the underlying MQTT library's memory limit. The PubSubClinet MQTT library has a default memory limit that is not enough ......
Read more >
DHT11 interface Errors - Raspberry Pi Forums
If you're powering the sensor from a 3.3V pin, in some cases powering the DHT with 5V solves the problem. ... Sometimes powering...
Read more >
Problem with a DHT11 Temperature & Humidity sensor
Finally I was able to solve the problem by not using the resistor and connecting it directly, I also had a problem with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found