1

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!

1 Answer 1

0

It seems like the Adafruit_DHT package does not support the Raspberry Pi 4 - only up to Raspberry Pi 3b+. In your case it detects a Beaglebone Black.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.