🐻 Tutorial 31 - MPU-6050

The MPU-6050 is a commonly used accelerometer and gyroscope sensor module that measures the orientation, motion, and acceleration of an object in three-dimensional space. It combines a 3-axis accelerometer and a 3-axis gyroscope into a single package, allowing for accurate measurement of both linear acceleration and angular velocity.

The MPU-6050 communicates with a microcontroller using an I2C interface and provides information about the orientation, motion, and acceleration of an object in real-time. It also includes a Digital Motion Processor (DMP), which performs complex motion processing algorithms, such as motion fusion, gesture recognition, and sensor calibration, on the chip itself.

The MPU-6050 can be used in a wide range of applications, including gaming controllers, drones, robots, and other devices that require accurate motion sensing. It is easy to use and cost-effective, making it a popular choice for hobbyists and professionals alike.

The MPU-6050 is available in a variety of package types, including QFN, TQFP, and DFN, and can be easily integrated into electronic projects using a variety of programming languages, including C, C++, and Python.

Overall, the MPU-6050 is a versatile and widely-used sensor module that provides a simple and effective way to measure the orientation, motion, and acceleration of an object in three-dimensional space. Its ease of use and compatibility with a wide range of devices make it a popular choice for hobbyists and professionals alike.

Components Needed

ComponentQuantity
Raspberry Pi Pico W1
Micro USB Cable1
Breadboard1
WiresSeveral
MPU-60501

Fritzing Diagram

Code

from imu import MPU6050
from machine import I2C, Pin
import time

i2c = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000)
mpu = MPU6050(i2c)

while True:
    print("x: %s, y: %s, z: %s"%(mpu.accel.x, mpu.accel.y, mpu.accel.z))
    time.sleep(0.1)
    print("A: %s, B: %s, Y: %s"%(mpu.gyro.x, mpu.gyro.y, mpu.gyro.z))
    time.sleep(0.1)

Code Explanation