1/***************************************************************
3 * @brief Minimal I2C bring-up for 7Semi ICM-20948 on UNO/ESP32 +
4 * continuous accelerometer readout
7 * - I2C init on default/custom pins
8 * - IMU beginI2C() on I2C (addr 0x68/0x69)
9 * - Manual sensor enable (setSensors)
10 * - Accel config: scale, DLPF, averaging, sample rate
11 * - Read accel (g) at ~2 Hz print
14 * - WHO_AM_I must be 0xEA
15 * - Sensors must be explicitly enabled
16 * - Bank switching handled internally by library
18 * Wiring (Arduino UNO I2C)
21 * - VCC -> 3V3 (or 5V if your board supports it)
24 * Wiring (ESP32 default I2C)
29 ***************************************************************/
32#include <DevLab_ICM20948.h>
34/* ====================== User Config ======================= */
37#define I2C_FREQ 400000UL
45 Serial.println(F("ICM-20948 (I2C) — Accel Example"));
46 Wire.begin(SDA_PIN, SCL_PIN);
47 /** Initialize IMU using I2C */
48 if (!imu.beginI2C(ICM_ADDR, Wire, 400000)) {
49 Serial.println(F("ERROR: ICM-20948 beginI2C() failed."));
53 Serial.println(F("ICM-20948 ready."));
55 /** Verify device identity */
57 if (imu.readWhoAmI(who)) {
58 Serial.print("WHO_AM_I: 0x");
59 Serial.println(who, HEX);
62 /** Enable only accelerometer
67 if (!imu.setSensors(true, false, false)) {
68 Serial.println(F("setSensors failed."));
71 /* ---------------- ACCEL CONFIG ----------------
72 * - Scale: ±2/±4/±8/±16 g
73 * - DLPF: noise filtering
74 * - Averaging: noise reduction
75 * - Sample rate: output frequency
78 /** Set accelerometer full-scale range */
79 if (!imu.setAccelScale(ICM20948_Accel_FullScale::G_4)) {
80 Serial.println(F("setAccelScale failed."));
83 /** Enable DLPF (recommended)
84 * - bypass = false → DLPF enabled
86 if (!imu.setAccelDLPF(ACCEL_DLPFCFG_3, false)) {
87 Serial.println(F("setAccelDLPF failed."));
90 /** Set averaging (noise reduction) */
91 if (!imu.setAccelAveraging(ICM20948_Accel_Average::AVG_8)) {
92 Serial.println(F("setAccelAveraging failed."));
95 /** Set output data rate (ODR)
97 * - ODR = 1125 / (1 + divider)
100 if (!imu.setAccelSampleRate(225)) {
101 Serial.println(F("setAccelSampleRate failed."));
110 /** Read accelerometer data
111 * - Output in g units
112 * - Returns true on success
114 if (imu.readAccel(ax, ay, az)) {
115 Serial.print("ACCEL [g]: ");
120 Serial.println(az, 3);
122 Serial.println(F("ACCEL read failed"));
125 Serial.println(F("-----------------------------"));