1/***************************************************************
3 * @brief Minimal I2C bring-up for 7Semi ICM-20948 +
4 * basic Accel/Gyro/Temp/Mag readout (updated API).
7 * - I2C init (UNO / ESP32)
8 * - beginI2C() initialization
9 * - Manual sensor enable (setSensors)
10 * - Read Accel / Gyro / Temp / Mag
13 * - WHO_AM_I must be 0xEA
14 * - Sensors must be explicitly enabled
15 * - Magnetometer requires initMag()
17 * Wiring (Arduino UNO I2C)
20 * - VCC -> 3V3 (or 5V if supported)
23 * Wiring (ESP32 default I2C)
26 ***************************************************************/
28#include <DevLab_ICM20948.h>
30/* ====================== User Config ======================= */
31/** @brief I2C SDA pin used by the example board. */
33/** @brief I2C SCL pin used by the example board. */
35/** @brief I2C bus speed in hertz. */
36#define I2C_FREQ 400000UL
37/** @brief ICM-20948 I2C address selected by the AD0 pin. */
40/** @brief Global ICM-20948 driver instance. */
44 * @brief Configure Serial, I2C, sensor identity check, and enabled sensors.
46 * The sketch stops in an infinite loop if the IMU cannot be initialized or
47 * the WHO_AM_I register does not match the expected ICM-20948 value.
52 Serial.println(F("ICM-20948 — I2C Basic"));
53 Wire.begin(SDA_PIN, SCL_PIN);
55 if (!imu.beginI2C(ICM_ADDR, Wire, 400000)) {
56 Serial.println(F("ERROR: beginI2C() failed"));
62 if (!imu.readWhoAmI(who) || who != 0xEA) {
63 Serial.println(F("ERROR: WHO_AM_I mismatch"));
67 Serial.print(F("WHO_AM_I = 0x"));
68 Serial.println(who, HEX);
70 /* Enable all sensors. */
71 if (!imu.setSensors(true, true, true)) {
72 Serial.println(F("ERROR: setSensors failed"));
75 /* Initialize magnetometer. */
77 Serial.println(F("Mag init failed"));
79 Serial.println(F("Mag initialized"));
82 Serial.println(F("Ready.\n"));
86 * @brief Read accelerometer, gyroscope, magnetometer, and temperature data.
88 * Values are printed periodically to the Serial monitor in engineering units.
96 /* Read accelerometer. */
97 if (imu.readAccel(ax, ay, az)) {
98 Serial.print(F("ACC [g]: "));
99 Serial.print(ax, 3); Serial.print(", ");
100 Serial.print(ay, 3); Serial.print(", ");
101 Serial.println(az, 3);
103 Serial.println(F("ACC read failed"));
106 /* Read gyroscope. */
107 if (imu.readGyro(gx, gy, gz)) {
108 Serial.print(F("GYR [dps]: "));
109 Serial.print(gx, 2); Serial.print(", ");
110 Serial.print(gy, 2); Serial.print(", ");
111 Serial.println(gz, 2);
113 Serial.println(F("GYR read failed"));
116 /* Read magnetometer. */
117 if (imu.readMag(mx, my, mz)) {
118 Serial.print(F("MAG [uT]: "));
119 Serial.print(mx, 2); Serial.print(", ");
120 Serial.print(my, 2); Serial.print(", ");
121 Serial.println(mz, 2);
123 Serial.println(F("MAG read failed"));
126 /* Read temperature. */
127 if (imu.readTemperature(tC)) {
128 Serial.print(F("TMP [C]: "));
129 Serial.println(tC, 2);
131 Serial.println(F("TMP read failed"));
134 Serial.println(F("-----------------------------"));
138/* Note on magnetometer:
139 * - Uses internal I2C master (AK09916 via ICM20948)
140 * - initMag() must be called before readMag()
141 * - If values are zero:
143 * → verify power + pull-ups