Skip to content

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.

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!

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
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.

4 participants