DevLab_ICM20948 1.0.0 Driver para sensor ICM-20948

Loading...
Searching...
No Matches
SPI_Basic.ino
Go to the documentation of this file.
1/***************************************************************
2 * @file SPI_Basic.ino
3 * @brief Minimal SPI bring-up for 7Semi ICM-20948 +
4 * basic Accel/Gyro/Temp readout (updated API).
5 *
6 * Features
7 * - SPI init (UNO / ESP32)
8 * - beginSPI() initialization
9 * - Manual sensor enable
10 * - Read Accel / Gyro / Temp
11 *
12 * Notes
13 * - WHO_AM_I must be 0xEA
14 * - Sensors must be explicitly enabled
15 * - SPI speed ~1MHz recommended during init
16 *
17 * Wiring (Arduino UNO SPI)
18 * - SCK -> D13
19 * - MOSI -> D11
20 * - MISO -> D12
21 * - CS -> D10 (changeable; update CS_PIN)
22 * - VCC -> 3V3
23 * - GND -> GND
24 *
25 * Wiring (ESP32 VSPI default)
26 * - SCK -> D13
27 * - MOSI -> D11
28 * - MISO -> D12
29 * - CS -> D10
30 ***************************************************************/
31#include <DevLab_ICM20948.h>
32
33#define SPI_FAST_SPEED 1000000
34
35/** IMU inst0ance */
36DevLab_ICM20948 imu;
37
38SPIClass spi_bus(SPI); // ← usa el bus SPI por defecto del Arduino
39
40void setup() {
41 Serial.begin(115200);
42 delay(200);
43
44
45 if (!imu.beginSPI(CS_PIN, spi_bus, 1000000)) {
46 Serial.println("ERROR: beginSPI() failed");
47 while (1) delay(200);
48 }
49
50 imu.setSensors(true, true, true);
51 Serial.println("Ready.");
52}
53
54void loop() {
55 float ax, ay, az;
56 float gx, gy, gz;
57 float tC;
58
59 /** Read Accelerometer */
60 if (imu.readAccel(ax, ay, az)) {
61 Serial.print(F("ACC [g]: "));
62 Serial.print(ax, 3); Serial.print(", ");
63 Serial.print(ay, 3); Serial.print(", ");
64 Serial.println(az, 3);
65 } else {
66 Serial.println(F("ACC read failed"));
67 }
68
69 /** Read Gyroscope */
70 if (imu.readGyro(gx, gy, gz)) {
71 Serial.print(F("GYR [dps]: "));
72 Serial.print(gx, 2); Serial.print(", ");
73 Serial.print(gy, 2); Serial.print(", ");
74 Serial.println(gz, 2);
75 } else {
76 Serial.println(F("GYR read failed"));
77 }
78
79 /** Read Temperature */
80 if (imu.readTemperature(tC)) {
81 Serial.print(F("TMP [C]: "));
82 Serial.println(tC, 2);
83 } else {
84 Serial.println(F("TMP read failed"));
85 }
86
87 Serial.println(F("-----------------------------"));
88 delay(500);
89}