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 ======================= */
35/** @brief I2C SDA pin used by the example board. */
37/** @brief I2C SCL pin used by the example board. */
39/** @brief I2C bus speed in hertz. */
40#define I2C_FREQ 400000UL
41/** @brief ICM-20948 I2C address selected by the AD0 pin. */
44/** @brief Global ICM-20948 driver instance. */
48 * @brief Configure the IMU for accelerometer-only operation over I2C.
50 * The function initializes the bus, verifies the device identity, enables the
51 * accelerometer, and applies range, DLPF, averaging, and sample-rate settings.
56 Serial.println(F("ICM-20948 (I2C) — Accel Example"));
57 Wire.begin(SDA_PIN, SCL_PIN);
58 /* Initialize IMU using I2C. */
59 if (!imu.beginI2C(ICM_ADDR, Wire, 400000)) {
60 Serial.println(F("ERROR: ICM-20948 beginI2C() failed."));
64 Serial.println(F("ICM-20948 ready."));
66 /* Verify device identity. */
68 if (imu.readWhoAmI(who)) {
69 Serial.print("WHO_AM_I: 0x");
70 Serial.println(who, HEX);
73 /* Enable only accelerometer
78 if (!imu.setSensors(true, false, false)) {
79 Serial.println(F("setSensors failed."));
82 /* ---------------- ACCEL CONFIG ----------------
83 * - Scale: ±2/±4/±8/±16 g
84 * - DLPF: noise filtering
85 * - Averaging: noise reduction
86 * - Sample rate: output frequency
89 /* Set accelerometer full-scale range. */
90 if (!imu.setAccelScale(ICM20948_Accel_FullScale::G_4)) {
91 Serial.println(F("setAccelScale failed."));
94 /* Enable DLPF (recommended)
95 * - bypass = false → DLPF enabled
97 if (!imu.setAccelDLPF(ACCEL_DLPFCFG_3, false)) {
98 Serial.println(F("setAccelDLPF failed."));
101 /* Set averaging (noise reduction). */
102 if (!imu.setAccelAveraging(ICM20948_Accel_Average::AVG_8)) {
103 Serial.println(F("setAccelAveraging failed."));
106 /* Set output data rate (ODR)
108 * - ODR = 1125 / (1 + divider)
111 if (!imu.setAccelSampleRate(225)) {
112 Serial.println(F("setAccelSampleRate failed."));
119 * @brief Read and print accelerometer data in g.
124 /* Read accelerometer data
125 * - Output in g units
126 * - Returns true on success
128 if (imu.readAccel(ax, ay, az)) {
129 Serial.print("ACCEL [g]: ");
134 Serial.println(az, 3);
136 Serial.println(F("ACCEL read failed"));
139 Serial.println(F("-----------------------------"));