Hi,
I think you cannot call the function readBytes() from an ISR, at least you shouldnt. The reason for this is because that function includes I2C communications, that take some time and also may conflict with ISR manager for reasons I don't really know.
Just use the timer interrupt to change the value of a flag, and then check that flag from main code and execute the readbytes().
What I do to get calibration values using Arduino is the following:
- Put the MPU6050 in a flat and horizontal surface. Use an inclinometer to check that it is as horizontal as possible.
- Modify the RAW program to put every offset to 0. ("setXGyroOffset/setYGyroOffset/setZGyroOffset/setZAccelOffset" =0 ).
- Upload the RAW program to your arduino and open serial monitor so you can see the values it is returning.
- Leave it operating for a few minutes (5-10) so temperature gets stabilized.
- Check the values in the serial monitor and write them down.
- Now modify your program again updating your offsets and run the sketch, with updated offsets.
- Repeat this process until your program is returning 0 for every gyro, 0 for X and Y accel, and +16384 for Z accel.
Once you achieve this, those are the offsets for that MPU6050, you will have to repeat this for every MPU6050 you use.
*NOTES:
- If you stop the sketch for a while, sensor's temperature will get lower. If you only stop it to reprogram new offsets, you dont need to wait those 5-10 minutes every time.
- What you should try to achieve is to get the average of every gyro and XY accel to those values mentioned, so it is best if you modify the sketch to take, for example, 10000 measures, and just show on the serial monitor the average, because there is always some noise.
- It is not so straigthforward to update your offset every time. In my case, I had to put my initial readings, negated (change sign) and divided by 4 (gyros) and by 7.8 (accels).