I'm running the latest raspberry pi os "Linux raspberrypi 5.4.51-v7l+ #1327 SMP Thu Jul 23 11:04:39 BST 2020 armv7l GNU/Linux" on a Raspberrypi 4B 4Gb.
I've installed Python3
sudo apt-get install python3-dev python3-pip
Updated setuptools, wheel and pip
sudo python3 -m pip install --upgrade pip setuptools wheel
And installed Adafruit_DHT module
sudo pip3 install Adafruit_DHT
After that i've connected my DHT22 to my rpi on gpio4 and created the following python script:
import Adafruit_DHT
import time
from datetime import datetime
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
PROBE_NAME = "PI4"
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("{2} - T={0:0.1f} H={1:0.1f}".format(temperature, humidity, datetime.now()))
else:
print("Failed to retrieve data from humidity sensor")
Than i run it
sudo python3 temp.py
and i get the following error
Traceback (most recent call last):
File "temp.py", line 11, in <module>
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
File "/usr/local/lib/python3.7/dist-packages/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/common.py", line 80, in read
platform = get_platform()
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/common.py", line 60, in get_platform
from . import Beaglebone_Black
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/Beaglebone_Black.py", line 24, in <module>
from . import Beaglebone_Black_Driver as driver
ImportError: cannot import name 'Beaglebone_Black_Driver' from 'Adafruit_DHT' (/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/__init__.py)
Any idea how to get it working?
I've done the exact same steps on a raspberry pi zero w and it works out of the box
In "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/platform_detect.py", you can add the followings at line #112 in the elif ladder, so it should workaround the issue.
elif match.group(1) == 'BCM2711':
return 3
It looks like the hardware name in the /proc/cpuinfo has been changed due to the recent raspbian upgrade.
The solution of Kotaro Hashimoto works. I had the same problem with my Pi4.
The real problem is that AdaFruit no longer supports nor updates this old Adafruit_DHT library. The new library from AdaFruit for this sensor is "Adafruit_CircuitPython_DHT" can be found here. It could be a good idea to update your code to this new library.
https://github.com/adafruit/Adafruit_CircuitPython_DHT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With