MPU6050 - one axis reads wrong values?

Hello everyone,

I am reading the accelerometer values of all three axis from a MPU6050. My problem is that one axes reads only values very close to 0 after a few seconds, regardles of the orientation of the sensor.

Screenshot of the raw accelerometer output.

I am at a complete loss. Is the sensor toast? But why does it read "good" values at the beginning? This behaviour is completely repeatable. No sensor settings are changed during the loop section.

Please post the code, using code tags, and images in line according to this guide.

The accelerometer responds to the Earth's gravity in addition to the accelerations caused by other applied forces.

So, when the sensor is held still it will always report (+/-)1 g along an axis that is straight up or down, or the x,y,z components of g along all three axes, if in some other orientation. This can be used to test each axis function individually.

While creating a minimal working example I discovered my mistake. I had a memory leak:

main.cpp

void loop() {
  // ... 

  float * acc_data = new float[3];
  main_imu.readAcceleration(acc_data);
  // ...
}

MPU6050.cpp - readAcceleration:

void MPU6050::readAcceleration(float return_vals[]) {
  Wire.beginTransmission(MPU6050::i2c_address);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050::i2c_address, 6, true);  // request a total of 6 registers

  while(Wire.available() < 6);

  float x = Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  float y = Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  float z = Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)

  return_vals[0] = x;
  return_vals[1] = y;
  return_vals[2] = z;

  return_vals[0] /= acc_factor[1];
  return_vals[1] /= acc_factor[1];
  return_vals[2] /= acc_factor[1];
}

Making acc_data a global variable by moying the declaration before the setup() function resolved the issue.

With this solution working - is this the recommended way of retrieving multiple return values?