Skip to content

Commit

Permalink
Merge pull request #16 from adafruit/aht20_calibration
Browse files Browse the repository at this point in the history
Calibration patch for newer AHT20's
  • Loading branch information
caternuson authored Sep 19, 2023
2 parents d62022d + fe1abce commit e7b71a5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion adafruit_ahtx0.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ def reset(self) -> None:

def calibrate(self) -> bool:
"""Ask the sensor to self-calibrate. Returns True on success, False otherwise"""
# Newer AHT20's may not succeed, so wrapping in try/except
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)
try:
i2c.write(self._buf, start=0, end=3)
except Exception: # pylint: disable=broad-except
pass
while self.status & AHTX0_STATUS_BUSY:
time.sleep(0.01)
if not self.status & AHTX0_STATUS_CALIBRATED:
Expand Down

0 comments on commit e7b71a5

Please sign in to comment.