Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot import name 'Beaglebone_Black_Driver' from 'Adafruit_DHT'

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

like image 830
Flavio CF Oliveira Avatar asked Aug 03 '20 15:08

Flavio CF Oliveira


2 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.

like image 118
Kotaro Hashimoto Avatar answered Nov 06 '22 16:11

Kotaro Hashimoto


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

like image 5
DavidE Avatar answered Nov 06 '22 18:11

DavidE