Flavio CF Oliveira
Flavio CF Oliveira

Reputation: 5285

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

Upvotes: 11

Views: 18207

Answers (5)

Zrn-dev
Zrn-dev

Reputation: 169

  • Rasperry pi 4 model b
  • dht11
import time
import Adafruit_DHT  #Adafruit_DHT , adafruit_dht both are needed
import adafruit_dht
from board import *


DHT_PIN = D17       # GPIO17
dht11 = adafruit_dht.DHT11(DHT_PIN, False)

while True:
    try:
        dht11.measure()
        temp = dht11.temperature
        humid = dht11.humidity

        if humid is not None and temp is not None:
            print(f"temp= {temp:.2f}°C")
            print(f"humid= {humid:.2f}")
        else:
            print("failed to get reading from the sensor.Try again!")
        
    except RuntimeError as error:
        print("runtime error: "+str(error.args[0]))
    time.sleep(1.0)

output:

humid= 26.00
runtime error: Checksum did not validate. Try again.
temp= 22.00°C
humid= 26.00

Upvotes: 0

Meqdad Dev
Meqdad Dev

Reputation: 141

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)

Upvotes: 3

WinBase
WinBase

Reputation: 31

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.

Upvotes: 0

DavidE
DavidE

Reputation: 41

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

Upvotes: 4

Kotaro Hashimoto
Kotaro Hashimoto

Reputation: 201

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.

Upvotes: 20

Related Questions