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.

DHT sensor not found, check wiring

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jposada202020commented, Feb 25, 2021

@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.

1reaction
jposada202020commented, Feb 26, 2021

@Tob1as Thanks, Changes are merged, they will be released soon!, and thanks fr the feeback and testing on the changes (y)

Read more comments on GitHub >

github_iconTop Results From Across the Web

DHT 11 sensor not found, check wiring
Hint: Try running it in the loop like in the dht_simpletest.py - as @Milliways mentioned the python library is not stable. Running in...
Read more >
Wiring DHT11 to Raspberry pi - Python Forum
I have wired in the 3-wire DHT11 sensor like this on my RP 2 model B version 1: ... and I keep getting...
Read more >
Raspberry Pi: DHT 11 sensor not found, check wiring - YouTube
Raspberry Pi: DHT 11 sensor not found, check wiringHelpful? Please support me on Patreon: https://www.patreon.com/roelvandepaarWith thanks ...
Read more >
[SOLVED] DHT11/DHT22 - Failed to read from DHT sensor
1. Wiring. When you're building an electronics project, you need to double-check the wiring or pin assignment. · 2. Power · 3. Bad...
Read more >
Problem about DHT11 sensor - Raspberry Pi Forums
I'm tryng to configure DHT11 sensor. ... if humidity is not None and temperature is not None: ... print("Sensor failure. Check wiring.");
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