Hi, i know this is a very old thread but i just wanted to share my code that can auto calibrate the Gyroscope and Accelerometer of MPU6050. The code is increment based and after calibration all the values comes down to zero or close to it. I want to share this code so others can also test it and improve it. One of the things i haven't done is in z axis of accelerometer i haven't used +16384 offset. Calibration can be more fine tuned but the cost of doing it would be time. It will take more time to calibrate it closer to zero. Fining tuning is discussed in comments in code. I also noticed that the DMP takes 20secs(approx) to stabilize. So if you are using Yaw pitch Roll output then values of first 20 seconds are useless. Another problem is that this code sometimes work other times it fails. So do check. anyway here are the before and after calibration graph.
This sketch output raw data (Time(in miliseconds) AX Ay Az Gx Gy Gz)
https://www.dropbox.com/s/t0u4sv3nkoplnoz/MPU6050_auto_calibrationl_raw_data_output.ino.ino?dl=0
This sketch uses DMP and Output data in YAw pitch Roll or other formats. waits 20 seconds for stability before giving data. https://www.dropbox.com/s/hh2750l8x115eib/MPU6050_auto_calibration_output_yaw_pitch_roll.ino?dl=0