Skip to content

Commit 8ab1e6c

Browse files
committed
fix microbit.py
1 parent e613dcb commit 8ab1e6c

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

10.microbit/microbit.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737
temperature = temperature.Temperature(__adc).temperature
3838

3939
try:
40-
import mpu9250
41-
__sensor = mpu9250.MPU9250(machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=200000))
42-
import compass
43-
compass = compass.Compass(__sensor)
40+
from mpu9250 import MPU9250
41+
from mpu6500 import MPU6500
42+
__i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=200000)
43+
__dev = __i2c.scan()
44+
# print("dev ", __dev)
45+
if 104 in __dev:
46+
print("1.4 version")
47+
__sensor = MPU9250(__i2c, MPU6500(__i2c, 0x68))
48+
if 105 in __dev:
49+
print("1.2 version No compass")
50+
__sensor = MPU9250(__i2c, MPU6500(__i2c, 0x69))
4451
import accelerometer
4552
accelerometer = accelerometer.Direction(__sensor)
53+
import compass
54+
compass = compass.Compass(__sensor)
4655
except Exception as e:
47-
print("MPU9250 ERROR")
56+
print("MPU9250 Error", e)

0 commit comments

Comments
 (0)