Open rkappel opened 1 year ago
Hi, this could be caused by a poor connection somewhere in your breadboard. Rewiring your entire circuit could solve it.
Hi, change the comparison in the return of is_ready to:
return self._i2c.readfrom(self._address, 1)[0] & 0x18 == 0x18
and it should work. But there are several flaws in this library. According to the datasheet, the waiting time after triggering a measurement (0xAC) must be at least 80ms, not 50ms as here. The initialization sequence of the calibration (0x1B, 0x1C, 0x1E) differs from the reference implementation of the manufacturer ASAIR.
Hi,
I soldered the connections properly and now it works fine. I did not need to change the code in the library.
Many Thanks for your prompt response and the follow-up.
Best Regards, René
Hi,
I get the same error as Rene, but my wiring was okay. For me the solution was to substitute I2C(...)
with SoftI2C(...)
. I found this solution in the MicroPython forum. Therefore my code to run the measurements is:
from machine import Pin, SoftI2C
from utime import sleep
from dht20 import DHT20
i2c0_sda = Pin(4)
i2c0_scl = Pin(5)
i2c0 = SoftI2C( sda=i2c0_sda, scl=i2c0_scl)
sleep(0.2)
dht20 = DHT20(0x38, i2c0)
while True:
measurements = dht20.measurements
print(f"Temperature: {measurements['t']} °C, humidity: {measurements['rh']} %RH")
sleep(1)
I also added theses two additional lines in the dht20.py file:
# https://github.com/flrrth/pico-dht20
from machine import I2C
from utime import sleep_ms
class DHT20:
"""Class for the DHT20 Temperature and Humidity Sensor.
The datasheet can be found at http://www.aosong.com/userfiles/files/media/Data%20Sheet%20DHT20%20%20A1.pdf
"""
def __init__(self, address: int, i2c: I2C):
self._address = address
self._i2c = i2c
sleep_ms(100)
# Added Columns
self._i2c.writeto(0x38, bytearray(b'\x71'))
sleep_ms(200)
Hello,
I tried to use your library to read a DHT20 sensor and did just basically copy/paste everything using Thonny.
When running the sample code I get the error below. A simple LED blink test program works, though.
Many Thanks for your help in advance.
René
Traceback (most recent call last): File "", line 11, in
File "dht20.py", line 18, in init
File "dht20.py", line 28, in is_ready
OSError: [Errno 5] EIO