How to perform MPU6050 Accelerometer Temperature Calibration?

Esteban Carnuccio picture Esteban Carnuccio · Jun 23, 2017 · Viewed 7.2k times · Source

I'm doing a project with the MPU6050 accelerometer. First I calculate the offsets of the MPU only once executing the sketch of Luis Ródenas.

Later, once I get the offsets, I copy them into the configuration of a second sketch and I always execute it with the same values.

//Placa casa MPU6050 viejo
//-1172  -873  1351  76  -758  27
accelgyro.setXAccelOffset(-1172);
accelgyro.setYAccelOffset(-873);
accelgyro.setZAccelOffset(1351);
accelgyro.setXGyroOffset(76);
accelgyro.setYGyroOffset(-773);
accelgyro.setZGyroOffset(33);

The problem I have is that after a time of having executed the second sketch several times, the raw readings present a new offset.

I read that this problem can be by the temperature of the sensor, that it is necessary to compensate the readings with the temperature. But I can not find an example to do so. I wanted to ask if anyone knows what the problem might be and how I can fix it.

Answer

ikleschenkov picture ikleschenkov · Jul 18, 2017

I see two ways to deal with MPU6050 temperature drift:

  1. Calibrate it before each start: put calibration code into you setup(), so you will get the valid offset parameters on each device start, no matter, what is the temperature of device. This method is used in multirotor flight controller to calibrate its IMU, which is often based on MPU60x0.

  1. Prepare a table of calibration values. MPU6050 has embedded temperature sensor, which can be used for this approach.

Write sketch which do:

  1. read T (temperature). example sketch how to read T from MPU6050
  2. measure the offsets as you do now and print into Serial with current T.
  3. wait until T changes, if it took too long (30+ sec for example), stop calibration, otherwise go to 2.

Now cool down the MPU6050 in the freezer, and then put it into hot environment (50degC should be enough; depends on which T range the final device will be used) and start calibration sketch.

Now, having a table [T]->[offsets] your can adjust original sketch to monitor the T of MPU6050 and once it changes, assign the corresponding offsets to MPU6050.