Hello,
First of all, thank you !
I took a look into ur code (for I2C) u provided in a reply and put it together with another code.
ZeroValues > I did not take these values from the datasheet, I just ran a script with raw values and took the average values when the sensor was lying on the floor.
GyroSensitivity > I actually dont know which one I should take from the datasheet, but Ive tried everyone (there are 4 levels).
These are the values I get when the sensor is lying on the floor
343.26 136.31
344.40 126.77
345.49 117.89
346.50 109.65
347.41 101.99
348.27 94.83
349.07 113.36
349.82 105.43
350.48 98.05
351.12 91.18
351.71 84.80
352.27 104.04
352.78 96.76
353.25 89.98
353.69 83.68
354.12 77.82
354.51 72.36
354.87 67.28
355.23 87.76
330.36 106.78
332.41 99.32
334.33 92.38
336.12 85.92
337.78 79.92
339.31 74.32
340.73 69.13
342.06 64.28
343.30 59.78
344.46 55.58
345.50 76.87
346.49 96.67
322.25 115.07
324.85 107.02
327.25 124.71
329.51 115.98
331.62 107.86
333.54 100.32
And here is the code
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
bool blinkState = false;
unsigned long timer;
double zeroValue[5] = {950, -400, 13500, -100, -500};
/* All the angles start at 180 degrees */
double gyroXangle = 180;
double gyroYangle = 180;
double compAngleX = 180;
double compAngleY = 180;
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
Serial.begin(115200);
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
timer = micros();
}
void loop() {
// read raw accel/gyro measurements from device
//accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
accelgyro.getRotation(&gx, &gy, &gz);
double gyroXrate = -((gx-zeroValue[3])/131); //Change the sensitivity after your sensor
gyroXangle += gyroXrate*((double)(micros()-timer)/1000000); // Without any filter
double gyroYrate = ((gy-zeroValue[4])/131);
gyroYangle += gyroYrate*((double)(micros()-timer)/1000000); // Without any filter
///////////////////////////
//The acc X and Y angle///
//////////////////////////
accelgyro.getAcceleration(&ax, &ay, &az);
double accXval = ax-zeroValue[0];
double accZval = ay-zeroValue[2];
double accXangle = (atan2(accXval,accZval)+PI)*RAD_TO_DEG;
double accYval = ay-zeroValue[1];
accZval = ay-zeroValue[2];
double accYangle = (atan2(accYval,accZval)+PI)*RAD_TO_DEG;
//////////////////////////
//////////////////////////
compAngleX = (0.93*(compAngleX+(gyroXrate*(double)(micros()-timer)/1000000)))+(0.07*accXangle);
compAngleY = (0.93*(compAngleY+(gyroYrate*(double)(micros()-timer)/1000000)))+(0.07*accYangle);
timer = micros();
Serial.print(compAngleX);Serial.print("\t");
Serial.print(compAngleY); Serial.print("\t");
//Serial.print(timer); Serial.print("\t");
Serial.print("\n");
delay(10);
}
Edit:
Im using a sensor called MPU6050.
Datasheet can be found here:
When I move it like one mm to another direction it seems to be stable, I guess there is a point where everything gets screwd up..
2.51 1.53
2.49 1.50
2.48 1.49
2.48 1.49
2.47 1.49
2.47 1.48
2.46 1.46
2.47 1.44
2.49 1.41
2.51 1.37
2.52 1.38
2.54 1.38
2.51 1.38
2.51 1.39
2.50 1.41
2.48 1.40
2.46 1.38
2.48 1.39
2.49 1.38
2.51 1.39
2.50 1.38
2.51 1.39
2.50 1.40
2.49 1.39
2.50 1.40
2.49 1.42
2.46 1.43
2.45 1.41
2.44 1.41
2.47 1.40
2.44 1.42
2.46 1.43
2.47 1.46
2.44 1.45
2.44 1.46