lsm9ds1 — LSM9DS1 9-axis IMU
Driver for the ST LSM9DS1 iNEMO inertial module over I2C. The LSM9DS1
combines a 3-axis accelerometer, 3-axis gyroscope and 3-axis magnetometer
in a single package; the accelerometer and gyroscope share an I2C address
while the magnetometer responds on a second address. This driver also
enables the on-chip 16-deep gyro/accel FIFO so that the most recent
samples can be drained efficiently through iter_accel_gyro().
Example:
import time
from machine import Pin, I2C
from lsm9ds1 import LSM9DS1
imu = LSM9DS1(I2C(1, scl=Pin(15), sda=Pin(14)))
while True:
print("Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}".format(*imu.accel()))
print("Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}".format(*imu.magnet()))
print("Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}".format(*imu.gyro()))
time.sleep_ms(100)
Classes
- class lsm9ds1.LSM9DS1(bus: machine.I2C, address_imu: int = 0x6B, address_magnet: int = 0x1E, gyro_odr: float = 952, gyro_scale: int = 245, accel_odr: float = 952, accel_scale: int = 4, magnet_odr: int = 80, magnet_scale: int = 4)
Construct an
LSM9DS1instance, verify the WHO_AM_I registers of both sub-devices, configure all three sensors and enable the accel/gyro FIFO in continuous mode.busA configured
machine.I2Cbus the sensor is attached to.address_imu7-bit I2C address of the accelerometer/gyroscope sub-device. Defaults to
0x6B.address_magnet7-bit I2C address of the magnetometer sub-device. Defaults to
0x1E.gyro_odrGyroscope output data rate in Hz. Must be one of
0(off),14.9,59.5,119,238,476or952.gyro_scaleGyroscope full-scale range in degrees-per-second. Must be one of
245,500or2000.accel_odrAccelerometer output data rate in Hz. Same set of values as
gyro_odr.accel_scaleAccelerometer full-scale range in g. Must be one of
2,4,8or16.magnet_odrMagnetometer output data rate in Hz. Must be one of
0.625,1.25,2.5,5,10,20,40or80.magnet_scaleMagnetometer full-scale range in gauss. Must be one of
4,8,12or16.
- calibrate_magnet(offset: tuple[float, float, float]) None
Write a hard-iron offset vector into the magnetometer’s
OFFSET_REG_*_Mregisters. The offset is given in the same units asmagnet()returns (gauss); each component is converted to raw LSBs using the configured magnetometer scale before being written.
- gyro_id() bytes
Return the single-byte
WHO_AM_Iregister value of the accelerometer/gyroscope sub-device.