Skip to content

Pybadge LC compatibility #54

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

Merged
merged 4 commits into from
Dec 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions adafruit_pybadger/pybadge.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,24 @@ def __init__(self):
self._accelerometer = None

if i2c is not None:
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
i2c, address=0x19, int1=int1
)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
_i2c_devices = []

for _ in range(10):
# try lock 10 times to avoid infinite loop in sphinx build
if i2c.try_lock():
_i2c_devices = i2c.scan()
i2c.unlock()
break

# PyBadge LC doesn't have accelerometer
if int(0x18) in _i2c_devices or int(0x19) in _i2c_devices:
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
i2c, address=0x19, int1=int1
)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

# NeoPixels
self._neopixels = neopixel.NeoPixel(
Expand Down