Simple test

Ensure your device works with this simple test.

examples/icm20948_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya

import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

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


while True:
    accx, accy, accz = icm.acceleration
    gyrox, gyroy, gyroz = icm.gyro
    print(f"x: {accx}m/s², y: {accy},m/s² z: {accz}m/s²")
    print(f"x: {gyrox}°/s, y: {gyroy}°/s, z: {gyroz}°/s")
    print()
    time.sleep(1)

Clock select settings

Example showing the Clock select setting

examples/icm20948_clock_select.py
import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
icm = icm20948.ICM20948(i2c)

icm.clock_select = icm20948.CLK_SELECT_INTERNAL

while True:
    for clock_select in icm20948.clk_values:
        print("Current Clock select setting: ", icm.clock_select)
        for _ in range(10):
            accx, accy, accz = icm.acceleration
            print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
            print()
            time.sleep(0.5)
        icm.clock_select = clock_select

Accelerometer range settings

Example showing the Accelerometer range setting

examples/icm20948_accelerometer_range.py
import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
icm = icm20948.ICM20948(i2c)

icm.accelerometer_range = icm20948.RANGE_2G

while True:
    for accelerometer_range in icm20948.acc_range_values:
        print("Current Accelerometer range setting: ", icm.accelerometer_range)
        for _ in range(10):
            accx, accy, accz = icm.acceleration
            print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
            print()
            time.sleep(0.5)
        icm.accelerometer_range = accelerometer_range

Acc dlpf cutoff settings

Example showing the Acc dlpf cutoff setting

examples/icm20948_acc_dlpf_cutoff.py
import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
icm = icm20948.ICM20948(i2c)

icm.acc_dlpf_cutoff = icm20948.FREQ_246_0

while True:
    for acc_dlpf_cutoff in icm20948.acc_filter_values:
        print("Current Acc dlpf cutoff setting: ", icm.acc_dlpf_cutoff)
        for _ in range(10):
            accx, accy, accz = icm.acceleration
            print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
            print()
            time.sleep(0.5)
        icm.acc_dlpf_cutoff = acc_dlpf_cutoff

Gyro full scale settings

Example showing the Gyro full scale setting

examples/icm20948_gyro_full_scale.py
import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
icm = icm20948.ICM20948(i2c)

icm.gyro_full_scale = icm20948.FS_250_DPS

while True:
    for gyro_full_scale in icm20948.gyro_full_scale_values:
        print("Current Gyro full scale setting: ", icm.gyro_full_scale)
        for _ in range(10):
            gyrox, gyroy, gyroz = icm.gyro
            print("x:{:.2f}°/s, y:{:.2f}°/s, z:{:.2f}°/s".format(gyrox, gyroy, gyroz))
            print()
            time.sleep(0.5)
        icm.gyro_full_scale = gyro_full_scale

Gyro dlpf cutoff settings

Example showing the Gyro dlpf cutoff setting

examples/icm20948_gyro_dlpf_cutoff.py
import time
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
icm = icm20948.ICM20948(i2c)

icm.gyro_dlpf_cutoff = icm20948.G_FREQ_11_6

while True:
    for gyro_dlpf_cutoff in icm20948.gyro_filter_values:
        print("Current Gyro dlpf cutoff setting: ", icm.gyro_dlpf_cutoff)
        for _ in range(10):
            gyrox, gyroy, gyroz = icm.gyro
            print("x:{:.2f}°/s, y:{:.2f}°/s, z:{:.2f}°/s".format(gyrox, gyroy, gyroz))
            print()
            time.sleep(0.5)
        icm.gyro_dlpf_cutoff = gyro_dlpf_cutoff

Temperature Example

Example showing the how to get the temperature

examples/icm20948_temperature.py
from micropython_icm20948 import icm20948

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

_ = icm.temperature  # Dummy read to initialize the sensor
time.sleep(0.05)


while True:
    print(f"Temperature: {icm.temperature}°C")
    print()
    time.sleep(1)