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

Calibration patch for newer AHT20's #16

Merged
merged 4 commits into from
Sep 19, 2023
Merged

Calibration patch for newer AHT20's #16

merged 4 commits into from
Sep 19, 2023

Conversation

BlitzCityDIY
Copy link
Contributor

Updating calibration function so that it isn't required to pass for newer AHT20's. This same change was made for the Arduino library

Updating calibration function so that it isn't required to pass for newer AHT20's. This same change was made for the [Arduino library](adafruit/Adafruit_AHTX0#13)
@BlitzCityDIY
Copy link
Contributor Author

Tested with the library example (although with an older AHT20) and ran as expected. Also added print(sensor.calibrate()) before the loop and it was returning True as expected.

self._buf[0] = AHTX0_CMD_CALIBRATE
self._buf[1] = 0x08
self._buf[2] = 0x00
with self.i2c_device as i2c:
i2c.write(self._buf, start=0, end=3)
while self.status & AHTX0_STATUS_BUSY:
time.sleep(0.01)
if not self.status & AHTX0_STATUS_CALIBRATED:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this part in!

@@ -106,16 +106,14 @@ def reset(self) -> None:
time.sleep(0.02) # 20ms delay to wake up

def calibrate(self) -> bool:
"""Ask the sensor to self-calibrate. Returns True on success, False otherwise"""
"""Ask the sensor to self-calibrate. May not 'succeed' on newer AHT20s."""
self._buf[0] = AHTX0_CMD_CALIBRATE
self._buf[1] = 0x08
self._buf[2] = 0x00
with self.i2c_device as i2c:
i2c.write(self._buf, start=0, end=3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may fail, so do a try/except pass here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap only the call that can fail, please!

i2c.write(self._buf, start=0, end=3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ladyada ohh okay, will fix. one question though- in __init__ if calibration returns False then it raises a RuntimeError, should that be changed too to not raise an error? or would the sensor read the SENSOR_CALIBRATED bit with the try/except and not return False?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

image

@github-actions
Copy link

👋 Thanks for this pull request! Unfortunately, it looks like the automated continuous integration (CI) test(s) failed. These can be tricky to fix so we've written a guide on how to fix them locally. It has pages about running pre-commit locally and another about building the docs locally with sphinx. Thanks for contributing to CircuitPython! If you have more questions, feel free to join the Adafruit Discord and post in #circuitpython-dev.

@caternuson
Copy link
Contributor

@ladyada would you be able to test this with a "new" AHT with the funky behavior?

otherwise, LGTM, simple catch all exception pass

@caternuson caternuson merged commit e7b71a5 into main Sep 19, 2023
2 checks passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 20, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_AHTx0 to 1.0.19 from 1.0.18:
  > Merge pull request adafruit/Adafruit_CircuitPython_AHTx0#16 from adafruit/aht20_calibration
  > "fix rtd theme "

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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

Successfully merging this pull request may close these issues.

None yet

3 participants