Arduino driver for the TDK InvenSense ICM-20948 9-axis IMU sensor.
The ICM-20948 integrates a 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer (AK09916), enabling motion tracking, orientation sensing, and navigation applications.
-
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 (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
The ICM-20948 supports both I²C and SPI communication.
| 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 |
- Default I²C address: 0x29
- Supported bus speeds:
- 100 kHz
- 400 kHz (recommended)
| ICM-20948 Pin | MCU Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SCK | SCK |
| MOSI | MOSI |
| MISO | MISO |
| CS | GPIO |
- Open Arduino IDE
- Go to Library Manager
- Search for 7Semi ICM20948
- Click Install
- Download repository as ZIP
- Arduino IDE → Sketch → Include Library → Add .ZIP Library
- I2C
if (!imu.beginI2C(0x69, Wire, 400000))
{
Serial.println("IMU init failed");
while (1);
}- SPI
if (!imu.beginSPI(CS_PIN, SPI, 1000000))
{
Serial.println("SPI init failed");
while (1);
}imu.setSensors(true, true, true);- accel → enable accelerometer
- gyro → enable gyroscope
- temp → enable temperatur
float ax, ay, az;
imu.readAccel(ax, ay, az);- Output in g
float gx, gy, gz;
imu.readGyro(gx, gy, gz);- Output in degrees/sec
float temp;
imu.readTemperature(temp);- Output in °C
imu.initMag();
float mx, my, mz;
imu.readMag(mx, my, mz);- Output in microtesla (µT)
imu.setAccelScale(G_4);- G_2, G_4, G_8, G_16
imu.setGyroScale(DPS_2000);imu.setAccelSampleRate(225);
imu.setGyroSampleRate(225);imu.setAccelDLPF(ACCEL_DLPFCFG_3, false);
imu.setDLPF(GYRO_DLPF_3, false);imu.setAccelAveraging(AVG_8);- Robotics (obstacle detection)
- Drones (altitude sensing)
- Wearables (activity tracking)
- Navigation systems (IMU fusion)
- ndustrial motion sensing
- Gaming controllers
- MIT License