adafruit / Adafruit_CircuitPython_DHT

CircuitPython support for DHT11 and DHT22 type temperature/humidity devices
MIT License
179 stars 62 forks source link

DHT22 not working on Raspberry Pi Pico using CircuitPython #61

Closed gregwa1953 closed 3 years ago

gregwa1953 commented 3 years ago

Trying to use the DHT22 program on my Raspberry Pi Pico. I changed the pin to GP1 and let the program autoload into Mu.

I got the following error message:

Traceback (most recent call last): File "code.py", line 10, in File "adafruit_dht.py", line 274, in init File "adafruit_dht.py", line 52, in init Exception: Bitbanging is not supported when using CircuitPython.

Any help would be appreciated. Thank you in advance! Greg

jerryneedell commented 3 years ago

The DHT library requires the pulseio module. Unfortunately, the pulseio module has not yet been ported to the Pico. The Bitbang reference is generated because on some platforms (Raspberry Pi using the "Blinka" compatibility library) the library will use "bit-banging" when pulseio is not available - this option is not available to microcontrollers runing CircuitPython.

Until pulseio is made available, the DHT sensors will not be useable on the Pico.

edited to add: you can follow the progress here: https://github.com/adafruit/circuitpython/issues/4111

jerryneedell commented 3 years ago

Closing since this is not an issue with the DHT library.

gregwa1953 commented 3 years ago

Thank you very much!

jerryneedell commented 3 years ago

re-open until this is resolved

jerryneedell commented 3 years ago

Now that PulseIO had ben added to CP for the RPI2040 I tried the dht_simpletest with a DHT22 on pin GP22

Adafruit CircuitPython 6.2.0-beta.4-121-g550eab2dd on 2021-03-13; Raspberry Pi Pico with rp2040
>>> 
>>> import dht_simpletest
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 23.9% 
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 23.8% 
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 24.1% 
Temp: 71.1 F / 21.7 C    Humidity: 24.1% 
Temp: 71.1 F / 21.7 C    Humidity: 24.3% 
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 24.4% 

It works --- not great, but the DHT22 is finicky...

here is a second run

Adafruit CircuitPython 6.2.0-beta.4-121-g550eab2dd on 2021-03-13; Raspberry Pi Pico with rp2040
>>> 
>>> import dht_simpletest
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 23.8% 
Temp: 71.1 F / 21.7 C    Humidity: 23.7% 
Temp: 71.1 F / 21.7 C    Humidity: 24.1% 
Temp: 71.1 F / 21.7 C    Humidity: 24.5% 
Checksum did not validate. Try again.
Temp: 71.1 F / 21.7 C    Humidity: 24.2% 
Temp: 71.1 F / 21.7 C    Humidity: 24.0% 
Checksum did not validate. Try again.
Checksum did not validate. Try again.
Temp: 71.2 F / 21.8 C    Humidity: 24.6% 
gregwa1953 commented 3 years ago

I didn't know that CircuitPython had been updated to include PulseIO. DHT22 is now working under MicroPython for the Pico. You can see the thread at https://www.raspberrypi.org/forums/viewtopic.php?f=146&t=303606 . The code provided (at github) also supports DHT11.

I found no major issues like you are seeing with the checksum errors. I ran it continuously for about 36 hours without a hitch. That having been said, I remember from earlier work with the DHT22 and DHT11, timing is fairly critical. In my test code, I think I was only pulling a temp about every 5 seconds, which for me is pretty much as fast as I can imagine anything would need, but your mileage may vary ;o)

I'll try to carve out some time this weekend to play with the new version of CircuitPython and see if I can get some reasonable readings. Greg

On Sat, Mar 13, 2021 at 5:20 AM jerryneedell @.***> wrote:

Now that PulseIO had ben added to CP I tried the dht_simpletest with a DHT22 on pin GP22

Adafruit CircuitPython 6.2.0-beta.4-121-g550eab2dd on 2021-03-13; Raspberry Pi Pico with rp2040

import dht_simpletest Checksum did not validate. Try again. Temp: 71.1 F / 21.7 C Humidity: 23.9% Checksum did not validate. Try again. Checksum did not validate. Try again. Checksum did not validate. Try again. Checksum did not validate. Try again. Temp: 71.1 F / 21.7 C Humidity: 23.8% Checksum did not validate. Try again. Checksum did not validate. Try again. Checksum did not validate. Try again. Temp: 71.1 F / 21.7 C Humidity: 24.1% Temp: 71.1 F / 21.7 C Humidity: 24.1% Temp: 71.1 F / 21.7 C Humidity: 24.3% Checksum did not validate. Try again. Temp: 71.1 F / 21.7 C Humidity: 24.4%

It works --- not great, but the DHT22 is finicky...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_DHT/issues/61#issuecomment-798184422, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEKEQMI7WXP2YCFWHQJ76NTTDM373ANCNFSM4W6NF2KA .

-- TEA. Earl Gray. HOT. Nuff Said! Greg Walters

jerryneedell commented 3 years ago

The PulseIO PR was merged yesterday and it is not in the "released" version ...yet. It is available from the "S3" latest builds.

gregwa1953 commented 3 years ago

Thanks for the information.

Trying to deal with MicroPython, CircuitPython, other Microcontrollers in a learning mode with everything else that life throws at me (mostly my fault) keeps me hopping from one project to another without time to keep up to date on everything I should.

Again, thank you for the information.

Greg

On Sat, Mar 13, 2021 at 5:32 AM jerryneedell @.***> wrote:

The PulseIO PR was merged yesterday and it is not in the "released" version ...yet. It is available from the "S3" latest builds.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_DHT/issues/61#issuecomment-798201875, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEKEQMOAV5P44I3NTFHC6UTTDM5KJANCNFSM4W6NF2KA .

-- TEA. Earl Gray. HOT. Nuff Said! Greg Walters

mperino commented 3 years ago

This works well enough. Wired up to pin 10 (GP7) on Circutpython 6 from adafruit:


import time
import board
import adafruit_dht

print("library loaded")
sleep_timer = 2.0
retries = 4
samples = 3
dhtDevice = adafruit_dht.DHT22(board.GP7)

def sample_and_avg_DHT(sleep_timer, retries, samples):
    valid = 0
    invalid = 0
    temperature_c =0
    humidity = 0
    while valid < samples:
        try:
            temperature_c = temperature_c + dhtDevice.temperature
            humidity = humidity + dhtDevice.humidity
            valid += 1

        except:
            invalid += 1
            if invalid > retries:
                print("Retries exceeded Aborting")
                print("Last Error{}".format(dhtDevice.exit()))
        time.sleep(sleep_timer)
    return (round(temperature_c/valid, 1), round(humidity/valid,1))

print("Temperature:{}C, Humidity:{}%".format(*sample_and_avg_DHT(sleep_timer, retries, samples)))
gregwa1953 commented 3 years ago

Thank you for the update!