Calibration#

IMU_Zero#

Before running any of the measurement programs, with the MPU6050 showing acceleration in any direction first run IMU_Zero.ino, this is a calibration program and requires the unit to be placed on a level surface for 10 to 15 minutes. As long as the gravity is 1g then it should calibrate. The offsets are printed, these should be saved as they will be used in later scripts. If you happen to have more than one module then each will need its own calibration and identification.

The address is normally 0x68 and this is explained in the sketch.

Show/Hide Code IMU_Zero.txt

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
PID tuning Each Dot = 100 readings
>......>......
at 600 Readings

//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     1334,   -2406,    1656,     -76,      70,      62

>.>.700 Total Readings

//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     1334,   -2408,    1656,     -77,      69,      63

>.>.800 Total Readings

//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     1334,   -2408,    1656,     -76,      69,      62

>.>.900 Total Readings

//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     1334,   -2408,    1656,     -77,      71,      62

>.>.1000 Total Readings

//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     1332,   -2408,    1656,     -76,      70,      62


 Any of the above offsets will work nice 

 Lets proof the PID tuning using another method:
averaging 1000 readings each time
expanding:
....	XAccel			YAccel				ZAccel			XGyro			YGyro			ZGyro
 [0,0] --> [-11002,-11003]	[0,0] --> [21061,21061]	[0,0] --> [2507,2508]	[0,0] --> [307,307]	[0,0] --> [-277,-279]	[0,0] --> [-247,-247]
.... [0,1000] --> [-11000,-2755]	[-1000,0] --> [12310,21062]	[0,1000] --> [2505,10879]	[-1000,0] --> [-3690,306]	[0,1000] --> [-278,3718]	[0,1000] --> [-248,3747]
.... [0,2000] --> [-11001,5493]	[-2000,0] --> [3559,21053]	[0,2000] --> [2506,19246]	[-1000,0] --> [-3690,308]	[0,1000] --> [-275,3720]	[0,1000] --> [-245,3746]
.... [0,2000] --> [-10997,5501]	[-3000,0] --> [-5193,21058]	[0,2000] --> [2500,19252]	[-1000,0] --> [-3690,305]	[0,1000] --> [-273,3720]	[0,1000] --> [-244,3747]

closing in:
..	XAccel			YAccel				ZAccel			XGyro			YGyro			ZGyro
 [1000,2000] --> [-2751,5501]	[-3000,-1500] --> [-5193,7932]	[1000,2000] --> [10878,19252]	[-500,0] --> [-1691,305]	[0,500] --> [-273,1725]	[0,500] --> [-244,1753]
.. [1000,1500] --> [-2751,1376]	[-3000,-2250] --> [-5193,1369]	[1500,2000] --> [15059,19252]	[-250,0] --> [-693,305]	[0,250] --> [-273,725]	[0,250] --> [-244,753]
.. [1250,1500] --> [-685,1376]	[-2625,-2250] --> [-1919,1369]	[1500,1750] --> [15059,17154]	[-125,0] --> [-193,305]	[0,125] --> [-273,224]	[0,125] --> [-244,252]
.. [1250,1375] --> [-685,334]	[-2437,-2250] --> [-276,1369]	[1625,1750] --> [16101,17154]	[-125,-62] --> [-193,59]	[62,125] --> [-28,224]	[62,125] --> [0,252]
.. [1312,1375] --> [-179,334]	[-2437,-2343] --> [-276,546]	[1625,1687] --> [16101,16623]	[-93,-62] --> [-64,59]	[62,93] --> [-28,94]	[62,93] --> [0,123]
..	XAccel			YAccel				ZAccel			XGyro			YGyro			ZGyro
 [1312,1343] --> [-179,70]	[-2437,-2390] --> [-276,146]	[1656,1687] --> [16371,16623]	[-77,-62] --> [0,59]	[62,77] --> [-28,31]	[62,77] --> [0,60]
.. [1327,1343] --> [-62,70]	[-2413,-2390] --> [-64,146]	[1656,1671] --> [16371,16484]	[-77,-69] --> [0,30]	[69,77] --> [0,31]	[62,69] --> [0,28]
.. [1327,1335] --> [-62,6]	[-2413,-2401] --> [-64,41]	[1656,1663] --> [16371,16419]	[-77,-73] --> [0,14]	[69,73] --> [0,15]	[62,65] --> [0,12]
.. [1331,1335] --> [-26,6]	[-2407,-2401] --> [-8,41]	[1659,1663] --> [16383,16419]	[-77,-75] --> [0,7]	[69,71] --> [0,7]	[62,63] --> [0,4]
.. [1333,1335] --> [-9,6]	[-2407,-2404] --> [-8,21]	[1659,1661] --> [16383,16397]	[-77,-76] --> [0,2]	[69,70] --> [0,2]	[62,63] --> [0,4]
averaging 10000 readings each time
....................	XAccel			YAccel				ZAccel			XGyro			YGyro			ZGyro
 [1333,1334] --> [-9,6]	[-2407,-2405] --> [-8,5]	[1659,1660] --> [16383,16398]	[-77,-76] --> [-1,2]	[69,70] --> [0,2]	[62,63] --> [0,4]
.................... [1333,1334] --> [-9,6]	[-2407,-2406] --> [-8,5]	[1659,1660] --> [16379,16398]	[-77,-76] --> [-1,2]	[69,70] --> [0,2]	[62,62] --> [0,1]
.................... [1333,1334] --> [-9,6]	[-2407,-2406] --> [-10,5]	[1659,1660] --> [16378,16398]	[-77,-76] --> [-1,2]	[69,70] --> [0,2]	[62,62] --> [0,1]
-------------- done --------------

So the offsets I should use is for example 1334 for XAccel, the bracketed value following [1333,1334] is a confidence limit.

Raw MPU6050 Data#

Now look at MPU6050_raw.ino, this will give us

  • XAccel

  • YAccel

  • ZAccel

  • XGyro

  • YGyro

  • ZGyro

The accelerometer is set to ±2g, the raw 16 bit register gives 65536 (2**16) therefore to obtain the readings in g divide 65536 by 4 to obtain 16384. The gyroscope is set to ±250°/sec, so to obtain the actual change in degrees per second divide 65536 by 500 gives 131.07, round this figure 131 and divide the raw values to give the gyroscope readings.

Each will have its own offset, an example has been shown in the original script, run it as it is and check the output, before changing. He has a choice of human readable output, or binary, as we are working with the serial monitor choose human readable. Don't get caught out by the change in baud rate, he's using 38400. You should see something like the following output if the module is left standing:

Testing device connections...
MPU6050 connection successful
a/g:        1552    48      15776   1207    22      -591
a/g:        1568    4       15960   1200    2       -599
a/g:        1624    -8      15656   1179    13      -607
a/g:        1540    -48     15712   1193    30      -567
a/g:        1516    20      15816   1181    17      -583
a/g:        1444    -28     15684   1185    24      -597
a/g:        1604    24      15784   1168    27      -579
a/g:        1524    -20     15832   1188    5       -578

Considering that my unit needed the following offsets

1334 -2407 1659 -77 69 62

Not too bad, uncomment updating the offsets and put in your values, once again leave the module standing and check the results:

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Updating internal sensor offsets...
       1520  -2407       1582    0   0      0
       1334  -2407       1659  -77  69     62
a/g:     56     48      16384    4 -15    117
a/g:    -16      0      16516   16   5     20
a/g:    -76     68      16364   -2 -51     12
a/g:     68     64      16472   -4 -40    -12
a/g:    -28     52      16348  -22 -29     -7
a/g:    -60    -44      16388   -6  -3     10
a/g:    -76     20      16356   -9   6    -20
a/g:    -96    -20      16504   -6   8     37

You should see something similar with your results, remember that the values should all be around 0 apart from the ZAccel which should be about 16384.

Having sorted out the offsets, the raw data is no longer so interesting.