MPU-6050 IMU
The MPU-6050 is a 6-axis IMU (3-axis accelerometer + 3-axis gyroscope) with I²C interface.
Wiring (Raspberry Pi)
| MPU-6050 | Raspberry Pi |
|---|---|
| VCC | Pin 1 (3.3V) |
| GND | Pin 6 (GND) |
| SDA | Pin 3 (GPIO2) |
| SCL | Pin 5 (GPIO3) |
Enable I²C: sudo raspi-config → Interface Options → I2C → Enable.
Python Reading
bash
pip install mpu6050-raspberrypipython
from mpu6050 import mpu6050
sensor = mpu6050(0x68)
accel = sensor.get_accel_data()
gyro = sensor.get_gyro_data()
temp = sensor.get_temp()
print(f"Accel: {accel}")
print(f"Gyro: {gyro}")
print(f"Temp: {temp:.1f} °C")Verify I²C Address
bash
sudo i2cdetect -y 1
# Should show 0x68 (or 0x69 if AD0 pin is HIGH)WARNING
The MPU-6050 has significant gyroscope drift. Always complement it with an accelerometer-based tilt correction or use the DMP (Digital Motion Processor) for fused orientation.