Code: Select all
#include
#include
#include "I2Cdev.h"
MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize(); // Initialize the sensor
if (!mpu.testConnection()) {
Serial.println("MPU6050 connection failed");
while (1); // Halt if connection fails
}
Serial.println("MPU6050 connection successful");
}
void loop() {
// Read normalized accelerometer data
Vector normAccel = mpu.readNormalizeAccel();
// Calculate pitch and roll
float pitch_rad = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis * normAccel.YAxis + normAccel.ZAxis * normAccel.ZAxis))) +0.01745;
float roll_rad = (atan2(normAccel.YAxis, normAccel.ZAxis)) + 1.5708;
int pitch = pitch_rad * 180.0 / M_PI;
int roll = roll_rad * 180.0 / M_PI;
Serial.print(" Pitch: ");
Serial.print(pitch);
Serial.print(" Roll: ");
Serial.println(roll);
}
Code: Select all
error: 'normAccel' was not declared in this scope
float pitch_rad = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis * normAccel.YAxis + normAccel.ZAxis * normAccel.ZAxis))) +0.01745;
^~~~~~~~~
exit status 1
Compilation error: 'Vector' was not declared in this scope
Vielen Dank