I am working on a project which needs to read the direction constantly,
I am using MPU6050 sensor's yaw value for it,
I tried using a magnetometer but it was not working as expected, I am also limited by time.
Here's the code:
/* Get tilt angles on X and Y, and rotation angle on Z
* Angles are given in degrees
*
* License: MIT
*/
#include "Wire.h"
#include <MPU6050_light.h>
MPU6050 mpu(Wire);
unsigned long timer = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
Serial.println("Done!\n");
}
void loop() {
mpu.update();
if((millis()-timer)>10){ // print data every 10ms
Serial.print("\tZ : ");
Serial.println(mpu.getAngleZ());
timer = millis();
}
}
It is an example from the library:
MPU6050_light-master.zip (194.1 KB)
And here's an example of the drift:
GyroDrift.txt (450 Bytes)
I have pasted the data into a text file as it is too large
I know it doesn't look like much but it happened in less than a minute
Please help me fix this drift, I am very close to completing this project.
Thank you,
Helio phoebus