I am trying to read the temperature and humidity data in DHT22 sensor using Raspberry Pi 4 board by following the python scripts below
import Adafruit_DHT
DHT22Sensor = Adafruit_DHT.DHT22
DHTpin = 16
humidity, temperature = Adafruit_DHT.read_retry(DHT22Sensor, DHTpin)
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!')
However, when I tried to run the code, the following error appears:
Traceback (most recent call last):
File "test_DHT.py", line 6, in <module>
humidity, temperature = Adafruit_DHT.read_retry(DHT22Sensor, DHTpin)
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
Does anyone why is it happen? Thank you!