Adafruit_CircuitPython_DHT: DHT sensor not found, check wiring
I’m using DHT11 on Rpi 4B and I turn to using Adafruit_CircuitPython_DHT today from Adafruit_Python_DHT. I had changed my code to fit the Adafruit_CircuitPython_DHT, but when I run it I meet this error:
Traceback (most recent call last):
File "tmpv0.2.py", line 44, in <module>
main()
File "tmpv0.2.py", line 23, in main
temperature = dht_device.temperature
File "/usr/local/lib/python3.8/dist-packages/adafruit_dht.py", line 253, in temperature
self.measure()
File "/usr/local/lib/python3.8/dist-packages/adafruit_dht.py", line 205, in measure
raise RuntimeError("DHT sensor not found, check wiring")
RuntimeError: DHT sensor not found, check wiring
I am sure the connection is fine, because after this error I run the former code and it work perfectly.
Here is the code that has been change to fit Adafruit_CircuitPython_DHT
import datetime
import time
import adafruit_dht
from board import D4
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
from PIL import ImageFont
# OLED settings
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
font = ImageFont.truetype('simyou.ttf', 15)
# DHT11 settings
dht_device = adafruit_dht.DHT11(D4)
def main():
while True:
temperature = dht_device.temperature
humidity = dht_device.humidity
if humidity is not None and temperature is not None:
Temperature = "温度: {0:0.1f}°C".format(temperature)
Humidity = "湿度: {0:0.1f}%".format(humidity)
print(Temperature, Humidity)
for i in range(0, 10):
now = datetime.datetime.now()
today_time = now.strftime("%H:%M:%S")
with canvas(device) as draw:
draw.text((30, 4), today_time, font=font, fill="white")
draw.text((10, 23), Temperature, font=font, fill="white")
draw.text((10, 42), Humidity, font=font, fill="white")
time.sleep(0.2)
else:
print('失败')
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
device.cleanup()
pass
And here is the former code
import datetime
import time
import Adafruit_DHT
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
from PIL import ImageFont
# OLED settings
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
font = ImageFont.truetype('simyou.ttf', 15)
# DHT11 settings
sensor = Adafruit_DHT.DHT11
DHT11pin = 4
def main():
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, DHT11pin)
if humidity is not None and temperature is not None:
Temperature = "温度: {0:0.1f}°C".format(temperature)
Humidity = "湿度: {0:0.1f}%".format(humidity)
print(Temperature, Humidity)
for i in range(0, 10):
now = datetime.datetime.now()
today_time = now.strftime("%H:%M:%S")
with canvas(device) as draw:
draw.text((30, 4), today_time, font=font, fill="white")
draw.text((10, 23), Temperature, font=font, fill="white")
draw.text((10, 42), Humidity, font=font, fill="white")
time.sleep(0.2)
else:
print('失败')
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
device.cleanup()
pass
I am new to python and Rpi, and thanks for any help!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 31 (1 by maintainers)
@Tob1as I review the PR, and I was wrong. Sorry about that. The intended change in 3.5.6 was to addresses mentioned the trigger time for DHT11. However in doing so, I used the ‘//’ division instead of the / division, given a 0 every time. I have just submitted a new PR #64 to correct this. Thank you for pointing that out.
Hi,
i’m facing the same problem.
This does not run …
which end up in “DHT sensor not found, check wiring”
while
works like a charm.
Any ideas?
@Tob1as Thanks, Changes are merged, they will be released soon!, and thanks fr the feeback and testing on the changes (y)
FWIW I’m using the below code that I set up last week (13 Feb) and it works perfectly with a DHT22 connected to pin 4. Swap out the 22 for an 11 and change the dhtDevice setting to DHT11 and it gives me DHT sensor not found (same wiring - literally just changed out the 22 for an 11). I’ve tried it with 4 different DHT11’s and 2 DHT22’s - the 22’s both work fine (about 50/50 valid reading + error messages various) but the 11’s don’t work at all.
from https://tutorials-raspberrypi.com/raspberry-pi-measure-humidity-temperature-dht11-dht22/
@bsolino Agree with this kind of sensor everything could go wrong, and is very difficult to troubleshoot. These Sensor are very time dependent, and this is something that the RP is not very good at. At least in my experience. But the RP3 is indeed strange both have worked in my case, inconsistent but worked.
@bsolino Hello, I did a little investigation into this, you can follow my results here https://github.com/jposada202020/DHT_Investigation But I have never been able to read a DHT sensor in a Raspberry PI Zero. I tried both the DHT11 and the DHT22. I saw that you followed the recommendation to not to use Pin 4. In my tests I used pin D17. However, I can read in both sensor in the RP3/4 do you happen to have one in hand?
I’ve been struggling with this issue too. I know the wiring is right because it works sometimes. However, I’m trying now a DHT22 and it is extremely temperamental, sometimes taking several minutes before correct readings. I’ve also encountered a few instances of “A full buffer was not returned. Try again.”. I have modified the code to actually show the number of pulses received, and oddly enough it usually doesn’t receive any pulses.
As an example, I have this code that checks the sensor every two seconds. I’m using here a DHT22 sensor on a RaspberryPi Zero W, pin 4, and using the pulseio method. I’ve also tried pin 18 (as recommended above), with similar results.
I used to have a DHT11 sensor, and that one also had this issue often, but not as frequently. I could usually get 5 correct readings in 1 or 2 minutes. Unfortunately, it seems I’ve burned it so I can’t do tests with it anymore.
For reference, my pip list:
I think it wrong to solve a problem by using a deprecated libraray which links to this (CircuitPython) library. However it’s a dirty but working hack.