7Semi_ICM20948 is a lightweight Arduino library for the TDK ICM-20948 9-axis IMU.
It supports both I²C and SPI interfaces with flexible configuration, including DLPF, ODR, full-scale selection, and sensor gating.
- I²C (400 kHz+) and SPI (Mode 0) support
- Accelerometer, Gyroscope, Magnetometer, and Temperature readouts
- Built-in scale conversion to physical units (g, dps, µT, °C)
- DLPF (Digital Low-Pass Filter) configuration
- Adjustable output data rates (ODR)
- Self-test, decimation (DEC3), and averaging options
-
- SCLK → D13
-
- MISO (SDO) → D12
-
- MOSI (SDI) → D11
-
- CS → D10
-
- INT → D2, optional
-
- 3V3 → 3.3V
-
- GND → GND
-
- SCLK → GPIO18
-
- MISO (SDO) → GPIO19
-
- MOSI (SDI) → GPIO23
-
- CS → GPIO5
-
- INT → any GPIO, optional
-
- 3V3 → 3.3V
-
- GND → GND
-
- SCL → A5
-
- SDA → A4
-
- INT → D2, optional
-
- 3V3 → 3.3V
-
- GND → GND
-
- SCL → GPIO22
-
- SDA → GPIO21
-
- INT → any GPIO, optional
-
- 3V3 → 3.3V
-
- GND → GND
-
Magnetometer (AK09916)
- The magnetometer is connected internally to the ICM-20948 via an auxiliary I²C master interface.
- It works automatically when you call
readMag(). - If your board exposes AUX_DA / AUX_CL (SDA/SCL) pins, you can also connect them to your MCU I²C bus and enable bypass mode.
-
Voltage Levels
- Always use 3.3 V logic.
- The ICM-20948 is not 5 V tolerant unless your breakout includes level shifting.
-
SPI Mode
- The device operates in SPI Mode 0 (CPOL = 0, CPHA = 0).
- SPI clock is 1000000 Hz.
-
I²C Mode
- Default address is 0x68; if AD0 = HIGH, it becomes 0x69.
- Use
imu.begin(Wire, 0x68)orimu.begin(Wire, 0x69)accordingly.
-
Sensor Orientation
- Axes follow the right-hand convention:
- +X → right - left
- +Y → forward - backward
- +Z → up - down
- Use
invertAxes()if you need to match your board’s orientation.
- Axes follow the right-hand convention:
-
Temperature Output
- The temperature sensor reports die temperature, not ambient.
- Typical offset is around +10 °C compared to the environment.
-
Power Notes
- Typical active current: ~3.5 mA (Accel + Gyro)
- Use
setSensors()to disable unused sensors to save power.
-
Best Practices
- Always call
applyBasicDefaults()afterbegin(). - Add a short delay (~100 ms) after
begin()before reading data. - For very stable readings, apply simple averaging in software (e.g. 10-sample moving average).
- Always call
-
Interface bring-up
SPI.begin()andWire.begin()must match your board type.- On Arduino UNO / AVR: use default hardware pins only.
- On ESP32: call
SPIClass SPI_ESP32(VSPI); SPI_ESP32.begin(SCK, MISO, MOSI, CS);and
Wire.begin(SDA, SCL);beforeimu.begin().