This guide explains how to calibrate the MPU6050 6-axis IMU (accelerometer and gyroscope) on the Wheelie robot. Proper calibration ensures accurate motion sensing, stable orientation, and reliable sensor fusion.
- Factory offsets: Each MPU6050 has unique bias and offset values.
- Mounting orientation: Small misalignments affect readings.
- Environmental factors: Temperature and vibration can introduce drift.
- Wheelie robot assembled with MPU6050 connected and powered.
- Firmware flashed and serial monitor available (via PlatformIO or Arduino IDE).
- Robot placed on a stable, level surface.
- Place the robot on a flat, stable surface.
- Ensure the robot is completely still during calibration.
- Power on the robot and connect to the serial monitor (baud rate: 115200).
- If your firmware includes a calibration mode, enter it (e.g., send
calibrate_mpuvia serial or use the CLI menu). - If not, modify your code to print raw accelerometer and gyroscope readings continuously.
- Observe the raw values for each axis (Accel X/Y/Z, Gyro X/Y/Z).
- For a stationary, level robot:
- Accelerometer Z should read close to +1g (typically ~16384 for ±2g setting).
- Accelerometer X and Y should be near zero.
- All gyroscope axes should be near zero.
- Accel Offset = 0 (X/Y), +1g (Z) - Raw Value
- Gyro Offset = 0 - Raw Value
- Average readings over several seconds for best results.
- In your code, subtract the calculated offsets from each raw reading:
// Example: Apply offsets in your read function
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
ax -= ACCEL_X_OFFSET;
ay -= ACCEL_Y_OFFSET;
az -= ACCEL_Z_OFFSET;
gx -= GYRO_X_OFFSET;
gy -= GYRO_Y_OFFSET;
gz -= GYRO_Z_OFFSET;- Store offsets in firmware or EEPROM for persistent calibration.
- Re-test with the robot stationary and moving.
- Confirm that stationary readings are close to expected values.
- Adjust offsets if necessary.
- Libraries like MPU6050_light or Jeff Rowberg's MPU6050 include built-in calibration routines.
- Follow library instructions for automated offset calculation and storage.
- Drifting values: Re-run calibration, check for vibration, or use digital low-pass filter.
- Large offsets: Verify sensor orientation and mounting.
- No response: Check I2C wiring and address.