Giter Site home page Giter Site logo

nopnop2002 / esp-idf-mpu6050-dmp Goto Github PK

View Code? Open in Web Editor NEW
34.0 1.0 7.0 297 KB

A demo showing the pose of the mpu6050 in 3D using esp-idf

License: MIT License

CMake 0.89% Makefile 0.69% C++ 65.57% C 23.81% HTML 5.12% CSS 0.24% JavaScript 3.69%
esp32 esp-idf imu mpu6050 mpu9250 visualization mpu6500 mpu9255 mpu9225 euler

esp-idf-mpu6050-dmp's Introduction

esp-idf-mpu6050-dmp

A demo showing the pose of the mpu6050 in 3D using esp-idf.

MPU6050 has an internal processing function called DMP (Digital Motion Processor).
You can use this to get Euler angles.
Euler angles are roll, pitch and yaw.
It's very intuitive and easy to understand.
a-Pitch-yaw-and-roll-angles-of-an-aircraft-with-body-orientation-O-u-v-original

Installation overview

  • Perform a calibration of your sensor.

  • Embed the calibration value of the sensor into the source.

  • Get Euler angles from IMU.

  • Display Euler angles in browser.

Software requiment

ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.

Hardware requirements

MotionTracking device with DMP function.

From the left MPU9250 MPU6500 MPU6050 GY-87
Hardware

MPU6000/6050/6500/6555/9150/9225/9250/9255

MPU9150/9225/9250/9255 is a multi-chip module (MCM) consisting of two dies integrated into a single LGA/QFN package.
One die houses the 3-Axis gyroscope and the 3-Axis accelerometer.
The other die houses the AK8975 3-Axis magnetometer from Asahi Kasei Microdevices Corporation.
Since the AK8963 is connected as a slave device, it is not recognized as an i2c device.

Device Reg#117 sensors Compass
MPU6000 0x68 Gyro/Accel
MPU6050 0x68 Gyro/Accel
MPU6500 0x70 Gyro/Accel
MPU6555 0x7C Gyro/Accel
MPU9150 0x68 Gyro/Accel/Compass AK8963
MPU9225 0x73 Gyro/Accel/Compass AK8963
MPU9250 0x71 Gyro/Accel/Compass AK8963
MPU9255 0x73 Gyro/Accel/Compass AK8963

GY-86

GY-86 consists of three chips, MPU6050, HMC5883L and MS5611.
The HMC5883L is 3-Axis magnetometer from Honeywell.
The MS5611 is Barometric Pressure Sensor from TE Connectivity.
Since the HMC5883L is connected as a slave device of MPU6050, it is not recognized as an i2c device.

GY-87

GY-87 consists of three chips, MPU6050, HMC5883L and BMP180.
The HMC5883L is 3-Axis magnetometer from Honeywell.
The BMP180 is Barometric Pressure Sensor from Bosch Sensortec.
Since the HMC5883L is connected as a slave device of MPU6050, it is not recognized as an i2c device.

M5 Product

Some M5 products have an IMU built in.
M5Stack Gray/Fire/Faces/M5GO is equipped with MPU9250 or MPU6886.
M5Core2 is equipped with MPU9250.
M5StickC is equipped with SH200Q or MPU6886.
M5StickC Plus/Plus2 is equipped with MPU6886.
ATOM Matrix/ATOM S3 is equipped with MPU6886.
MPU6886 does not support DMP.
MPU6050_KALMAN/MPU6050_MADGWICK can be used in MPU6886.

About M5Stick
M5Stick has a regular version and an MPU9250 version.
The regular version does not have an IMU.
MPU9250 version supports DMP.

You can check the built-in IMU using IMU_Detect.

Wireing

MPU6xxx/9xxx ESP32 ESP32-S2/S3 ESP32-C2/C3/C6
VCC -- 3.3V 3.3V 3.3V
GND -- GND GND GND
SCL -- GPIO22 GPIO12 GPIO5 (*1)
SDA -- GPIO21 GPIO11 GPIO4 (*1)
GY-86/87 ESP32 ESP32-S2/S3 ESP32-C2/C3/C6
VCC_IN -- N/C N/C N/C
3.3V -- 3.3V 3.3V 3.3V
GND -- GND GND GND
SCL -- GPIO22 GPIO12 GPIO5 (*1)
SDA -- GPIO21 GPIO11 GPIO4 (*1)

(*1)You can change it to any pin using menuconfig.

Perform a calibration of your sensor

I based on this.

git clone https://github.com/nopnop2002/esp-idf-mpu6050-dmp
cd esp-idf-mpu6050-dmp/IMU_Zero
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

More details on configuration is here.

It will take a few minutes for the calibration to complete.
The serial monitor should show results similar to the following.
If -- done -- is displayed, it is completed.

....................    XAccel                  YAccel                          ZAccel                  XGyro                   YGyro                   ZGyro
 [-2891,-2889] --> [-10,3]      [-445,-444] --> [-17,1] [697,698] --> [16381,16400]     [148,149] --> [-1,2]    [26,27] --> [-1,2]      [16,17] --> [-2,1]
.................... [-2890,-2889] --> [-5,3]   [-445,-444] --> [-17,1] [697,698] --> [16375,16400]     [148,149] --> [0,2]     [26,27] --> [0,2]       [16,17] --> [-2,1]
.................... [-2890,-2889] --> [-10,3]  [-445,-444] --> [-16,1] [697,698] --> [16373,16400]     [148,149] --> [0,2]     [26,27] --> [0,2]       [16,17] --> [-1,1]
-------------- done --------------

The last line is your offset value.
We need 6 values XAccelOffset, YAccelOffset, ZAccelOffset, XGyroOffset, YGyroOffset, ZGyroOffset. In this example:

XAccelOffset = -2889
YAccelOffset = -444
ZAccelOffset = 698
XGyroOffset = 149
YGyroOffset = 27
ZGyroOffset = 17

Embed the calibration value of the sensor into the source

Change the offset values below:

cd esp-idf-mpu6050-dmp/MPU6050_DMP6/main
vi mpu6050.cpp
    // This need to be setup individually
    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXAccelOffset(-2889);
    mpu.setYAccelOffset(-444);
    mpu.setZAccelOffset(698);
    mpu.setXGyroOffset(149);
    mpu.setYGyroOffset(27);
    mpu.setZGyroOffset(17);

Get Euler angles from IMU

I based on this.

cd esp-idf-mpu6050-dmp/MPU6050_DMP6
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

More details on configuration is here.

View Euler angles with built-in web server

ESP32 acts as a web server.
I used this component.
This component can communicate directly with the browser.
Enter the following in the address bar of your web browser.

http:://{IP of ESP32}/
or
http://esp32.local/

browser-roll-pitch-yaw

WEB pages are stored in the html folder.
I used this for gauge display.
I used this for 3D display.
You can change the design and color according to your preference.

View Euler angles using PyTeapot

You can view Euler angles using this tool.
It works as a UDP display server.
This is a great application.

+-------------+         +-------------+         +-------------+
|     IMU     |         |    ESP32    |         | pyteapot.py |
|             |--(ic2)->|             |--(UDP)->|             |
|             |         |             |         |             |
+-------------+         +-------------+         +-------------+

Installation

$ sudo apt install python3-pip python3-setuptools
$ python3 -m pip install -U pip
$ python3 -m pip install pygame
$ python3 -m pip install PyOpenGL PyOpenGL_accelerate
$ git clone https://github.com/thecountoftuscany/PyTeapot-Quaternion-Euler-cube-rotation
$ cd PyTeapot-Quaternion-Euler-cube-rotation
$ python3 pyteapot.py

The posture of your sensor is displayed.
pyteapot_2023-03-11_09-11-46

Using IMU Filter

You can use Kalman and Madgwick filters instead of DMP.
DMP estimates Euler angles in-device, whereas these filters estimate Euler angles purely in software.

  • MPU6050_KALMAN
    Estimation using MPU6050 and KALMAN filter.
  • MPU6050_MADGWICK
    Estimation using MPU6050 and MADGWICK filter.
  • MPU9250_KALMAN
    Estimation using MPU9250 and KALMAN filter.
  • MPU9250_MADGWICK
    Estimation using MPU9250 and MADGWICK filter.
  • MPU6050_HMC5883L_KALMAN
    Estimation using MPU6050 + HMC5883L and KALMAN filter.
  • MPU6050_HMC5883L_MADGWICK
    Estimation using MPU6050 + HMC5883L and MADGWICK filter.

esp-idf-mpu6050-dmp's People

Contributors

nopnop2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

esp-idf-mpu6050-dmp's Issues

Seeking Assistance on MPU9250 DMP Implementation

Hi there,

I hope this message finds you well. I'm relatively new to using the MPU6050 and MPU9250 series and have been exploring the capabilities of these sensors, particularly their integrated Digital Motion Processor (DMP). It’s clear that the DMP offloads significant processing from the host processor, which is fantastic for power-saving and efficiency.

The embedded Digital Motion Processor (DMP) is located within the MPU-9250 and offloads computation of
motion processing algorithms from the host processor. The DMP acquires data from accelerometers, gyroscopes, magnetometers and additional 3rd party sensors, and processes the data.

According to the datasheet, the DMP can process data from the gyroscopes, accelerometers, and magnetometers, and fuse these to output comprehensive motion data. Currently, I'm interested in implementing the MPU9250 with its DMP functionality but have noticed the example code is provided only for the MPU6050.

Could you possibly guide me on how to adjust the existing MPU6050_DMP code to work with the MPU9250? Any pointers, example codes, or resources you could share would be greatly appreciated.

Thank you for your time and for all the effort you put into maintaining this repository. I really like your implementation of the 3D object shown in the webpage. ❤️

Looking forward to your insights!

Best regards,

Hays Chan

Reading IMU Data via Serial/UDP

Hi, I am learning to connect my ESP32-S3 with MPU6050 sensor using MPU6050-DMP.

Here is my setup:

  • Board: ESP32-S3 by VCC-GND Studio (YD-ESP32-S3)
  • Host: Ubuntu 22.04
  • ESP-IDF v5.1.

Expected Output:

  • Webpage like in the README.md

Actual Output:

  • I try to open the url using esp32.local / esp ip address but nothing show-up
  • I change to serial with the pyteapot and error as well
    image

Additional Information:
While trying with UDP, the board successfully connected to my wifi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.