MicroPython driver for the STMicroelectronics ISM330DL 6-axis IMU.
The ISM330DL integrates:
- a 3-axis accelerometer
- a 3-axis gyroscope
This driver provides a simple API to configure the sensor and read motion data using I²C.
- I²C communication
- device identification (
WHO_AM_I) - accelerometer configuration
- gyroscope configuration
- raw sensor readings
- converted physical units
- board orientation reading
- accelerometer bias offset correction
- board rotation reading
- temperature reading
- data-ready status helpers
- power-down mode
| Sensor | Range | Unit |
|---|---|---|
| Accelerometer | ±2g / ±4g / ±8g / ±16g | g |
| Gyroscope | ±125 / ±250 / ±500 / ±1000 / ±2000 | degrees/s |
| Temperature | internal sensor | °C |
The sensor can use two I²C addresses depending on the SA0 pin:
| SA0 | Address |
|---|---|
| 0 | 0x6A |
| 1 | 0x6B |
The STeaMi board uses 0x6B (default).
from machine import I2C
from ism330dl import ISM330DL
i2c = I2C(1)
imu = ISM330DL(i2c)
ax, ay, az = imu.acceleration_g()
gx, gy, gz = imu.gyroscope_dps()
temp = imu.temperature()
print("Accel:", ax, ay, az)
print("Gyro :", gx, gy, gz)
print("Temp :", temp)imu = ISM330DL(i2c)imu.acceleration_raw()Returns:
(x, y, z)
16-bit raw values.
imu.acceleration_g()Example:
(0.01, -0.02, 0.99)
imu.acceleration_ms2()imu.orientation()The driver supports accelerometer bias correction using per-axis offsets.
imu.set_accel_offset(ox=0.01, oy=-0.02, oz=0.03)imu.get_accel_offset()
# -> (0.01, -0.02, 0.03)On the STeaMi board, accelerometer calibration can be stored using
steami_config and automatically applied at startup:
from steami_config import SteamiConfig
from daplink_bridge import DaplinkBridge
config = SteamiConfig(DaplinkBridge(i2c))
config.load()
imu = ISM330DL(i2c)
config.apply_accelerometer_calibration(imu)imu.gyroscope_raw()imu.gyroscope_dps()Example:
(0.5, -0.3, 1.2)
imu.gyroscope_rads()imu.motion()imu.temperature()Example:
26.3
imu.configure_accel(odr, scale)Example:
from ism330dl.const import ACCEL_ODR_104HZ, ACCEL_FS_4G
imu.configure_accel(ACCEL_ODR_104HZ, ACCEL_FS_4G)imu.configure_gyro(odr, scale)Example:
from ism330dl.const import GYRO_ODR_104HZ, GYRO_FS_500DPS
imu.configure_gyro(GYRO_ODR_104HZ, GYRO_FS_500DPS)imu.status()Returns:
{
"temp_ready": True,
"gyro_ready": True,
"accel_ready": True
}
imu.power_off()Stops accelerometer and gyroscope.
The repository provides several example scripts:
| Example | Description |
|---|---|
basic_read.py |
Simple sensor readout |
static_orientation.py |
Detect device orientation using the accelerometer |
motion_orientation.py |
Detect rotation using the gyroscope |
spirit_level.py |
Interactive digital bubble level using SSD1327 OLED |