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.
icm42688.ICM42688(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> icm42688_imu
icm42688.ICM42688(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> icm42688_imuCreate 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.
| 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. |
icm42688_imu icm42688_imu object.
icm42688.ICM42688().configure(accel_range=None, gyro_range=None, accel_rate=None, gyro_rate=None) -> bool
icm42688.ICM42688().configure(accel_range=None, gyro_range=None, accel_rate=None, gyro_rate=None) -> boolConfigure full-scale ranges and output data rates for this IMU.
| 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
icm42688.ICM42688().read() -> dictRead acceleration, gyroscope, and temperature from this IMU.
icm42688.ICM42688().accel() -> dict
icm42688.ICM42688().accel() -> dictRead acceleration only.
icm42688.ICM42688().gyro() -> dict
icm42688.ICM42688().gyro() -> dictRead angular velocity only.
icm42688.ICM42688().temperature() -> float
icm42688.ICM42688().temperature() -> floatRead the on-chip temperature in degrees Celsius.
icm42688.ICM42688().ready() -> bool
icm42688.ICM42688().ready() -> boolCheck whether a fresh accelerometer/gyroscope sample is ready.
icm42688.ICM42688().sleep(enabled=None) -> bool
icm42688.ICM42688().sleep(enabled=None) -> boolPut this sensor into or out of sleep mode.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
enabled |
bool |
positional or keyword | No | Optional value. Defaults to None. |
icm42688.ICM42688().wake() -> bool
icm42688.ICM42688().wake() -> boolWake the accelerometer and gyroscope in low-noise mode.
icm42688.ICM42688().reset() -> bool
icm42688.ICM42688().reset() -> boolSoft-reset this sensor and restore its configuration.
icm42688.ICM42688().id() -> int
icm42688.ICM42688().id() -> intRead this sensor's WHO_AM_I register.
icm42688.ICM42688().info() -> dict
icm42688.ICM42688().info() -> dictReturn I2C settings, chip id, ranges, rates, and scale factors for this IMU.
icm42688.ICM42688().close() -> bool
icm42688.ICM42688().close() -> boolRelease this ICM-42688 handle.
icm42688.ICM42688().Example
icm42688.ICM42688().Exampleimu = 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
icm42688.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> boolLegacy: initialize the module-level default ICM-42688 sensor.
Prefer ``imu = icm42688.ICM42688(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| 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. |
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
icm42688.configure(accel_range: int = None, gyro_range: int = None, accel_rate: any = None, gyro_rate: any = None) -> boolConfigure full-scale ranges and output data rates.
| 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. |
bool True when the configuration registers are updated.
icm42688.read() -> dict
icm42688.read() -> dictRead acceleration, gyroscope, and temperature.
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
icm42688.accel() -> dictRead acceleration only.
dict Dict with ``ok``, ``x``, ``y``, ``z``, ``x_g``, ``y_g``, ``z_g``, and ``range_g``.
icm42688.gyro() -> dict
icm42688.gyro() -> dictRead angular velocity only.
dict Dict with ``ok``, ``x``, ``y``, ``z``, ``x_dps``, ``y_dps``, ``z_dps``, and ``range_dps``.
icm42688.temperature() -> float
icm42688.temperature() -> floatRead the on-chip temperature sensor.
float Temperature in degrees Celsius.
icm42688.ready() -> bool
icm42688.ready() -> boolCheck whether a fresh accelerometer/gyroscope sample is ready.
bool True when the data-ready status bit is set.
icm42688.sleep(enabled: bool = None) -> bool
icm42688.sleep(enabled: bool = None) -> boolPut the sensor into or out of sleep mode.
| 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. |
bool True when the power-management register is updated.
icm42688.wake() -> bool
icm42688.wake() -> boolWake the accelerometer and gyroscope in low-noise mode.
bool True when the wake command is accepted.
icm42688.reset() -> bool
icm42688.reset() -> boolSoft-reset the sensor and restore the default module configuration.
bool True when reset and reconfiguration succeed.
icm42688.id() -> int
icm42688.id() -> intRead the WHO_AM_I register.
int Integer device identifier. A normal ICM-42688 returns 0x47.
icm42688.info() -> dict
icm42688.info() -> dictReturn ICM-42688 module state.
dict Dict with initialization state, I2C settings, chip id, ranges, rates, and scale factors.