adafruit / Adafruit_CircuitPython_AHTx0

CircuitPython driver for the Adafruit AHT10 Humidity and Temperature Sensor
MIT License
15 stars 12 forks source link

Recent AHT20 shipment Errno 19 (ENODEV) retrieving device status fails in ahtx0_simpletest.py #18

Closed boltonja closed 11 months ago

boltonja commented 11 months ago

Ordered some new AHT20 breakout boards on 26 Nov 2023. The first two of these devices (others remain sealed) fail in status with CircuitPython 8.2.9 and Adafruit CircuitPython Bundle 20231205:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
  File "code.py", line 17, in <module>
  File "adafruit_ahtx0.py", line 96, in __init__
  File "adafruit_ahtx0.py", line 120, in calibrate
  File "adafruit_ahtx0.py", line 129, in status
OSError: [Errno 19] No such device

Code done running.

Expected output is:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:

Temperature: 26.5 C
Humidity: 32.9 %

Temperature: 26.4 C
Humidity: 33.0 %

Temperature: 26.2 C
Humidity: 33.1 %

This is the line 129 in the library that is failing:

def status(self) -> int:
        """The status byte initially returned from the sensor, see datasheet for details"""
        with self.i2c_device as i2c:
            i2c.readinto(self._buf, start=0, end=1)  ### line 129
        # print("status: "+hex(self._buf[0]))
        return self._buf[0]

There are several revisions of the data sheet floating around on the internet. The one linked on the Adafruit Product site says the minimum wait time after power on is 100ms. Other documentation that I have found e.g., from Sparkfun indicate 20ms and a sample C program that I found on the manufacturer's product page waits 500ms after power-on.

I increased wait time to 110ms in a copy of adafruit_ahtx0.py, without any improvement in status reading. I also tried commenting out the self.reset() invocation in init() because the literature seems to indicate it might be unnecessary. Here is the snippet with my change:

    def __init__(
        self, i2c_bus: busio.I2C, address: int = AHTX0_I2CADDR_DEFAULT
    ) -> None:
        time.sleep(0.110)  # 20ms delay to wake up
        self.i2c_device = I2CDevice(i2c_bus, address)
        self._buf = bytearray(6)
#        self.reset()
        if not self.calibrate():
            raise RuntimeError("Could not calibrate")
        self._temp = None
        self._humidity = None

    def reset(self) -> None:
        """Perform a soft-reset of the AHT"""
        self._buf[0] = AHTX0_CMD_SOFTRESET
        with self.i2c_device as i2c:
            i2c.write(self._buf, start=0, end=1)
        time.sleep(0.110)  # 20ms delay to wake up

Let me know how I can help? More context in a forum thread here

boltonja commented 11 months ago

I'm not sure what I'm doing wrong with the code formatting tool, but if anything is unclear please reach out.

DemiVis commented 11 months ago

I believe that this issue is a misdirecting error message bubbling up from the depths. I ran into it too (see #17 )

If you'd like, feel free to try out the modified version I made (#19) and let us know if that works to support the pull request (or not so we can fix it!)

mikeysklar commented 11 months ago

@DemiVis thank you for mentioning PR #19. I just tested and it worked smoothly for me. I was also getting the No such device error with the current release AHTx0 1.0.20 CircuitPython library.

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
  File "code.py", line 15, in <module>
  File "adafruit_ahtx0.py", line 96, in __init__
  File "adafruit_ahtx0.py", line 120, in calibrate
  File "adafruit_ahtx0.py", line 129, in status
OSError: [Errno 19] No such device

After applying PR#19 update:

Adafruit CircuitPython 8.2.9 on 2023-12-06; Adafruit QT Py ESP32-S3 no psram with ESP32S3
>>>
>>>
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:

Temperature: 20.1 C
Humidity: 45.0 %
ladyada commented 11 months ago

hopefully resolved by merging https://github.com/adafruit/Adafruit_CircuitPython_AHTx0/pull/19 mpy and pypi will take a day to update!

boltonja commented 11 months ago

19 works for me, too!