TinyMPU6050.h. How long should calibration call take?

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 :slight_smile:

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.

Take a look at this page

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

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.

The TinyMPU6050 library has some ugly code, and is best avoided.

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

 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.

This may be worth reading if you are still interested:

Hi everybody.

I feel so sorry about the previous releases of TinyMPU6050. I've just released v0.5.0 that shall soon be available at the Arduino Library Manager index.

The calibration method indeed was messy, so I decided to keep it simple. I also removed dependencies of String objects and Serial stuff and it seems to work pretty fine now.

If you keep having issues with that, please let me know!

The official link to release 0.5.0 follows:

Much improved, but one of these two equations is wrong.

	// Computing accel angles
	angAccX = wrap((atan2(accY, sqrt(accZ * accZ + accX * accX))) * RAD_TO_DEG);
	angAccY = wrap((-atan2(accX, sqrt(accZ * accZ + accY * accY))) * RAD_TO_DEG);

You are not using a definition for Euler angles that corresponds to any of the recognized systems. The order in which you apply rotations matters!

Neither of the two correct definitions will correspond to your treatment of the gyro terms, so I don't think the angles that are output are particularly meaningful. Everyone uses quaternion-based systems these days.