MicroPython ICM20948 Driver

ICM20948

MicroPython Driver for the ICM20948 Accelerometer/Gyro Sensor

  • Author(s): Jose D. Montoya

Implementation Notes

Software and Dependencies:

This library depends on Micropython

class micropython_icm20948.icm20948.ICM20948(i2c, address=0x69)[source]

Main class for the Sensor

Parameters:
i2c : I2C

The I2C bus the ICM20948 is connected to.

address : int

The I2C device address. Defaults to 0x69

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
import micropython_icm20948.icm20948 as icm20948

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
icm = icm20948.ICM20948(i2c)

Now you have access to the acceleration attribute and gyro attribute

accx, accy, accz = icm.accelerometer
gyro = icm.gyro
property acc_data_rate

The rate at which accelerometer measurements are taken in Hz

property acc_data_rate_divisor : int

Accepted values are:

* 7
* 10
* 15
* 22
* 31
* 63
* 127
* 255
* 513
* 1022
* 2044
* 4095
property acc_dlpf_cutoff : int

The cutoff frequency for the accelerometer’s digital low pass filter. Signals above the given frequency will be filtered out.

Note

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

Mode

Value

icm20948.FREQ_246_0

0b001

icm20948.FREQ_111_4

0b010

icm20948.FREQ_50_4

0b011

icm20948.FREQ_23_9

0b100

icm20948.FREQ_11_5

0b101

icm20948.FREQ_5_7

0b110

icm20948.FREQ_473

0b111

property acc_enabled : str

Accelerometer enabled

Mode

Value

icm20948.ACC_ENABLED

0b000 Accelerometer (all axes) on

icm20948.ACC_DISABLED

0b111 Accelerometer (all axes) disabled

property acc_filter_choice : int

Enables accelerometer DLPF

property acceleration : tuple[float, float, float]

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

property accelerometer_range : str

Sensor acceleration_range

Mode

Value

icm20948.RANGE_2G

0b00

icm20948.RANGE_4G

0b01

icm20948.RANGE_8G

0b10

icm20948.RANGE_16G

0b11

property clock_select

CLK_SELECT_INTERNAL: Internal 20 MHz oscillator CLK_SELECT_BEST: Auto selects the best available clock source - PLL if ready, else use the Internal oscillator CLK_SELECT_STOP: Stops the clock and keeps timing generator in reset NOTE: CLKSEL should be set to CLK_SELECT_BEST to achieve full gyroscope performance.

Mode

Value

icm20948.CLK_SELECT_INTERNAL

0b000

icm20948.CLK_SELECT_BEST

0b001

icm20948.CLK_SELECT_STOP

0b111

property gyro : tuple[float, float, float]

Gyro Property. The x, y, z angular velocity values returned in a 3-tuple and are in \(degrees / second\) :return: Angular velocity Values

property gyro_data_rate

The rate at which gyro measurements are taken in Hz

property gyro_data_rate_divisor : int

Accepted values are:

* 1
* 2
* 3
* 4
* 5
* 7
* 8
* 10
* 15
* 16
* 22
* 31
* 32
* 63
* 64
* 255
property gyro_dlpf_cutoff : int

The cutoff frequency for the gyro’s digital low pass filter. Signals above the given frequency will be filtered out.

Note

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

Mode

Value

icm20948.G_FREQ_196_6

0b000

icm20948.G_FREQ_151_8

0b001

icm20948.G_FREQ_119_5

0b010

icm20948.G_FREQ_51_2

0b011

icm20948.G_FREQ_23_9

0b100

icm20948.G_FREQ_11_6

0b101

icm20948.G_FREQ_5_7

0b110

icm20948.G_FREQ_361_4

0b111

property gyro_enabled : str

Gyro Enabled

Mode

Value

icm20948.GYRO_ENABLED

0b000 Gyroscope (all axes) on

icm20948.GYRO_DISABLED

0b111 Gyroscope (all axes) disabled

property gyro_filter_choice : int

Enables gyro DLPF

property gyro_full_scale : str

Sensor gyro_full_scale

Mode

Value

icm20948.FS_250_DPS

0b00

icm20948.FS_500_DPS

0b01

icm20948.FS_1000_DPS

0b10

icm20948.FS_2000_DPS

0b11

property power_bank : int

Power bank selected

property reset : int

Reset the internal registers and restores the default settings. Write a 1 to set the reset, the bit will auto clear

property temperature : float

Temperature Value. In the setup tested, there is the need to read either the values from acceleration, gyro and temperature or gyro and temperature at the same time in order to have a logic temperature value.

property temperature_enabled : str

Temperature Enabled. When set to 1, this bit disables the temperature sensor.

Mode

Value

icm20948.TEMP_ENABLED

0b0 Temperature on

icm20948.TEMP_DISABLED

0b1 Temperature disabled