Skip to content

Commit f8f1915

Browse files
authored
Merge pull request #31 from Sigafoos/issue30
Updating examples to default to hardware I2C or CPX
2 parents dc7da90 + 97ad17f commit f8f1915

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

examples/lis3dh_simpletest.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
# Uncomment _one_ of the hardware setups below depending on your wiring:
1111

12-
# Hardware I2C setup:
12+
# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available;
13+
# otherwise check I2C pins.
1314
import busio
14-
i2c = busio.I2C(board.SCL, board.SDA)
15-
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
16-
17-
# Hardware I2C setup on CircuitPlayground Express:
18-
# import busio
19-
# i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
20-
# lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
15+
if hasattr(board, 'ACCELEROMETER_SCL'):
16+
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
17+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
18+
else:
19+
i2c = busio.I2C(board.SCL, board.SDA)
20+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
2121

2222
# Software I2C setup:
2323
#import bitbangio

examples/tap.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
# Uncomment _one_ of the hardware setups below depending on your wiring:
1010

11-
# Hardware I2C setup:
11+
# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available;
12+
# otherwise check I2C pins.
1213
import busio
13-
i2c = busio.I2C(board.SCL, board.SDA)
14-
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
15-
16-
# Hardware I2C setup on CircuitPlayground Express:
17-
# import busio
18-
# i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
19-
# lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
14+
if hasattr(board, 'ACCELEROMETER_SCL'):
15+
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
16+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
17+
else:
18+
i2c = busio.I2C(board.SCL, board.SDA)
19+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
2020

2121
# Software I2C setup:
2222
#import bitbangio

0 commit comments

Comments
 (0)