GY-521 Showing Odd Values when not moving

Hi There,

I have a GY-521 connected to a Uno R3 and I have it sitting on my desk not moving at all. When looking at the values being sent over, they seem very odd.

I would imagine the accelerometer and gyro's should be closer to 0 and not move so much?

Serial Output
aX = -2316 | aY = 280 | aZ = 17712 | tmp = 42.65 | gX = -72 | gY = 150 | gZ = 52
aX = -2360 | aY = 288 | aZ = 17720 | tmp = 42.60 | gX = -110 | gY = 137 | gZ = 67
aX = -2272 | aY = 240 | aZ = 17856 | tmp = 42.65 | gX = -99 | gY = 148 | gZ = 95
aX = -2236 | aY = 288 | aZ = 17784 | tmp = 42.41 | gX = -69 | gY = 141 | gZ = 77
aX = -2300 | aY = -32 | aZ = 17464 | tmp = 42.74 | gX = -122 | gY = 183 | gZ = 53
aX = -2248 | aY = 336 | aZ = 17816 | tmp = 42.65 | gX = -98 | gY = 128 | gZ = 57
aX = -2356 | aY = 340 | aZ = 17700 | tmp = 42.65 | gX = -71 | gY = 162 | gZ = 65
aX = -2312 | aY = 352 | aZ = 17808 | tmp = 42.46 | gX = -71 | gY = 131 | gZ = 89
aX = -2284 | aY = 276 | aZ = 17808 | tmp = 42.46 | gX = -26 | gY = 109 | gZ = 59
aX = -2392 | aY = 324 | aZ = 17808 | tmp = 42.60 | gX = -70 | gY = 123 | gZ = 33
aX = -2292 | aY = 260 | aZ = 17780 | tmp = 42.51 | gX = -121 | gY = 139 | gZ = 42
aX = -2248 | aY = 328 | aZ = 17880 | tmp = 42.65 | gX = -79 | gY = 168 | gZ = 87
aX = -2300 | aY = 316 | aZ = 17752 | tmp = 42.60 | gX = -103 | gY = 146 | gZ = 43

// (c) Michael Schoeffler 2017, http://www.mschoeffler.de 

#include "Wire.h" // This library allows you to communicate with I2C devices.

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.

int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data

char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
  sprintf(tmp_str, "%6d", i);
  return tmp_str;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
  Wire.write(0x6B); // PWR_MGMT_1 register
  Wire.write(0); // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}
void loop() {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
  Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
  Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers
  
  // "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
  accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
  accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
  accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
  temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
  gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
  gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
  gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)
  
  // print out data
  Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
  Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
  Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
  // the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]
  Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
  Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
  Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
  Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
  Serial.println();
  
  // delay
  delay(1000);
}

I found out that it needs to be calibrated...Using this library I'm getting "MPU6050 connection failed". It connects fine with the script above and the address is right. So I have some more work to do.

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