Skip to content

Commit 60ef01a

Browse files
committed
add init retries
1 parent 06243aa commit 60ef01a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

adafruit_am2320.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ class AM2320:
8585
8686
"""
8787
def __init__(self, i2c_bus, address=AM2320_DEFAULT_ADDR):
88-
self._i2c = I2CDevice(i2c_bus, address)
88+
for _ in range(3):
89+
# retry since we have to wake up the devices
90+
try:
91+
self._i2c = I2CDevice(i2c_bus, address)
92+
return
93+
except ValueError:
94+
pass
95+
time.sleep(0.25)
96+
raise ValueError("AM2320 not found")
8997

9098
def _read_register(self, register, length):
9199
with self._i2c as i2c:

0 commit comments

Comments
 (0)