cannot import name 'Beaglebone_Black_Driver' from 'Adafruit_DHT'

Viewed 15117

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

4 Answers

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

After Raspberry Pi OS released, and Adafruit DHT library is deprecated, I have the same issue.

I solved it by using the new released library from Adafruit.

Adafruit CircuitPython DHT

Try this example:

import adafruit_dht
from board import *

# GPIO17
SENSOR_PIN = D17

dht22 = adafruit_dht.DHT22(SENSOR_PIN, use_pulseio=False)

temperature = dht22.temperature
humidity = dht22.humidity

print(f"Humidity= {humidity:.2f}")
print(f"Temperature= {temperature:.2f}°C")

Output:

Humidity= 65.70
Temperature= 22.30°C

Considering my environment:

  • Raspberry Pi 4 Model B (RAM 4GB)
  • Python 3.7
  • Raspberry Pi OS
  • DHT 22 (AM2302)

I tried using circuitpython and did as instructed, it all worked ok, until i stopped the python script and tried restarting it only to get errors like:

Unable to set line 18 to input Timed out waiting for PulseIn message

and i just dont have the knowledge to resolve it in code - searching the web appears like many other people get the same issue, and killing process's every time or rebooting to fix it just isnt viable

IMHO the circuit python way is either rubbish, buggy or not properly documented, (probably all 3), so i did the fix above and used the old library which works.

Related