Skip to content

Commit 8f5fa08

Browse files
committed
check for accelerometer before initialising
1 parent 75785b6 commit 8f5fa08

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

adafruit_pybadger/pybadge.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ def __init__(self):
6464
self._accelerometer = None
6565

6666
if i2c is not None:
67-
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
68-
try:
69-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
70-
i2c, address=0x19, int1=int1
71-
)
72-
except ValueError:
73-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
67+
while not i2c.try_lock():
68+
pass
69+
_i2c_devices = i2c.scan()
70+
i2c.unlock()
71+
if (int(0x18) in _i2c_devices): # PyBadge LC doesn't have accelerometer
72+
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
73+
try:
74+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
75+
i2c, address=0x19, int1=int1
76+
)
77+
except ValueError:
78+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
7479

7580
# NeoPixels
7681
self._neopixels = neopixel.NeoPixel(

0 commit comments

Comments
 (0)