Hi!
I am using a GY-521 MPU6050 with arduino uno. I am using the sketch below (it was from Johnchi, but I slightly modified it)
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
float FX ;
float FY ;
float FZ ;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
// Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
FX = AcX/16384;
FY = AcY/16384;
FZ = AcZ/16384;
Serial.print("AcX = "); Serial.print(AcX/16384.0);
Serial.print(" | AcY = "); Serial.print(AcY/16384.0);
Serial.print(" | AcZ = "); Serial.print(AcZ/16384.0);
// Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX/131.0);
Serial.print(" | GyY = "); Serial.print(GyY/131.0);
Serial.print(" | GyZ = "); Serial.println(GyZ/131.0);
delay(10);
}
when I put the sensor on table horizontally and statically, in serial monitor, I can see the outputs like the attached picture
gyro has those values, even it is not moving or rotating or vibrating
(but when I rotate the sensor, gyro readings seem right)
z axis g force is only about 0.94, with any attitude (not moving)
x axis g force shows about 1.05 when x is vertical
I guess something is wrong with the code or the sensor?
How can I fix it?
Thank you!