
9DOF : Getting Pitch & Roll with ICM20948 v2
2025.04.27 20:17
// Example #7 sketch for the ICM20948_WE library
#include <Wire.h>
#include <ICM20948_WE.h>
#define ICM20948_ADDR 0x68
char s[100]; // for formatted output using sprintf
ICM20948_WE myIMU = ICM20948_WE(ICM20948_ADDR);
void setup() {
//delay(2000); // maybe needed for some MCUs, in particular for startup after power off
Wire.begin(4,5);
Serial.begin(115200);
while(!Serial) {}
if(!myIMU.init()){
Serial.println("ICM20948 does not respond");
}
else{
Serial.println("ICM20948 is connected");
}
//myIMU.setAccOffsets(-16330.0, 16450.0, -16600.0, 16180.0, -16520.0, 16690.0);
Serial.println("Position your ICM20948 flat and don't move it - calibrating...");
delay(1000);
myIMU.autoOffsets();
Serial.println("Done!");
/* enables or disables the acceleration sensor, default: enabled */
// myIMU.enableAcc(true);
myIMU.setAccRange(ICM20948_ACC_RANGE_2G);
myIMU.setAccDLPF(ICM20948_DLPF_6);
//myIMU.setAccSampleRateDivider(10);
}
void loop() {
xyzFloat gValue;
xyzFloat angle;
myIMU.readSensor();
myIMU.getGValues(&gValue);
myIMU.getAngles(&angle);
float pitch = myIMU.getPitch();
float roll = myIMU.getRoll();
sprintf(s, "<M-GAPR:%6.3f, %6.3f, %6.3f, %7.2f, %7.2f, %7.2f, %5.1f, %5.1f>",
gValue.x, gValue.y, gValue.z,
angle.x, angle.y, angle.z,
pitch, roll);
Serial.println(s);
delay(100);
}

Comment 0
| No. | Subject | Author | Date | Views |
|---|---|---|---|---|
| Notice | For the first time user of ESP32-S3 super mini users. | me | 2025.04.25 | 823 |
| 16 | Other Approach proposed by Gemini | me | 2025.10.02 | 101 |
| 15 | Data Route | me | 2025.10.02 | 106 |
| 14 |
Extra Hardware Serial + JSON servo control
| me | 2025.09.22 | 142 |
| 13 |
Wheel Arc movement with continous servos
| me | 2025.09.21 | 158 |
| 12 |
3 Servo Test
| me | 2025.09.21 | 134 |
| 11 |
Object Pascal App getting data from ESP32-S3 (Parsing)
| me | 2025.04.29 | 594 |
| 10 |
Sound Sensor Test
| me | 2025.04.27 | 606 |
| 9 |
Laser distance sensor VL53L0X
| me | 2025.04.27 | 628 |
| » |
9DOF : Getting Pitch & Roll with ICM20948 v2
| me | 2025.04.27 | 611 |
| 7 |
Formating output
| me | 2025.04.27 | 593 |
| 6 | Blinking Built-in RGB without delay() | me | 2025.04.25 | 3889 |
| 5 | Built-in RGB led Demo | me | 2025.04.25 | 689 |
| 4 | Servo Demo | me | 2025.04.25 | 587 |
| 3 |
HMC5883L Compass demo
| me | 2025.04.25 | 653 |
| 2 |
I2C Address Search
| me | 2025.04.25 | 647 |
| 1 |
Serial Sample (ASCII Table)
| me | 2025.04.25 | 675 |