Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Calibrate Command not valid for newer ATH20 #17

Closed
@DemiVis

Description

@DemiVis

Relevant line:
https://github.com/adafruit/Adafruit_CircuitPython_AHTx0/blame/e7b71a57a769c57ce4efb95491dffc32e5940132/adafruit_ahtx0.py#L48

While trying to initialize a new AHT20 device ( shop link ) using a QT Py ESP32-S2 WiFi Dev Board with STEMMA QT ( shop link ) connected using a breadboard and wires (not STEMMA) between labelled QT Py SCL/SDA and AHT20 SCL/SDA, labeled GND pins connected, and AHT20 VIN tied to QT Py 3V I was getting an error using the above code library on intial call with the following traceback:

Traceback (most recent call last):
  File "code.py", line 46, in <module>
  File "adafruit_ahtx0.py", line 96, in __init__
  File "adafruit_ahtx0.py", line 114, in calibrate
OSError: [Errno 19] No such device

Upon further investigation using an analog discovery, I found the AHT20 was NACK-ing the first word of calibrate command (defined in this library as AHTX0_CMD_CALIBRATE).
Initial soft reboot:
Initial soft reboot
followed by NACK of Calibrate command first word:
NACK of Calibrate command

I tried various other things, including manually emulating the library step by step to find the issue, and continually got NACK on that first word. Digging into the AHT20 documentation, I found this document that shows a different calibrate word in section 5.4

  1. Wait 40ms after power-on. Before reading the temperature and humidity values, first check whether the calibration enable bit Bit [3] of the status word is 1 (you can get a byte of status word by sending 0x71). If not 1, need to send 0xbe command (for initialization), this command parameter has two bytes, the first byte is 0x08, the second byte is 0x00, and then wait for 10ms

I modified my manual recreation of this library to use 0xBE as the first word instead and it worked. So I downloaded this file directly, modified only line 48 (above) to read

AHTX0_CMD_CALIBRATE: int = const(0xBE)  # Calibration command

and the library works exactly as intended. Further calls to the returned object as shown in the guide work as expected for as long as I tested it.

I didn't want to submit a pull request as I'm not sure this update would be valid for all uses of the library, but wanted to report the issue I saw and subsequent solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions