Go Down

Topic: TinyMPU6050.h. How long should calibration call take? (Read 141 times) previous topic - next topic


When I include the call for calibration it never seems to complete. Waited for at least 15 minutes.

Example code is here...


...by the way, if I skip this call, the rest of the example works fine :)


I only took a brief look into the code involved, but it seems like it is waiting for some 'convergence' of the measurements in the calibrate function.

I'd look in to that and set a hard limit on the number times it runs the calibration loop and spit out a very values to see what's going on.


Aug 26, 2019, 08:41 pm Last Edit: Aug 26, 2019, 08:43 pm by ScrewLoose
Take a look at this page


Line 202 goes into a potentially infinite loop lines 281 to 285 are the only way out

Code: [Select]

if (loopCount >= DEADZONE_ATTEMPTS) break;

Check all your variables, throw in a few serial.println to see how far you are progressing and pay close attention to deadzone attempts.


Aug 26, 2019, 09:17 pm Last Edit: Aug 27, 2019, 04:39 am by jremington
The TinyMPU6050 library has some ugly code, and is best avoided.

For example: use of totally unnecessary, program-crashing String objects, Serial.print(), etc.

Code: [Select]

 String notConverged = "";

 // Checking if readings are on the deadzone and, eventually, fixing preOffsets
 if (abs(sumAccX) <= accelDeadzoneThreshold) ready++;
 else {
 preOffAccX = preOffAccX - sumAccX / accelDeadzoneThreshold;


Serial.print (" loops / ");
Serial.print (ready);
Serial.print (" axis calibrated. Missing: ");
Serial.println (notConverged);

The "dead zone" concept is a misguided attempt to fix some other problem and is likely the cause of failure.

For calibrating the gyro, just sum up a few hundred readings while the sensor is stationary, calculate the average offset and subtract the offsets from later readings.

For calibrating the accelerometer, follow this general approach (change the details as necessary for the MPU6050). You need to do this only once, and never again.


Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Go Up