已将DHT11连接到Rpi4。
VCC--引脚1
datapin--gpio4
接地引脚--引脚6
它工作得很好,但在给出几次结果后,我得到了这个错误。pigpio新手,请帮我找出问题所在
import time
from pigpio_dht import DHT11, DHT22
while True:
gpio = 4 # BCM Numbering
sensor = DHT11(gpio)
#sensor = DHT22(gpio)
result = sensor.read()
temperature=([value for value in result.values()][0])
print(temperature)
humidity=([value for value in result.values()][2])
print(humidity)
time.sleep(10)输出:
28
46
28
46
28
46
28
46
28
46然后,我得到了以下内容:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)
Can't create callback thread.
Perhaps too many simultaneous pigpio connections.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
File "dht8.py", line 9, in <module>
sensor = DHT11(gpio)
File "/home/pi/.local/lib/python3.7/site-packages/pigpio_dht/dht11.py", line 24, in __init__
super(DHT11, self).__init__(gpio, pi=pi, timeout_secs=timeout_secs, use_internal_pullup=True, max_read_rate_secs=1, datum_byte_count=1)
File "/home/pi/.local/lib/python3.7/site-packages/pigpio_dht/dhtxx.py", line 47, in __init__
self._pi.set_pull_up_down(gpio, pigpio.PUD_UP)
File "/usr/lib/python3/dist-packages/pigpio.py", line 1385, in set_pull_up_down
return _u2i(_pigpio_command(self.sl, _PI_CMD_PUD, gpio, pud))
File "/usr/lib/python3/dist-packages/pigpio.py", line 993, in _pigpio_command
sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'提前感谢
发布于 2021-03-11 21:03:48
您在while循环中设置了设备,因此它创建了同一设备的多个实例,因此产生了错误代码
Can't create callback thread.
Perhaps too many simultaneous pigpio connections.您需要创建一个设备实例,并长期从传感器读取信息。像这样的东西会起作用的:
import time
from pigpio_dht import DHT11, DHT22
gpio = 4 # BCM Numbering
sensor = DHT11(gpio)
while True:
result = sensor.read()
temperature=([value for value in result.values()][0])
print(temperature)
humidity=([value for value in result.values()][2])
print(humidity)
time.sleep(10)https://stackoverflow.com/questions/66578398
复制相似问题