| 1 |
""" |
| 2 |
IMU module for Arduino Nano BLE 33 SENSE (REV1 and REV2). |
| 3 |
|
| 4 |
Example usage: |
| 5 |
|
| 6 |
import time |
| 7 |
import imu |
| 8 |
from machine import Pin, I2C |
| 9 |
|
| 10 |
bus = I2C(1, scl=Pin(15), sda=Pin(14)) |
| 11 |
imu = imu.IMU(bus) |
| 12 |
|
| 13 |
while (True): |
| 14 |
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel())) |
| 15 |
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro())) |
| 16 |
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet())) |
| 17 |
print("") |
| 18 |
time.sleep_ms(100) |
| 19 |
""" |
| 20 |
|
| 21 |
import time |
| 22 |
|
| 23 |
|
| 24 |
class IMU: |
| 25 |
def __init__(self, bus): |
| 26 |
"""Initializes Gyro, Accelerometer and Magnetometer using default values.""" |
| 27 |
if 0x68 in bus.scan(): |
| 28 |
from bmm150 import BMM150 |
| 29 |
from bmi270 import BMI270 |
| 30 |
|
| 31 |
magnet = BMM150(bus) |
| 32 |
self.imu = BMI270(bus, bmm_magnet=magnet) |
| 33 |
else: |
| 34 |
from lsm9ds1 import LSM9DS1 |
| 35 |
|
| 36 |
self.imu = LSM9DS1(bus) |
| 37 |
|
| 38 |
def gyro(self): |
| 39 |
return self.imu.gyro() |
| 40 |
|
| 41 |
def accel(self): |
| 42 |
return self.imu.accel() |
| 43 |
|
| 44 |
def magnet(self): |
| 45 |
return self.imu.magnet() |