Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

dht 11 not working pi 4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

dht 11 not working pi 4

by osoblanco84 on Thu Aug 13, 2020 1:28 am

i have tried everything on the forums and nothing is working and wondering if it can even work. keep getting error
Traceback (most recent call last):
File "/home/pi/humidity.py", line 7, 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)

Ive done ever update possible

osoblanco84
 
Posts: 5
Joined: Thu Aug 13, 2020 12:50 am

Re: dht 11 not working pi 4

by dastels on Thu Aug 13, 2020 9:56 am

For some reason it thinks it's running on a Beaglebone Black. Which is odd, based on reading through the code.

Please post the contents of /usr/local/lib/python3.7/dist-packages/Adafruit_DHT/platform_detect.py

Also the output from
Code: Select all | TOGGLE FULL SIZE
cat /proc/cpuinfo


Dave

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: dht 11 not working pi 4

by osoblanco84 on Thu Aug 13, 2020 1:18 pm

Sorry if i don't post this right

Code: Select all | TOGGLE FULL SIZE
import platform
import re

# Platform identification constants.
UNKNOWN          = 0
RASPBERRY_PI     = 1
BEAGLEBONE_BLACK = 2


def platform_detect():
    """Detect if running on the Raspberry Pi or Beaglebone Black and return the
    platform type.  Will return RASPBERRY_PI, BEAGLEBONE_BLACK, or UNKNOWN."""
    # Handle Raspberry Pi
    pi = pi_version()
    if pi is not None:
        return RASPBERRY_PI

    # Handle Beaglebone Black
    # TODO: Check the Beaglebone Black /proc/cpuinfo value instead of reading
    # the platform.
    plat = platform.platform()
    if plat.lower().find('armv7l-with-debian') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-ubuntu') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-glibc2.4') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-arch') > -1:
        return BEAGLEBONE_BLACK

    # Couldn't figure out the platform, just return unknown.
    return UNKNOWN


def pi_revision():
    """Detect the revision number of a Raspberry Pi, useful for changing
    functionality like default I2C bus based on revision."""
    # Revision list available at: http://elinux.org/RPi_HardwareHistory#Board_Revision_History
    with open('/proc/cpuinfo', 'r') as infile:
        for line in infile:
            # Match a line of the form "Revision : 0002" while ignoring extra
            # info in front of the revsion (like 1000 when the Pi was over-volted).
            match = re.match('Revision\s+:\s+.*(\w{4})$', line, flags=re.IGNORECASE)
            if match and match.group(1) in ['0000', '0002', '0003']:
                # Return revision 1 if revision ends with 0000, 0002 or 0003.
                return 1
            elif match:
                # Assume revision 2 if revision ends with any other 4 chars.
                return 2
        # Couldn't find the revision, throw an exception.
        raise RuntimeError('Could not determine Raspberry Pi revision.')


def pi_version():
    """Detect the version of the Raspberry Pi.  Returns either 1, 2, 3 or
    None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
    Raspberry Pi 2 (model B+), Raspberry Pi 3,Raspberry Pi 3 (model B+) or not a Raspberry Pi.
    """
    # Check /proc/cpuinfo for the Hardware field value.
    # 2708 is pi 1
    # 2709 is pi 2
    # 2835 is pi 3
    # 2837 is pi 3b+
    # Anything else is not a pi.
    with open('/proc/cpuinfo', 'r') as infile:
        cpuinfo = infile.read()
    # Match a line like 'Hardware   : BCM2709'
    match = re.search('^Hardware\s+:\s+(\w+)$', cpuinfo,
                      flags=re.MULTILINE | re.IGNORECASE)
    if not match:
        # Couldn't find the hardware, assume it isn't a pi.
        return None
    if match.group(1) == 'BCM2708':
        # Pi 1
        return 1
    elif match.group(1) == 'BCM2709':
        # Pi 2
        return 2
    elif match.group(1) == 'BCM2835':
        # Pi 3
        return 3
    elif match.group(1) == 'BCM2837':
        # Pi 3b+
        return 3
    else:
        # Something else, not a pi.
        return None


from terminal

Code: Select all | TOGGLE FULL SIZE
processor   : 0
model name   : ARMv7 Processor rev 3 (v7l)
BogoMIPS   : 342.00
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 1
model name   : ARMv7 Processor rev 3 (v7l)
BogoMIPS   : 342.00
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 2
model name   : ARMv7 Processor rev 3 (v7l)
BogoMIPS   : 342.00
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 3
model name   : ARMv7 Processor rev 3 (v7l)
BogoMIPS   : 342.00
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

Hardware   : BCM2711
Revision   : c03112
Serial      : 100000005e2ae97c
Model      : Raspberry Pi 4 Model B Rev 1.2

osoblanco84
 
Posts: 5
Joined: Thu Aug 13, 2020 12:50 am

Re: dht 11 not working pi 4

by dastels on Thu Aug 13, 2020 2:10 pm

Thanks. That shows the problem.

Interesting... your Pi4 Model B is Rev 1.2 and has a BCM2711. My Rev 1.1 identifies as having a BCM2835.

The platform detect code isn't accounting for this (assumedly) recent change. I'll raise this as something to be fixed. But for now, you can edit /usr/local/lib/python3.7/dist-packages/Adafruit_DHT/platform_detect.py to fix it. In the pi_version function at the end of the file, make the following addition:

Code: Select all | TOGGLE FULL SIZE
    elif match.group(1) == 'BCM2835':
        # Pi 3 or Pi 4
        return 3
    ### start of addition
    elif match.group(1) == 'BCM2711':
        # Pi 4
        return 3
    ### end of addition
    elif match.group(1) == 'BCM2837':
        # Pi 3b+
        return 3


That should do it. Let me know if it does and I'll do a PR for the fix.

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: dht 11 not working pi 4

by osoblanco84 on Thu Aug 13, 2020 2:29 pm

I've tried editing the file but i keep getting an error that it looks like this file isn't writable.

osoblanco84
 
Posts: 5
Joined: Thu Aug 13, 2020 12:50 am

Re: dht 11 not working pi 4

by osoblanco84 on Thu Aug 13, 2020 2:54 pm

Sorry new to Linux and pi's forgot sudo nano. got it done fully working now thanks so much.

osoblanco84
 
Posts: 5
Joined: Thu Aug 13, 2020 12:50 am

Re: dht 11 not working pi 4

by taveresc on Fri Oct 09, 2020 11:10 am

Thanks for the fix. Helped me. Strange, that the Rasp 4 is missing. I updated the Adafruit_DHT package just a few days ago. adafruit should consider updating it.

taveresc
 
Posts: 1
Joined: Fri Oct 09, 2020 11:08 am

Please be positive and constructive with your questions and comments.