adafruit_icm20x

Library for the ST ICM20X Motion Sensor Family

  • Author(s): Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_icm20x.CV

struct helper

classmethod add_values(value_tuples: Iterable[Tuple]) None

Add CV values to the class

classmethod is_valid(value: AccelRange | GyroRange | GyroDLPFFreq | AccelDLPFFreq) bool

Validate that a given value is a member

class adafruit_icm20x.AccelRange

Options for ICM20X.accelerometer_range

class adafruit_icm20x.GyroRange

Options for ICM20X.gyro_data_range

class adafruit_icm20x.GyroDLPFFreq

Options for ICM20X.gyro_dlpf_cutoff

class adafruit_icm20x.AccelDLPFFreq

Options for ICM20X.accel_dlpf_cutoff

class adafruit_icm20x.ICM20X(i2c_bus: I2C, address: int)

Library for the ST ICM-20X Wide-Range 6-DoF Accelerometer and Gyro Family

Parameters:
  • i2c_bus (I2C) – The I2C bus the ICM20X is connected to.

  • address (int) – The I2C address of the device.

initialize() None

Configure the sensors with the default settings. For use after calling reset()

reset() None

Resets the internal registers and restores the default settings

data_ready() None

Checks if new data is available

property acceleration: Tuple[float, float, float]

The x, y, z acceleration values returned in a 3-tuple and are in \(m / s ^ 2.\)

property gyro: Tuple[float, float, float]

The x, y, z angular velocity values returned in a 3-tuple and are in \(radians / second\)

property accelerometer_range: AccelRange

Adjusts the range of values that the sensor can measure, from +/- 4G to +/-30G Note that larger ranges will be less accurate. Must be an AccelRange

property gyro_range: GyroRange

Adjusts the range of values that the sensor can measure, from 500 Degrees/second to 4000 degrees/s. Note that larger ranges will be less accurate. Must be a GyroRange

property accelerometer_data_rate_divisor: int

The divisor for the rate at which accelerometer measurements are taken in Hz

Note

The data rates are set indirectly by setting a rate divisor according to the following formula:

\[\text{accelerometer_data_rate} = \frac{1125}{1 + divisor}\]

This function sets the raw rate divisor.

property gyro_data_rate_divisor: int

The divisor for the rate at which gyro measurements are taken in Hz

Note

The data rates are set indirectly by setting a rate divisor according to the following formula:

\[\text{gyro_data_rate} = \frac{1100}{1 + divisor}\]

This function sets the raw rate divisor.

property accelerometer_data_rate: float

The rate at which accelerometer measurements are taken in Hz

Note

The data rates are set indirectly by setting a rate divisor according to the following formula:

\[\text{accelerometer_data_rate} = \frac{1125}{1 + divisor}\]

This function does the math to find the divisor from a given rate but it will not be exactly as specified.

property gyro_data_rate: float

The rate at which gyro measurements are taken in Hz

Note

The data rates are set indirectly by setting a rate divisor according to the following formula:

\[\text{gyro_data_rate } = \frac{1100}{1 + divisor}\]

This function does the math to find the divisor from a given rate but it will not be exactly as specified.

property accel_dlpf_cutoff: AccelDLPFFreq

The cutoff frequency for the accelerometer’s digital low pass filter. Signals above the given frequency will be filtered out. Must be an AccelDLPFCutoff. Use AccelDLPFCutoff.DISABLED to disable the filter

Note

Readings immediately following setting a cutoff frequency will be inaccurate due to the filter “warming up”

property gyro_dlpf_cutoff: GyroDLPFFreq

The cutoff frequency for the gyro’s digital low pass filter. Signals above the given frequency will be filtered out. Must be a GyroDLPFFreq. Use GyroDLPFCutoff.DISABLED to disable the filter

Note

Readings immediately following setting a cutoff frequency will be inaccurate due to the filter “warming up”

property gravity: float

The gravity magnitude in m/s^2.

class adafruit_icm20x.ICM20649(i2c_bus: I2C, address: int = 104)

Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro.

Parameters:
  • i2c_bus (I2C) – The I2C bus the ICM20649 is connected to.

  • address (int) – The I2C address of the device. Defaults to 0x68

Quickstart: Importing and using the ICM20649 temperature sensor

Here is an example of using the ICM2020649 class. First you will need to import the libraries to use the sensor

import board
import adafruit_icm20x

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
icm = adafruit_icm20x.ICM20649(i2c)

Now you have access to the acceleration using acceleration attribute and the gyro information using the gyro attribute.

acceleration = icm.acceleration
gyro = icm.gyro
class adafruit_icm20x.MagDataRate

Options for ICM20948.magnetometer_data_rate

class adafruit_icm20x.ICM20948(i2c_bus: I2C, address: int = 105)

Library for the ST ICM-20948 Wide-Range 6-DoF Accelerometer and Gyro.

Parameters:
  • i2c_bus (I2C) – The I2C bus the ICM20948 is connected to.

  • address (int) – The I2C address of the device. Defaults to 0x69

Quickstart: Importing and using the ICM20948 temperature sensor

Here is an example of using the ICM20948 class. First you will need to import the libraries to use the sensor

import board
import adafruit_icm20x

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
icm = adafruit_icm20x.ICM20948(i2c)

Now you have access to the acceleration using acceleration attribute, the gyro information using the gyro attribute and the magnetic information using the magnetic attribute

acceleration = icm.acceleration
gyro = icm.gyro
magnetic = icm.magnetic
property magnetic: Tuple[float, float, float]

The current magnetic field strengths on the X, Y, and Z axes in uT (micro-teslas)

property magnetometer_data_rate: MagDataRate

The rate at which the magnetometer takes measurements to update its output registers