求助树莓派4b DHT11湿度传感器Python程序错误 急!!!

xiaohuang 2021-04-0747 次点击
以下为程序:
```
import Adafruit_DHT
import time

makerobo_pin = 17 # DHT11 温湿度传感器管脚定义

# GPIO口定义
def makerobo_setup():
global sensor
sensor = Adafruit_DHT.DHT11

# 循环函数
def loop():
humidity, temperature = Adafruit_DHT.read_retry(sensor, makerobo_pin)
while True:
if humidity is not None and temperature is not None:
print('Temp={‌‌0:0.1f}*C Humidity={‌‌1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
time.sleep(1) # 延时1s

def destroy():
GPIO.cleanup() # 释放资源

# 程序入口
if __name__ == '__main__':
makerobo_setup()
try:
loop()
except KeyboardInterrupt: # 当按下Ctrl+C时,将执行destroy()子程序。
destroy()

```



出现的错误:
Traceback (most recent call last):
File "/home/pi/CLBDEMO/27_humiture.py", line 28, in <module>
loop()
File "/home/pi/CLBDEMO/27_humiture.py", line 13, in loop
humidity, temperature = Adafruit_DHT.read_retry(sensor, makerobo_pin)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT-1.4.0-py3.7-linux-armv7l.egg/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT-1.4.0-py3.7-linux-armv7l.egg/Adafruit_DHT/common.py", line 81, in read
return platform.read(sensor, pin)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT-1.4.0-py3.7-linux-armv7l.egg/Adafruit_DHT/Beaglebone_Black.py", line 202, in read
match = re.match('GPIO([0123])_(\d+)', pin, re.IGNORECASE)
File "/usr/lib/python3.7/re.py", line 173, in match
return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object

不知如何解决 毕设项目 哭了!!!求大神
收藏 ♥ 感谢
Spoony 小组长 2021-04-08 
看起来是 Adafruit_DHT 这个库里面的 BUG

https://blog.csdn.net/weixin_42683639/article/details/89365846
相逢已是初识 33.6m 2021-04-08 
先看看文件有没有问题吧,再看看数据类型是否匹配, (•̀ᴗ•́)و ̑̑
店长大人 50cm 2021-04-08 
感觉是数据类型跟你的函数不匹配啊。
店长大人 50cm 2021-04-08  ♥ 1
这个库有问题,目前只支持到树莓派3b+,并没有更新最新的4B BCM2711的支持,所以,你可以考虑换个其他库,或者添加对BCM2711的支持。
https://www.cnblogs.com/ucas123/p/13904528.html

登录注册 后可回复。