Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: [Errno 5] EIO #3

Open
rkappel opened this issue Dec 1, 2022 · 4 comments
Open

OSError: [Errno 5] EIO #3

rkappel opened this issue Dec 1, 2022 · 4 comments

Comments

@rkappel
Copy link

rkappel commented Dec 1, 2022

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

@flrrth
Copy link
Owner

flrrth commented Dec 4, 2022

Hi, this could be caused by a poor connection somewhere in your breadboard. Rewiring your entire circuit could solve it.

@Pokinatcha
Copy link

@property
def is_ready(self) -> bool:
"""Check if the DHT20 is ready."""
self._i2c.writeto(self._address, bytearray(b'\x71'))
return self._i2c.readfrom(self._address, 1)[0] == 0x18

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.

@rkappel
Copy link
Author

rkappel commented Dec 26, 2022

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é

@fxschmidt
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants