File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,21 @@ def play_wav(wav):
74
74
i2c = board .I2C () # uses board.SCL and board.SDA
75
75
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
76
76
if IS_HALLOWING_M4 :
77
- import adafruit_msa301
78
- ACCEL = adafruit_msa301 .MSA301 (i2c )
77
+ # i2c scan to determine which accelo
78
+ while not i2c .try_lock ():
79
+ pass
80
+ ADDR = i2c .scan ()
81
+ i2c .unlock ()
82
+ if 0x26 in ADDR :
83
+ # MSA301
84
+ from adafruit_msa3xx import MSA301
85
+ ACCEL = MSA301 (i2c )
86
+ elif 0x62 in ADDR :
87
+ # MSA311
88
+ from adafruit_msa3xx import MSA311
89
+ ACCEL = MSA311 (i2c )
90
+ else :
91
+ raise RuntimeError ("Accelerometer not found." )
79
92
else :
80
93
import adafruit_lis3dh
81
94
try :
Original file line number Diff line number Diff line change @@ -57,8 +57,21 @@ def load_wav(name):
57
57
i2c = board .I2C () # uses board.SCL and board.SDA
58
58
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
59
59
if IS_HALLOWING_M4 :
60
- import adafruit_msa301
61
- ACCEL = adafruit_msa301 .MSA301 (i2c )
60
+ # i2c scan to determine which accelo
61
+ while not i2c .try_lock ():
62
+ pass
63
+ ADDR = i2c .scan ()
64
+ i2c .unlock ()
65
+ if 0x26 in ADDR :
66
+ # MSA301
67
+ from adafruit_msa3xx import MSA301
68
+ ACCEL = MSA301 (i2c )
69
+ elif 0x62 in ADDR :
70
+ # MSA311
71
+ from adafruit_msa3xx import MSA311
72
+ ACCEL = MSA311 (i2c )
73
+ else :
74
+ raise RuntimeError ("Accelerometer not found." )
62
75
else :
63
76
import adafruit_lis3dh
64
77
try :
You can’t perform that action at this time.
0 commit comments