DevLab_ICM20948 1.0.2 ICM-20948 9-Axis Motion Sensor Driver

Loading...
Searching...
No Matches
DevLab ICM20948 Arduino Library

Arduino driver for the module DevLab ICM-20948 9-axis IMU sensor.

This library is a DevLab adaptation derived from the 7Semi ICM20948 Arduino Library. The original MIT license notice from 7semi-solutions is preserved in `LICENSE`. See `NOTICE.md` for attribution and origin details.

The ICM-20948 integrates a 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer (AK09916), enabling motion tracking, orientation sensing, and navigation applications.

# Features

- 9-axis motion sensing
  - 3-axis Accelerometer
  - 3-axis Gyroscope
  - 3-axis Magnetometer
- Configurable sensor ranges
  - Accel: ±2g / ±4g / ±8g / ±16g
  - Gyro: ±250 / ±500 / ±1000 / ±2000 dps
- Digital Low Pass Filter configurable(DLPF)
  - Noise reduction
  - Configurable bandwidth
- Adjustable sample rates
  - Accel: up to 1125 Hz
  - Gyro: up to 1100 Hz
- Internal I2C Master (for magnetometer)
  - AK09916 integration via SLV0/SLV4
- ISupports both communication interfaces
  - I²C
  - SPI
- Temperature measurement

# Connections / Wiring

The ICM-20948 supports both I²C and SPI communication.

# I²C Connection

ICM-20948 Pin | MCU Pin | Notes
--- | --- | ---
VCC | 3.3V | 5V only if board supports
GND | GND | Common ground
SDA | SDA | I²C data
SCL | SCL | I²C clock
AD0 | GND/3V3 | Address select

## I²C Notes

- Default I²C address: 0x29
- Supported bus speeds:
  - 100 kHz
  - 400 kHz (recommended)

# SPI Connection

ICM-20948 Pin | MCU Pin
--- | ---
VCC | 3.3V
GND | GND
SCK | SCK
MOSI | MOSI
MISO | MISO
CS | GPIO

# Installation

## Arduino Library Manager

1. Open Arduino IDE
2. Go to Library Manager
3. Search for DevLab ICM20948
4. Click Install

## Manual Installation

1. Download repository as ZIP
2. Arduino IDE → Sketch → Include Library → Add .ZIP Library

# Library Overview

## Initialize Sensor

- I2C

if (!imu.beginI2C(0x69, Wire, 400000))
{
Serial.println("IMU init failed");
while (1);
}
DevLab_ICM20948::beginI2C
bool beginI2C(uint8_t address=0x69, TwoWire &i2cPort=Wire, uint32_t i2cSpeed=400000)
Definition DevLab_ICM20948.cpp:6
imu
DevLab_ICM20948 imu
Global ICM-20948 driver instance.
Definition gyr_test.ino:98

- SPI

if (!imu.beginSPI(CS_PIN, SPI, 1000000))
{
Serial.println("SPI init failed");
while (1);
}
DevLab_ICM20948::beginSPI
bool beginSPI(uint8_t csPin, SPIClass &spiPort=SPI, uint32_t spiSpeed=1000000)
Definition DevLab_ICM20948.cpp:60
CS_PIN
#define CS_PIN
Definition spi_accel.ino:36

## Enable Sensors

imu.setSensors(true, true, true);
DevLab_ICM20948::setSensors
bool setSensors(bool accel_on, bool gyro_on, bool temp_on)
Definition DevLab_ICM20948.cpp:1006

- accel → enable accelerometer
- gyro → enable gyroscope
- temp → enable temperatur

# Reading Accelerometer

float ax, ay, az;
imu.readAccel(ax, ay, az);
DevLab_ICM20948::readAccel
bool readAccel(float &x, float &y, float &z)
Definition DevLab_ICM20948.cpp:238

- Output in g

# Reading Gyroscope

float gx, gy, gz;
imu.readGyro(gx, gy, gz);
DevLab_ICM20948::readGyro
bool readGyro(float &x, float &y, float &z)
Definition DevLab_ICM20948.cpp:258

- Output in degrees/sec

# Reading Temperature

float temp;
imu.readTemperature(temp);
DevLab_ICM20948::readTemperature
bool readTemperature(float &temperature)
Definition DevLab_ICM20948.cpp:278

- Output in °C

# Reading Magnetometer

imu.initMag();
float mx, my, mz;
imu.readMag(mx, my, mz);
DevLab_ICM20948::initMag
bool initMag()
Definition DevLab_ICM20948.cpp:334
DevLab_ICM20948::readMag
bool readMag(float &x, float &y, float &z)
Definition DevLab_ICM20948.cpp:310

- Output in microtesla (µT)

# Setting Accelerometer Scale

imu.setAccelScale(G_4);
ICM20948_Accel_FullScale::G_4
@ G_4
DevLab_ICM20948::setAccelScale
bool setAccelScale(ICM20948_Accel_FullScale fullScale)
Definition DevLab_ICM20948.cpp:857

- G_2, G_4, G_8, G_16

## Setting Gyroscope Scale

imu.setGyroScale(DPS_2000);
ICM20948_Gyro_FullScale::DPS_2000
@ DPS_2000
DevLab_ICM20948::setGyroScale
bool setGyroScale(ICM20948_Gyro_FullScale fullScale)
Definition DevLab_ICM20948.cpp:644

## Setting Sample Rate

imu.setAccelSampleRate(225);
imu.setGyroSampleRate(225);
DevLab_ICM20948::setGyroSampleRate
bool setGyroSampleRate(float sampleRate)
Definition DevLab_ICM20948.cpp:550
DevLab_ICM20948::setAccelSampleRate
bool setAccelSampleRate(uint16_t sampleRate)
Definition DevLab_ICM20948.cpp:709

## DLPF Configuration

imu.setAccelDLPF(ACCEL_DLPFCFG_3, false);
imu.setDLPF(GYRO_DLPF_3, false);
ACCEL_DLPFCFG_3
#define ACCEL_DLPFCFG_3
Definition ICM20948_regs.h:348
DevLab_ICM20948::setDLPF
bool setDLPF(ICM20948_Gyro_DLPF dlpf, bool bypass)
Definition DevLab_ICM20948.cpp:593
DevLab_ICM20948::setAccelDLPF
bool setAccelDLPF(uint8_t dlpf, bool bypass)
Definition DevLab_ICM20948.cpp:897

## Averaging Configuration

imu.setAccelAveraging(AVG_8);
ICM20948_Gyro_Average::AVG_8
@ AVG_8
DevLab_ICM20948::setAccelAveraging
bool setAccelAveraging(ICM20948_Accel_Average avg)
Definition DevLab_ICM20948.cpp:952

# Applications

- Robotics (obstacle detection)
- Drones (altitude sensing)
- Wearables (activity tracking)
- Navigation systems (IMU fusion)
- ndustrial motion sensing
- Gaming controllers

# License

- MIT License
- Original work copyright: 2025 7semi-solutions
- DevLab adaptation maintains the original license notice and attribution.