2

I recently got an MPU6050 and I noticed the accelerometer data was a bit off, especially on the Z axis.

I'm running it on a Teensy 4.0 with Adafruit's MPU6050 library and basic example code: https://github.com/adafruit/Adafruit_MPU6050/blob/master/examples/basic_readings/basic_readings.ino

While stable on a flat surface (+Z up), it's reading ~8.5 m/s^2 and when flipped over (-Z up), ~11.6 m/s^2:

+Z:
Acceleration X: -0.06, Y: 0.00, Z: 8.44 m/s^2
-Z:
Acceleration X: -0.01, Y: -0.07, Z: -11.57 m/s^2

Aligning the other axes vertically gives me:

+X:
Acceleration X: 10.16, Y: -0.16, Z: -0.03 m/s^2
-X:
Acceleration X: -9.27, Y: -0.10, Z: -0.18 m/s^2
+Y:
Acceleration X: 0.07, Y: 9.55, Z: -0.10 m/s^2
-Y:
Acceleration X: 0.04, Y: -9.93, Z: -0.05 m/s^2

The X and Y readings could be adjusted fairly close to 9.81 m/s^2 with just an offset, but it seems like the Z axis would also require some scaling.

My question, is there a standard method of calibrating it in code?

2 Answers 2

2

Yes an accelerometer can be calibrated. An offset for each of the 3 accelerometers can be found such that the absolute value of the maximum and minimum values of any given accelerometer axis are equal. The maximum and minimum values can be found by rotating the accelerometer such that each axes is pointed directly toward and directly away from the earth. Once each axes is normalized each axes needs a magnitude adjustment value such that the maximum value of all axes equal one another. It may be convenient the product of the maximum of any given axes and that axes' magnitude adjustment value is 9.8 (meters per second * second).

3
  • Would you have an article or link you can share so we can have a look. I understand what you're saying but have no idea how to actually do it. Commented Aug 7, 2021 at 12:10
  • 1
    It's a little difficult to find an appropriate article. This NIST article goes way overboard assuming the 3 accelerometers may not even be orthogonal. And other articles skip over accelerometer calibration (to be honest, accelerometers are usually good out of the box for most Arduino applications). Try this Adafruit article it sounds like what you are after.
    – st2000
    Commented Aug 8, 2021 at 16:39
  • Thank you for your comment Commented Aug 20, 2021 at 10:55
-1

Yes. Jeff Rowberg's library performs the calibration for you when you power on. You'll need to make sure the module is lying level and still and then send a character over serial to trigger the calibration. A version based on Jeff's library, called Electronic Cats, can be downloaded directly using the Arduino IDE.

Note that Jeff's library is a bit overwhelming/intimidating for new users. If you'd like to learn more about hiding its complexity behind a simple and easy to use interface, or about being able to save the calibration results to persistent memory so that you don't have to perform the calibration every time you power on, or just want to learn more about this topic in general, please consult the following tutorial:

https://youtu.be/k5i-vE5rZR0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.