Skip to content

This project captures orientation data (roll, pitch, and yaw) from an MPU6050 Inertial Measurement Unit (IMU) connected to an ESP8266 (or other Arduino-compatible board). The data is sent via a serial connection to a Python script, which uses PyOpenGL and PyGame to render a real-time 3D visualization of the sensor's orientation.

Notifications You must be signed in to change notification settings

shohanur-shoron/MPU6050

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Real-Time MPU6050 IMU 3D Visualization

This project captures orientation data (roll, pitch, and yaw) from an MPU6050 Inertial Measurement Unit (IMU) connected to an ESP8266 (or other Arduino-compatible board). The data is sent via a serial connection to a Python script, which uses PyOpenGL and PyGame to render a real-time 3D visualization of the sensor's orientation.

Additionally, the Arduino code demonstrates how to control a servo motor based on the calculated roll angle.

(A sample GIF showing the 3D model rotating in sync with the physical IMU board)

Features

  • Real-time Sensor Fusion: Reads accelerometer and gyroscope data from the MPU6050.
  • Complementary Filter: A simple and effective filter is used on the Arduino to combine sensor readings for stable angle calculations.
  • 3D Visualization: A Python script uses PyOpenGL to draw a 3D cuboid that visually represents the IMU's current orientation.
  • Serial Communication: Efficient request/response communication between the Arduino and the Python script.
  • Interactive Controls: Toggle yaw tracking on the fly and quit the application gracefully.
  • Servo Control: The Arduino sketch includes code to control a servo motor based on the roll angle, perfect for projects like self-balancing robots or camera gimbals.

How It Works

  1. Arduino/ESP8266:

    • The microcontroller continuously reads raw data from the MPU6050 sensor.
    • It applies a complementary filter to the raw values to calculate stable roll, pitch, and yaw angles.
    • It listens for a . character over the serial port. Upon receiving it, it sends back the latest calculated angles as a comma-separated string (e.g., -10.24, 5.12, 95.80).
    • It also drives a connected servo motor to an angle corresponding to the current roll value.
  2. Python Script:

    • Initializes a PyGame window with an OpenGL context.
    • In a loop, it sends a . character to the specified serial port to request data from the Arduino.
    • It reads and parses the incoming line of data to get the roll, pitch, and yaw angles.
    • It uses these angles to apply rotations (glRotatef) to the 3D model, updating its orientation on the screen.
    • It handles user input for quitting the application or toggling yaw mode.

How Accelerometers works

mainStructure

proof mass substrate senceFinger electrodes

capacitance

capacitance charge changes

substrateGIF

movement

three axis

How Gyroscopes works

gyro01 gyro04 gyro03 gyro02

Hardware Requirements

  • An Arduino-compatible board (the code is configured for an ESP8266 like a Wemos D1 Mini or NodeMCU).
  • MPU6050 Gyroscope/Accelerometer Module.
  • A standard servo motor (optional).
  • Jumper wires.

Wiring (for ESP8266)

  • MPU6050 VCC -> 3.3V
  • MPU6050 GND -> GND
  • MPU6050 SCL -> D1 (GPIO5)
  • MPU6050 SDA -> D2 (GPIO4)
  • Servo Signal -> D4 (GPIO2)
  • Servo VCC -> 5V / VIN
  • Servo GND -> GND

Software & Dependencies

Arduino

  • Arduino IDE
  • Board support for your microcontroller (e.g., ESP8266 Core).
  • Wire.h and Servo.h libraries (typically included with the board core).

Python

  • Python 3.x
  • PyOpenGL
  • PyGame
  • PySerial

You can install the required Python packages using pip:

pip install PyOpenGL PyGame pyserial

Setup and Usage

  1. Hardware: Connect the components as described in the wiring diagram above.
  2. Arduino:
    • Open the .ino sketch in the Arduino IDE.
    • Select your board (e.g., "LOLIN(WEMOS) D1 R2 & mini") and the correct COM port from the Tools menu.
    • Upload the sketch to your board.
  3. Python:
    • Open the main.py file.
    • Crucially, find this line and change 'COM3' to the COM port your Arduino is using:
      ser = serial.Serial('COM3', 115200)
  4. Run:
    • Execute the Python script from your terminal:
      python main.py
    • A window should appear showing the 3D model. Tilt your MPU6050 sensor to see it move!

Controls

  • z key: Toggles yaw tracking on or off. When toggled on, it also resets the current yaw angle to zero.
  • Esc key: Closes the application.

About

This project captures orientation data (roll, pitch, and yaw) from an MPU6050 Inertial Measurement Unit (IMU) connected to an ESP8266 (or other Arduino-compatible board). The data is sent via a serial connection to a Python script, which uses PyOpenGL and PyGame to render a real-time 3D visualization of the sensor's orientation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published