Skip to content

MPU6050

Works with

Any CircuitPython board with I2C

What it does

The MPU6050 is a 6-DOF (degrees of freedom) IMU that combines a triple-axis accelerometer and a triple-axis gyroscope in a single, inexpensive package. The accelerometer measures linear acceleration (useful for tilt and impact detection) while the gyroscope measures rotational rate around each axis (useful for tracking rotation speed). It also includes an onboard temperature sensor. The MPU6050 is one of the most common sensors in budget electronics projects. One important limitation: the gyroscope drifts over time, so accumulated angle estimates become less accurate without correction. For absolute orientation (heading, roll, pitch as stable values), use the BNO055 instead.

Installing the library

Copy adafruit_mpu6050.mpy from the Adafruit CircuitPython Bundle to your board's lib/ folder. Also copy adafruit_bus_device/ if it is not already present.

Quick start

import board
import busio
import adafruit_mpu6050

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_mpu6050.MPU6050(i2c)

print(sensor.acceleration)   # (x, y, z) in m/s²
print(sensor.gyro)            # (x, y, z) in rad/s
print(sensor.temperature)     # °C

Key things you can do

What you want How to do it
Read acceleration (m/s²) sensor.acceleration(x, y, z) tuple
Read rotation rate (rad/s) sensor.gyro(x, y, z) tuple
Read temperature (°C) sensor.temperature
Set accelerometer range sensor.accelerometer_range = adafruit_mpu6050.Range.RANGE_4_G
Set gyro range sensor.gyro_range = adafruit_mpu6050.GyroRange.RANGE_500_DPS

Reading the official docs

https://docs.circuitpython.org/projects/mpu6050/en/latest/

The Range and GyroRange constants are defined in the module — the docs list all available values. If your readings are saturating (clipping at maximum), increase the range. If you need more precision for small movements, reduce the range.

Projects using this library