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 | 44 |
11 |
Object Pascal App getting data from ESP32-S3 (Parsing)
![]() | me | 2025.04.29 | 43 |
10 |
Sound Sensor Test
![]() | me | 2025.04.27 | 41 |
9 |
Laser distance sensor VL53L0X
![]() | me | 2025.04.27 | 37 |
» |
9DOF : Getting Pitch & Roll with ICM20948 v2
![]() | me | 2025.04.27 | 40 |
7 |
Formating output
![]() | me | 2025.04.27 | 34 |
6 | Blinking Built-in RGB without delay() | me | 2025.04.25 | 39 |
5 | Built-in RGB led Demo | me | 2025.04.25 | 41 |
4 | Servo Demo | me | 2025.04.25 | 40 |
3 |
HMC5883L Compass demo
![]() | me | 2025.04.25 | 39 |
2 |
I2C Address Search
![]() | me | 2025.04.25 | 37 |
1 | Serial Sample (ASCII Table) | me | 2025.04.25 | 39 |