Help with GY-521 Module

I have purchased a GY-521 module, and I was hoping to make a plane that gives me constant readings about the angle of the plane. But when I was testing this accelerometer, I was only getting a spike when I quickly moved the gyroscope to one side, and the numbers quickly went back down even while I was not moving the gyroscope. I want readings that will stay remain consistent if the gyroscope is not moving. Am I doing something wrong? Thanks!

Here is my code:

#include<Wire.h>
const int MPU=0x68; 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B); 
  Wire.write(0);    
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,12,true);  
  AcX=Wire.read()<<8|Wire.read();    
  AcY=Wire.read()<<8|Wire.read();  
  AcZ=Wire.read()<<8|Wire.read();  
  GyX=Wire.read()<<8|Wire.read();  
  GyY=Wire.read()<<8|Wire.read();  
  GyZ=Wire.read()<<8|Wire.read();  
  
  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = "); Serial.println(AcZ); 
  
  Serial.print("Gyroscope: ");
  Serial.print("X = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");
  delay(333);
}

The rate gyro drifts, depending on the temperature and other factors. To cancel the drift you need to determine the rate gyro offsets and subtract them from subsequent readings.

How would I go about doing that?

Most people add up a few hundred readings from each axis and average them. Google "rate gyro calibration" for more ideas.

Ok, thanks!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.