Skip to content
SensorMITvRolling (I2Cdevlib, no formal semver — use latest commit)

MPU6050 Library

by Electronic Cats / Jeff Rowberg

This I2Cdevlib-based library drives the MPU6050 6-axis IMU (3-axis gyro + 3-axis accelerometer), including access to the chip's onboard Digital Motion Processor (DMP) — a hardware sensor-fusion engine that computes stable orientation quaternions on-chip, offloading the fusion math that would otherwise need a software filter (like Madgwick) running on your microcontroller. The catch that trips people up is the DMP firmware blob: enabling it requires uploading a several-kilobyte firmware image to the chip at startup via `dmpInitialize()`, which takes noticeable time and RAM, and fails silently on boards too memory-constrained to hold the FIFO buffer — an 8-bit Uno can run it, but it's tight; ESP32 has comfortable headroom.

Installation

Arduino IDE — Library Manager

Sketch → Include Library → Manage Libraries → search Requires I2Cdevlib-MPU6050 + I2Cdevlib-Core, added manually from GitHub (not in Library Manager)

PlatformIO

lib_deps = Not available on PlatformIO registry — add via lib_deps GitHub URL

Supported boards

Arduino UnoESP32STM32 Blue Pill

Examples

Read stable orientation via the onboard DMP

Offloads sensor-fusion math to the chip's hardware DMP instead of a software filter on the microcontroller.

#include "MPU6050_6Axis_MotionApps20.h"

MPU6050 mpu;
Quaternion q;
VectorFloat gravity;
float ypr[3];

void setup() {
  Wire.begin();
  mpu.initialize();
  mpu.dmpInitialize();
  mpu.setDMPEnabled(true);
}

void loop() {
  // read FIFO, then:
  mpu.dmpGetQuaternion(&q, fifoBuffer);
  mpu.dmpGetGravity(&gravity, &q);
  mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
}