How To Calibrate Gyroscope With Mpu6050
About the project
Learn how to calibrate the gyroscope on the MPU6050 using Raspberry Pi Pico W for more accurate sensor readings.
Project info
Difficulty: Easy
Platforms: Raspberry Pi, MicroPython
Estimated time: 1 hour
License: GNU General Public License, version 3 or later (GPL3+)
Items used in this project
Hardware components
Story
Calibrating a sensor is an integral part of achieving accurate results in practice. The tutorial will demonstrate how to calibrate the MPU6050 sensor using MicroPython and the Raspberry Pi Pico W. However the same technique can be applied to any setup, be it Arduino, or any other MicroController. We are calibrating because the sensor values the MPU6050 gives us are not entirely accurate. We proceed with the gyroscopic calibration shown in this tutorial to achieve more accurate representations of the angular acceleration values.
Step 1a-) Keep your sensor Plugged in, and on, and make sure it's not movingYou need to have a steady state to get accurate calibration values. If you move during calibration you will risk skewing the data. The aim of calibrating is to get the inherent error in the sensor readings; this is most easily done when the sensor is not moving because we know the angular acceleration values Gx, Gy, and Gz should be expectedly zero degrees per second in this situation. However, the truth is, if you are laying your sensor on the table at this moment without moving it, you will see you are probably getting non-zero values for your angular acceleration. We need to calculate three offset values that bring the resting sensor readings closer to zero. This is gyroscopic calibration in a nutshell.
Part 1b-) Utilize the following code from my GitHub page to retrieve the 3 offsets
Gyro Calibration Code Python:
MPU Library For MicroPython:
If your MPU6050 is connected just fine in Thonny with your Raspberry Pi Pico (assuming you have the library file saved to your Raspberry Pi), this code works right away, it will return three offsets that you can subtract from your sensor readings. In practice, you can utilize the offset sensor readings for measurement which should be more accurate than the measurements you took without the offset.
However, for those of you who aren't utilizing MicroPython, you may be wondering what the idea of the code is. The idea is that I am allowing the sensor to take a running sum (for a given time) of the gyro readings in all three degrees of angular acceleration. I know the true value of the sensor should be zero for all readings of angular acceleration, however, the sensor never gives me the true value; it gives me the true value plus some offset. Thus because we know,
- true_sensor_value = measured_sensor_value - offset
and when we are calibrating in a non-moving state the true_sensor_value is zero, the value we are measuring is just the offset. So we are taking a running sum of the offset and then taking the average... that is all we are doing!
Part 1c-) Add the offsets to your readings, calibration is done!I calculated the offset to be -2.145951, 1.384315, and -0.5084849. Yours should be a little different or even a lot different. I subtracted them as follows
Conclusion:Hope you were able to calibrate your Gyro appropriately. If you are having issues following this text or simply enjoyed this quick tutorial please follow my Youtube Channel to watch it and get more details. Also be sure to like, comment, and subscribe as well!
Credits
mahmood-m-shilleh
Mechanical and Software Engineering Background. University at Buffalo 2019 Texas A&M 2021 I make data pipelines for my day job. Outside of work, I participate in online communities regarding Full Stack Engineering, Microelectronics, and more. You can find more details about me on my Youtube Channel. https://www.youtube.com/@mmshilleh Feel free to reach out!
Leave your feedback...