MojoScale Studio Docs
API Reference

icm42688

ICM-42688 6-axis IMU module.

Studio Docs Sensors & I/O

import icm42688

The icm42688 module reads TDK/InvenSense ICM-42688 compatible accelerometer and gyroscope boards over I2C. It exposes acceleration in g, angular velocity in degrees per second, temperature, data-ready status, and basic power controls.

Quick example

import icm42688

imu = icm42688.ICM42688(sda=21, scl=22, address=0x68)
data = imu.read()
print(data["accel_z_g"], data["gyro_z_dps"])

imu.configure(accel_range=8, gyro_range=500, accel_rate=100, gyro_rate=100)

importicm42688

ICM-42688 6-axis IMU module.

The icm42688 module reads TDK/InvenSense ICM-42688 compatible accelerometer and gyroscope boards over I2C. It exposes acceleration in g, angular velocity in degrees per second, temperature, data-ready status, and basic power controls.

API 26 available

icm42688.ICM42688(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> icm42688_imu

Create and initialize an independent ICM-42688 IMU.

Use one ICM42688 object for each physical IMU. Multiple sensors can share one I2C bus when each board has a unique address.

Parameters
Name Type Pass as Required Description
sda int positional or keyword Yes GPIO pin used for I2C SDA.
scl int positional or keyword Yes GPIO pin used for I2C SCL.
address int positional or keyword No Optional I2C address. Defaults to 0x68. Some boards use 0x69.
frequency int positional or keyword No Optional I2C bus speed in hertz. Defaults to 400000.
port int positional or keyword No Optional ESP-IDF I2C port number. Defaults to 0.
Returns

icm42688_imu icm42688_imu object.

icm42688.ICM42688().configure(accel_range=None, gyro_range=None, accel_rate=None, gyro_rate=None) -> bool

Configure full-scale ranges and output data rates for this IMU.

Parameters
Name Type Pass as Required Description
accel_range int positional or keyword No Optional value. Defaults to None.
gyro_range int positional or keyword No Optional value. Defaults to None.
accel_rate any positional or keyword No Optional value. Defaults to None.
gyro_rate any positional or keyword No Optional value. Defaults to None.

icm42688.ICM42688().read() -> dict

Read acceleration, gyroscope, and temperature from this IMU.

icm42688.ICM42688().accel() -> dict

Read acceleration only.

icm42688.ICM42688().gyro() -> dict

Read angular velocity only.

icm42688.ICM42688().temperature() -> float

Read the on-chip temperature in degrees Celsius.

icm42688.ICM42688().ready() -> bool

Check whether a fresh accelerometer/gyroscope sample is ready.

icm42688.ICM42688().sleep(enabled=None) -> bool

Put this sensor into or out of sleep mode.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional value. Defaults to None.

icm42688.ICM42688().wake() -> bool

Wake the accelerometer and gyroscope in low-noise mode.

icm42688.ICM42688().reset() -> bool

Soft-reset this sensor and restore its configuration.

icm42688.ICM42688().id() -> int

Read this sensor's WHO_AM_I register.

icm42688.ICM42688().info() -> dict

Return I2C settings, chip id, ranges, rates, and scale factors for this IMU.

icm42688.ICM42688().close() -> bool

Release this ICM-42688 handle.

icm42688.ICM42688().Example

imu = icm42688.ICM42688(sda=21, scl=22) print(imu.read())

icm42688.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool

Legacy: initialize the module-level default ICM-42688 sensor.

Prefer ``imu = icm42688.ICM42688(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.

Parameters
Name Type Pass as Required Description
sda int positional or keyword Yes GPIO pin used for I2C SDA.
scl int positional or keyword Yes GPIO pin used for I2C SCL.
address int positional or keyword No Optional I2C address. Defaults to 0x68. Some boards use 0x69.
frequency int positional or keyword No Optional I2C bus speed in hertz. Defaults to 400000.
port int positional or keyword No Optional ESP-IDF I2C port number. Defaults to 0.
Returns

bool True when the sensor responds and the default configuration is applied.

icm42688.configure(accel_range: int = None, gyro_range: int = None, accel_rate: any = None, gyro_rate: any = None) -> bool

Configure full-scale ranges and output data rates.

Parameters
Name Type Pass as Required Description
accel_range int positional or keyword No Optional accelerometer full-scale range in g. Use 2, 4, 8, or 16. Defaults to 16.
gyro_range int positional or keyword No Optional gyroscope range in degrees per second. Use 125, 250, 500, 1000, or 2000. Defaults to 2000.
accel_rate any positional or keyword No Optional accelerometer output data rate in hertz. Common values are 50, 100, 200, 500, or 1000. Defaults to 100.
gyro_rate any positional or keyword No Optional gyroscope output data rate in hertz. Common values are 50, 100, 200, 500, or 1000. Defaults to 100.
Returns

bool True when the configuration registers are updated.

icm42688.read() -> dict

Read acceleration, gyroscope, and temperature.

Returns

dict Dict with ``ok``, raw accelerometer and gyroscope fields, ``accel_x_g``, ``accel_y_g``, ``accel_z_g``, ``gyro_x_dps``, ``gyro_y_dps``, ``gyro_z_dps``, ``temperature_c``, ranges, rates, and I2C address.

icm42688.accel() -> dict

Read acceleration only.

Returns

dict Dict with ``ok``, ``x``, ``y``, ``z``, ``x_g``, ``y_g``, ``z_g``, and ``range_g``.

icm42688.gyro() -> dict

Read angular velocity only.

Returns

dict Dict with ``ok``, ``x``, ``y``, ``z``, ``x_dps``, ``y_dps``, ``z_dps``, and ``range_dps``.

icm42688.temperature() -> float

Read the on-chip temperature sensor.

Returns

float Temperature in degrees Celsius.

icm42688.ready() -> bool

Check whether a fresh accelerometer/gyroscope sample is ready.

Returns

bool True when the data-ready status bit is set.

icm42688.sleep(enabled: bool = None) -> bool

Put the sensor into or out of sleep mode.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional sleep state. True sleeps the sensor, False wakes it. Defaults to True.
Returns

bool True when the power-management register is updated.

icm42688.wake() -> bool

Wake the accelerometer and gyroscope in low-noise mode.

Returns

bool True when the wake command is accepted.

icm42688.reset() -> bool

Soft-reset the sensor and restore the default module configuration.

Returns

bool True when reset and reconfiguration succeed.

icm42688.id() -> int

Read the WHO_AM_I register.

Returns

int Integer device identifier. A normal ICM-42688 returns 0x47.

icm42688.info() -> dict

Return ICM-42688 module state.

Returns

dict Dict with initialization state, I2C settings, chip id, ranges, rates, and scale factors.