# MPU6050 showing inconsistent angle values

I'm using this Arduino code to calibrate and read from an MPU6050 accel/gyro sensor from an Arduino Mega.

The calibration and reading of values seemed to go well. However, I'm seeing some inconsistent values reported from the gyroscope. When my apparatus is placed flat, it correctly read a pitch of 0 degrees. When I tilt it forward by 90 degrees, it reads a fairly accurate -89.6 degrees. However, when I tilt it backward at -90 degrees...it reads -26 degrees.

Why is this? Could this be caused by mis-calibration, interference, or is it possible my MPU6050 is damaged or defective?

The default orientation of the board is with it flat, so the z-axis points "up". However, I've mounted the sensor with the y-axis pointing "up" and the z-axis points forward/backward. Would this effect calibration? Other than having to remap, my axis when reading data (which I'm doing), I haven't read any warnings about needing to explicitly enter this re-orientation into the MPU6050 code.

• Idk but that link doesn't open for me. How do concert the readings to angle? May be your issue lies there? – MaNyYaCk Mar 27 '18 at 15:32
• You seem to incorrectly refer to the "gyroscope" when discussing angles determined by inverse trig functions from the accelerometers. While the chip also contains three rate gyros, these gives you angular rates, not angles. – Chris Stratton Mar 27 '18 at 18:28
• @ChrisStratton Noted. – Cerin Mar 27 '18 at 19:26

Turns out that calibration requires the sensor to be in the default "z-up" position, and that even if you adjust the trig functions later, the values will still be off if you use a different orientation. I tried removing the MPU6050 from my apparatus, placing it flat, and re-running the calibration. That improved the values, but the ranges still weren't aligning correctly with my custom orientation, so I added this function to flip the X and Z axis based on the code provided in this comment:

uint8_t MPU6050::dmpGetYawPitchRollOnEnd(float *data, Quaternion *q, VectorFloat *gravity) {