ICM20649 Simple test

Ensure your ICM20649 device works with one of these simple tests.

examples/icm20x_icm20649_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_icm20x

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

while True:
    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (icm.acceleration))
    print("Gyro X:%.2f, Y: %.2f, Z: %.2f rads/s" % (icm.gyro))
    print("")
    time.sleep(0.5)

ICM20649 Full test

Test using all the ICM20649 sensor capabilities

examples/examples/icm20x_icm20649_full_test.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from adafruit_icm20x import ICM20649, AccelRange, GyroRange


def printNewMax(value, current_max, axis):
    if value > current_max:
        current_max = value
        print(axis, "Max:", current_max)
    return current_max


# pylint:disable=no-member
i2c = board.I2C()  # uses board.SCL and board.SDA

ism = ICM20649(i2c)

ism.accelerometer_range = AccelRange.RANGE_30G
print("Accelerometer range set to: %d g" % AccelRange.string[ism.accelerometer_range])

ism.gyro_range = GyroRange.RANGE_500_DPS
print("Gyro range set to: %d DPS" % GyroRange.string[ism.gyro_range])

ax_max = ay_max = az_max = 0
gx_max = gy_max = gz_max = 0

ism.gyro_data_rate = 125
ism.accelerometer_data_rate = 4095
st = time.monotonic()
while time.monotonic() - st < 0.250:

    print(
        "Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f degrees/s"
        % (ism.acceleration + ism.gyro)
    )

#     acceleration = ism.acceleration
#     # ax_max = printNewMax(acceleration[0], ax_max, "AX")
#     # ay_max = printNewMax(acceleration[1], ay_max, "AY")
#     # az_max = printNewMax(acceleration[2], az_max, "AZ")

#     gyro = ism.gyro
#     # gx_max = printNewMax(gyro[0], gx_max, "GX")
#     # gy_max = printNewMax(gyro[1], gy_max, "GY")
#     # gz_max = printNewMax(gyro[2], gz_max, "GZ")

ICM20948 Simple test

Ensure your ICM20948 device works with one of these simple tests.

examples/icm20x_icm20948_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_icm20x

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

while True:
    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (icm.acceleration))
    print("Gyro X:%.2f, Y: %.2f, Z: %.2f rads/s" % (icm.gyro))
    print("Magnetometer X:%.2f, Y: %.2f, Z: %.2f uT" % (icm.magnetic))
    print("")
    time.sleep(0.5)

ICM20948 Acceleration data rate test

Example showing ICM20948 sensor cycling between two acceleration data rates

examples/icm20x_icm20948_accel_data_rate_test.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from adafruit_icm20x import ICM20948

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

# Cycle between two data rates
# Best viewed in the Mu serial plotter where you can see how
# the data rate affects the resolution of the data
while True:
    icm.accelerometer_data_rate_divisor = 0  # minimum
    print("Data Rate:", icm.accelerometer_data_rate)
    time.sleep(2)
    for i in range(cycles):
        print(icm.acceleration)

    icm.accelerometer_data_rate_divisor = 4095  # maximum
    print("Data Rate:", icm.accelerometer_data_rate)
    time.sleep(2)
    for i in range(cycles):
        print(icm.acceleration)

ICM20948 Gyro data rate test

Example showing ICM20948 sensor cycling between two gyro data rates

examples/icm20x_icm20948_gyro_data_rate_test.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from adafruit_icm20x import ICM20948

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

# Cycle between two data rates
# Best viewed in the Mu serial plotter where you can see how
# the data rate affects the resolution of the data
while True:
    icm.gyro_data_rate_divisor = 0  # minimum
    print("Data Rate:", icm.gyro_data_rate)
    time.sleep(2)
    for i in range(cycles):
        print(icm.gyro)

    icm.gyro_data_rate_divisor = 255  # maximum
    print("Data Rate:", icm.gyro_data_rate)
    time.sleep(2)
    for i in range(cycles):
        print(icm.gyro)

ICM20948 Magnetic data rate test

Example showing ICM20948 sensor cycling between two magnetic data rates

examples/icm20x_icm20948_mag_data_rate_test.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# pylint: disable=no-member
import time
import board
from adafruit_icm20x import MagDataRate, ICM20948

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

# Cycle between two data rates
# Best viewed in the Mu serial plotter where you can see how
# the data rate affects the resolution of the data
while True:
    icm.magnetometer_data_rate = MagDataRate.RATE_100HZ
    for i in range(cycles):
        print(icm.magnetic)
    time.sleep(0.3)
    icm.magnetometer_data_rate = MagDataRate.RATE_10HZ
    for i in range(cycles):
        print(icm.magnetic)
    time.sleep(0.3)