[英]Raspberry Pi DHT 11 sensor not working. I get None None
Have integrated Raspberry pi4 with a DHT sensor.集成了带有 DHT 传感器的 Raspberry pi4。 The data pin is connected to pin GPIO 26
数据引脚连接到引脚 GPIO 26
Have tried connecting the VCC to both 3.3V and 5V已尝试将 VCC 连接到 3.3V 和 5V
Have tried with both Adafruit_DHT.DHT11 and Adafruit_DHT.DHT22 in the code for the same sensor but I get None None已尝试在同一传感器的代码中同时使用 Adafruit_DHT.DHT11 和 Adafruit_DHT.DHT22,但我得到 None None
import Adafruit_DHT
# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = Adafruit_DHT.DHT22
pin = 26
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print(temperature, humidity)
Output: Output:
None None无 无
Is the sensor broken??Should I replace it or is there any other solution??传感器坏了吗??我应该更换它还是有其他解决办法??
from pigpio_dht import DHT11, DHT22
gpio = 4 # BCM Numbering
sensor = DHT11(gpio)
#sensor = DHT22(gpio)
result = sensor.read()
print(result)
This worked for me.这对我有用。 Before running the code enter the below commands on the terminal
在运行代码之前,在终端上输入以下命令
sudo pigpiod #Start daemon
pigs pud 4 u # Set internal pull up
If pigpio-dht is not installed enter pip3 install pigpio-dht
and run the above program如果没有安装 pigpio-dht 输入
pip3 install pigpio-dht
并运行上述程序
After 3 days with the same issue and trying all of the above (even bought a new DHT11), the issue with just with the GPIO's.在遇到同样的问题 3 天并尝试了上述所有方法(甚至买了一个新的 DHT11)后,问题只出在 GPIO 上。 I manually had to "push" the pin GPIO-4 to make it contact with the recevier end of the DHT11 cable.
我不得不手动“推动”引脚 GPIO-4 以使其与 DHT11 电缆的接收端接触。
my code was simpler version:我的代码是更简单的版本:
import Adafruit_DHT
import sys
while True:
humidity, temperature = Adafruit_DHT.read_retry(11,4)
print(temperature, humidity)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.