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

Calibrate Command not valid for newer ATH20 #17

Closed
DemiVis opened this issue Sep 30, 2023 · 4 comments
Closed

Calibrate Command not valid for newer ATH20 #17

DemiVis opened this issue Sep 30, 2023 · 4 comments

Comments

@DemiVis
Copy link
Contributor

DemiVis commented Sep 30, 2023

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.

@berarduc
Copy link

I got this error too. Then I went to the github repo:

github.com/adafruit/Adafruit_CircuitPython_AHTx0.

---> In commit fe1abce dated Aug 15 (2023), a change was made to the calibrate command. The comment associated with the change was:

"# Newer AHT20's may not succeed, so wrapping in try/except"

When I downloaded this code and used it, the part worked.

@berarduc
Copy link

BTW, new AHT20's from Adafruit have a RED led instead of GREEN led, which adds to the confusion :)

@DemiVis
Copy link
Contributor Author

DemiVis commented Dec 15, 2023

@berarduc I saw that try/except, but it still seemed to be failing for me. Maybe I'm misunderstanding something but I thought regardless it should've just pass if that write doesn't work, I still want my sensor to do the calibration if that's an option from the sensor manufacturer! :)

@DemiVis DemiVis changed the title Calibrate Command not valid for ATH20 Calibrate Command not valid for newer ATH20 Dec 17, 2023
@ladyada
Copy link
Member

ladyada commented Dec 18, 2023

thank you!!! <3

hopefully resolved by merging
#19
mpy and pypi will take a day to update!

@ladyada ladyada closed this as completed Dec 18, 2023
d00mfish added a commit to d00mfish/Mycodo that referenced this issue May 8, 2024
Newer AHT20s do not work, as they use a different calibration command as stated here : adafruit/Adafruit_CircuitPython_AHTx0#17 (comment)

To fix this problem the version should be bumped to the current one where they try the old and new calibration command. So far no other problems occured with this bugfix.
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

3 participants