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
- 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
- Open Arduino IDE
- Go to Library Manager
- Search for DevLab ICM20948
- Click Install
Manual Installation
- Download repository as ZIP
- Arduino IDE → Sketch → Include Library → Add .ZIP Library
Library Overview
Initialize Sensor
{
Serial.println("IMU init failed");
while (1);
}
bool beginI2C(uint8_t address=0x69, TwoWire &i2cPort=Wire, uint32_t i2cSpeed=400000)
DevLab_ICM20948 imu
Global ICM-20948 driver instance.
{
Serial.println("SPI init failed");
while (1);
}
bool beginSPI(uint8_t csPin, SPIClass &spiPort=SPI, uint32_t spiSpeed=1000000)
Enable Sensors
bool setSensors(bool accel_on, bool gyro_on, bool temp_on)
- accel → enable accelerometer
- gyro → enable gyroscope
- temp → enable temperatur
Reading Accelerometer
float ax, ay, az;
bool readAccel(float &x, float &y, float &z)
Reading Gyroscope
float gx, gy, gz;
bool readGyro(float &x, float &y, float &z)
Reading Temperature
float temp;
bool readTemperature(float &temperature)
Reading Magnetometer
float mx, my, mz;
bool readMag(float &x, float &y, float &z)
- Output in microtesla (µT)
Setting Accelerometer Scale
bool setAccelScale(ICM20948_Accel_FullScale fullScale)
Setting Gyroscope Scale
bool setGyroScale(ICM20948_Gyro_FullScale fullScale)
Setting Sample Rate
bool setGyroSampleRate(float sampleRate)
bool setAccelSampleRate(uint16_t sampleRate)
DLPF Configuration
bool setDLPF(ICM20948_Gyro_DLPF dlpf, bool bypass)
bool setAccelDLPF(uint8_t dlpf, bool bypass)
Averaging Configuration
bool setAccelAveraging(ICM20948_Accel_Average avg)
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.