Skip to content

nopnop2002/esp-idf-lsm6ds3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp-idf-lsm6ds3

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

You can use the Kalman filter or the Madgwick filter to estimate the Euler angle.
Euler angles are roll, pitch and yaw.
It's very intuitive and easy to understand.
However, since LSM6DS3 is a 6DoF IMU, YAW estimation is not possible.
a-Pitch-yaw-and-roll-angles-of-an-aircraft-with-body-orientation-O-u-v-original
You can view like this.
Image

Software requirements

ESP-IDF V5.2 or later.
Because this project uses the new I2C driver.

Hardware requirements

This project supports the following IMUs:

  • LSM6DS3 Accelerometer Gyroscope module 6 Dof inertial Measurement Sensors.
  • LSM6DSM Accelerometer Gyroscope module 6 Dof inertial Measurement Sensors.
  • LSM6DSL Accelerometer Gyroscope module 6 Dof inertial Measurement Sensors.
  • LSM6DSR Accelerometer Gyroscope module 6 Dof inertial Measurement Sensors.
  • LSM6DSO Accelerometer Gyroscope module 6 Dof inertial Measurement Sensors.

Note for LSM6DSV
LSM6DSV is not supported because it has a different register map.

Wireing

lsm6dsX ESP32 ESP32-S2/S3 ESP32-C2/C3/C6
VIN(*3) -- 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)
CS -- 3.3V 3.3V 3.3V Use i2c
SAO(*4) -- GND/3.3V GND/3.3V GND/3.3V (*2)

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

(*2)I2C address selection.
GND:i2c address is 0x6A.
3.3V:i2c address is 0x6B.

(*3)Some modules do not have this pin.

(*4)They may also be marked as ADO or SDO.

Find the sensor

We can find the sensor using i2c-tools.

  • Selcect SCL and SDA using menuconfig.
    Image

  • Detect senser.
    The i2c address for this sensor is 0x6a or 0x6b.
    Image

  • Read register.
    Read register 0x0F.
    LSM6DS3 is 0x69.
    LSM6DSM/LSM6DSL is 0x6A.
    LSM6DSR is 0x6B.
    LSM6DSO is 0x6C.
    Image

Get Euler angles from lsm6ds3 using Kalman filter

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

Configuration

config-top config-app

Get Euler angles from lsm6ds3 using Madgwick filter

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

Configuration

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/

lsm6ds3-browser

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

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 |
|             |          |             |          |             |
+-------------+          +-------------+          +-------------+

Installation for Linux

$ python3 --version
Python 3.11.2
$ 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.
lsm6ds3_2023-03-23_10-52-26

Installation for Windows

Install Git for Windows from here.
Install Python Releases for Windows from here.
Open Git Bash and run:

$ python --version
Python 3.11.9
$ python -m pip install -U pip
$ python -m pip install pygame
$ python -m pip install PyOpenGL PyOpenGL_accelerate
$ git clone https://github.com/thecountoftuscany/PyTeapot-Quaternion-Euler-cube-rotation
$ cd PyTeapot-Quaternion-Euler-cube-rotation
$ python pyteapot.py

Image

View Euler angles using panda3d library

You can view Euler angles using this library.
It works as a UDP display server.

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

Installation for Linux

$ python3 --version
Python 3.11.2
$ sudo apt install python3-pip python3-setuptools
$ python3 -m pip install -U pip
$ python3 -m pip install panda3d
$ git clone https://github.com/nopnop2002/esp-idf-mpu6050-dmp
$ cd esp-idf-mpu6050-dmp/panda3d
$ python3 panda.py --help
usage: panda.py [-h] [--model {jet,biplain,707,fa18}]

options:
  -h, --help            show this help message and exit
  --model {jet,biplain,707,fa18}

Image

Installation for Windows

Install Git for Windows from here.
Install Python Releases for Windows from here.
Open Git Bash and run:

$ python --version
Python 3.11.9
$ python -m pip install -U pip
$ python -m pip install panda3d
$ git clone https://github.com/nopnop2002/esp-idf-mpu6050-dmp
$ cd esp-idf-mpu6050-dmp/panda3d
$ python panda.py --help
usage: panda.py [-h] [--model {jet,biplain,707,fa18}]

options:
  -h, --help            show this help message and exit
  --model {jet,biplain,707,fa18}

Image

How to use

See here

Releases

No releases published

Packages

 
 
 

Contributors