SysMick / esp-idf-lsm303dlhc

A demo showing the pose of the lsm303dlhc 6DoF IMU sensor in 3D using esp-idf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esp-idf-lsm303dlhc

A demo showing the pose of the lsm303dlhc 6DoF IMU sensor in 3D using esp-idf.

Usually 6Dof IMU has accelerometer and gyroscope, but this IMU has accelerometer and magnetometer.

Using the data we get from accelerometer and magnetometer we can estimate the 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

First, calibrate the compass and find the offset value for each axis.
As you can see, the X, Y and Z axes are quite off-center.
calibrate-0

Then use the accelerometer and magnetometer to find the Euler angle.
lsm303dlhc-euler

I used this library.

Software requiment

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

Hardware requirements

LSM303DLHC 3D accelerometer and 3D magnetometer module.

Wireing

LSM303DLHC ESP32 ESP32-S2/S3 ESP32-C2/C3
VIN -- N/C N/C N/C
3V3 -- 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.

Caribrate compass

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

Configuration

To find the offset value, set the compass offset to 0.
config-top config app

Execute calibration

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/

As you move the IMU it plots the X, Y and Z values.
X, Y, Z offset are displayed.

calibrate-1 calibrate-2

Execute calibration again

If you set the offset you got from the calibration and run it again, the circle position will change.

calibrate-11 calibrate-12

Get Euler angles from IMU

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

Configuration

Sets the compass offset obtained by calibration.

config-top config app

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/

lsm303dlhc-euler

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     | i2c |    ESP32    | UDP | pyteapot.py |
|             |---->|             |---->|             |
|             |     |             |     |             |
+-------------+     +-------------+     +-------------+
$ 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.
lsm303dlhc_2023-03-21_15-00-00

About

A demo showing the pose of the lsm303dlhc 6DoF IMU sensor in 3D using esp-idf

License:MIT License


Languages

Language:C++ 61.6%Language:C 30.1%Language:JavaScript 3.5%Language:HTML 3.3%Language:CMake 0.7%Language:Makefile 0.6%Language:CSS 0.2%