Hi guys, I have a hard problem with my gyroscope/accelerometer GY-521 (MPU6050) sensor.
The sensor working good, I tested it and it’s working without problems… BUT…
I notice that the raw gyroscope values are strange… seems that the gyroscope can’t understand correctly the angle inclination of my robot…
when my robot is stopped I change his X and Y rotation angle and I notice that the accelerometer can provide me good values (thx to the minimum 1g of the earth);
these values show a correct angle inclination but you know, if I rotate using more force so my accelerometer give me highest value due to the major acceleration so I need a gyroscope to know the angle rotation of my robot X and Y axys!!! not?
But, as I wrote above, my Gyro giving me strange values… I change the angle of the X and Y axys of my robot and I notice that the gyro values going high when I making this rotation and back to small values when I finish to apply the rotation… like an accelerometer… but without the precision of my accelerometer… indeed after I made this rotation I got values similar to the values I obtained before to start the rotation…
So… exist some way to get some math to find the degrees of my robot X and Y axys?
Here my code:
#include<Wire.h>
const int MPU=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
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);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,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)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
I would to tell you that the LED on the sensor is red… in all video I watched I see a green led… :
Please help me!..