Bryan Siepert
1 Dependencies 3
2 Installing from PyPI 5
3 Usage Example 7
4 Contributing 9
5 Documentation 11
6 Table of Contents 13
6.1 Simple test . . . 13
6.2 adafruit_icm20x . . . 14
6.2.1 Implementation Notes . . . 14
7 Indices and tables 17
Python Module Index 19
AdafruitICM20X Library Documentation, Release 1.0
Dependencies
This driver depends on: • Adafruit CircuitPython
• Bus Device
• Register
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading
AdafruitICM20X Library Documentation, Release 1.0
Installing from PyPI
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locallyfrom PyPI. To install for current user:
pip3 install adafruit-circuitpython-icm20x
To install system-wide (this may be required in some cases):
sudo pip3 install adafruit-circuitpython-icm20x
To install in a virtual environment in your current project:
mkdir project-name && cd project-name python3 -m venv .env
source .env/bin/activate
AdafruitICM20X Library Documentation, Release 1.0
Usage Example
For use with the ICM20649:
import time import board import busio
import adafruit_icm20x
i2c = busio.I2C(board.SCL, 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)
For use with the ICM20948:
import time import board import busio
import adafruit_icm20x
i2c = busio.I2C(board.SCL, 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("")
AdafruitICM20X Library Documentation, Release 1.0
Contributing
AdafruitICM20X Library Documentation, Release 1.0
Documentation
AdafruitICM20X Library Documentation, Release 1.0
Table of Contents
6.1 Simple test
Ensure your device works with one of these simple tests.
Listing 1: examples/icm20x_icm20649_simpletest.py 1 import time
2 import board 3 import busio
4 import adafruit_icm20x 5
6 i2c = busio.I2C(board.SCL, board.SDA) 7 icm = adafruit_icm20x.ICM20649(i2c) 8
9 while True:
10 print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (icm.acceleration)) 11 print("Gyro X:%.2f, Y: %.2f, Z: %.2f rads/s" % (icm.gyro))
12 print("") 13 time.sleep(0.5)
Listing 2: examples/icm20x_icm20948_simpletest.py 1 import time
2 import board 3 import busio
4 import adafruit_icm20x 5
6 i2c = busio.I2C(board.SCL, board.SDA) 7 icm = adafruit_icm20x.ICM20948(i2c) 8
9 while True:
AdafruitICM20X Library Documentation, Release 1.0
(continued from previous page) 12 print("Magnetometer X:%.2f, Y: %.2f, Z: %.2f uT" % (icm.magnetic))
13 print("") 14 time.sleep(0.5)
6.2
adafruit_icm20x
Library for the ST ICM20X Motion Sensor Family • Author(s): Bryan Siepert
6.2.1 Implementation Notes
Hardware:
• Adafruit’s ICM20649 Breakout:https://adafruit.com/product/4464
• Adafruit’s ICM20948 Breakout:https://adafruit.com/product/4554 Software and Dependencies:
• Adafruit CircuitPython firmware for the supported boards:https://circuitpython.org/downloads
• Adafruit’s Bus Device library:https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
• Adafruit’s Register library:https://github.com/adafruit/Adafruit_CircuitPython_Register class adafruit_icm20x.AccelDLPFFreq
Options foraccel_dlpf_cutoff
class adafruit_icm20x.AccelRange
Options foraccelerometer_range
class adafruit_icm20x.CV
struct helper
classmethod add_values(value_tuples)
Add CV values to the class
classmethod is_valid(value)
Validate that a given value is a member
class adafruit_icm20x.GyroDLPFFreq
Options forgyro_dlpf_cutoff
class adafruit_icm20x.GyroRange
Options forgyro_data_range
class adafruit_icm20x.ICM20649(i2c_bus,address=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– The I2C slave address of the sensor
class adafruit_icm20x.ICM20948(i2c_bus,address=105)
Library for the ST ICM-20948 Wide-Range 6-DoF Accelerometer and Gyro.
Parameters
magnetometer_data_rate
The rate at which the magenetometer takes measurements to update its output registers
class adafruit_icm20x.ICM20X(i2c_bus,address)
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– The I2C slave address of the sensor
accel_dlpf_cutoff
The cutoff frequency for the accelerometer’s digital low pass filter. Signals above the given frequency will be filtered out. Must be anAccelDLPFCutoff. Use AccelDLPFCutoff.DISABLED to disable the filter
Notereadings immediately following setting a cutoff frequency will be inaccurate due to the filter “warm-ing up”
acceleration
The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2.
accelerometer_data_rate
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:
accelerometer_data_rate = 1125/(1+divisor)
This function does the math to find the divisor from a given rate but it will not be exactly as specified.
accelerometer_data_rate_divisor
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:
accelerometer_data_rate = 1125/(1+divisor)
This function sets the raw rate divisor.
accelerometer_range
Adjusts the range of values that the sensor can measure, from +/- 4G to +/-30G Note that larger ranges will be less accurate. Must be anAccelRange
gyro
The x, y, z angular velocity values returned in a 3-tuple and are in degrees / second
gyro_data_rate
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:
gyro_data_rate = 1100/(1+divisor)This function does the math to find the divisor from a given rate but it will not be exactly as specified.
gyro_data_rate_divisor
The divisor for the rate at which gyro measurements are taken in Hz
AdafruitICM20X Library Documentation, Release 1.0
This function sets the raw rate divisor.
gyro_dlpf_cutoff
The cutoff frequency for the gyro’s digital low pass filter. Signals above the given frequency will be filtered out. Must be aGyroDLPFFreq. Use GyroDLPFCutoff.DISABLED to disable the filter
Notereadings immediately following setting a cutoff frequency will be inaccurate due to the filter “warm-ing up”
gyro_range
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 aGyroRange
initialize()
Configure the sensors with the default settings. For use after callingreset()
reset()
Resets the internal registers and restores the default settings
class adafruit_icm20x.MagDataRate
Options formagnetometer_data_rate
Indices and tables
• genindex • modindex • search
AdafruitICM20X Library Documentation, Release 1.0
a
AdafruitICM20X Library Documentation, Release 1.0
A
accel_dlpf_cutoff (adafruit_icm20x.ICM20X at-tribute),15
AccelDLPFFreq(class in adafruit_icm20x),14
acceleration (adafruit_icm20x.ICM20X attribute),
15
accelerometer_data_rate
(adafruit_icm20x.ICM20X attribute),15
accelerometer_data_rate_divisor
(adafruit_icm20x.ICM20X attribute),15
accelerometer_range (adafruit_icm20x.ICM20X attribute),15
AccelRange(class in adafruit_icm20x),14
adafruit_icm20x(module),14
add_values() (adafruit_icm20x.CV class method),
14
C
CV(class in adafruit_icm20x),14
G
gyro(adafruit_icm20x.ICM20X attribute),15
gyro_data_rate (adafruit_icm20x.ICM20X at-tribute),15
gyro_data_rate_divisor
(adafruit_icm20x.ICM20X attribute),15
gyro_dlpf_cutoff (adafruit_icm20x.ICM20X at-tribute),16
gyro_range(adafruit_icm20x.ICM20X attribute),16
GyroDLPFFreq(class in adafruit_icm20x),14
GyroRange(class in adafruit_icm20x),14
I
ICM20649(class in adafruit_icm20x),14
ICM20948(class in adafruit_icm20x),14
ICM20X(class in adafruit_icm20x),15
initialize()(adafruit_icm20x.ICM20X method),16
M
MagDataRate(class in adafruit_icm20x),16
magnetic(adafruit_icm20x.ICM20948 attribute),15
magnetometer_data_rate
(adafruit_icm20x.ICM20948 attribute),15