Proof of Concept

LSM6DS3 Driver

ESP-IDF driver for ST LSM6DS3 6‑axis IMU on ESP32-P4 (sensor fusion, roll/pitch)

Status: This project is a proof-of-concept implementation and requires further development, testing, and validation before production use.

LSM6DS3 6-DoF IMU

Overview

A comprehensive ESP-IDF driver for the STMicroelectronics LSM6DS3 6‑axis IMU sensor, featuring sensor fusion capabilities for computing absolute ground angles (roll and pitch). The driver is designed to be easy to integrate and use, providing both low-level sensor access and high-level orientation estimation functionality.

This driver includes comprehensive calibration support, angle zero reference management, and NVS persistence for maintaining settings across reboots. It is designed specifically for the ESP32-P4 platform and is used in EIP Ground Truth and FusionCoreEnIP projects.

Features

Hardware Setup

The driver works with any LSM6DS3 breakout; the image above shows the Adafruit LSM6DS3TR-C breakout.

I2C Connection (Default)

Connect the LSM6DS3 to your ESP32-P4:

SPI Connection

For SPI mode, connect:

Sensor Fusion Algorithms

This implementation provides two distinct sensor fusion algorithms, each suited for different application requirements:

Madgwick Filter

The Madgwick filter offers superior accuracy at the cost of increased computational requirements. This implementation provides quaternion output that can be converted to Euler angles (roll, pitch, yaw), making it ideal for applications requiring precise orientation tracking.

Parameters:

Complementary Filter

The complementary filter provides a computationally efficient alternative, offering direct roll and pitch angle output. This implementation is well-suited for applications where processing resources are limited or where real-time performance is critical.

Parameters:

Ground Angle from Vertical (0-180°)

The driver provides a function to calculate the absolute angle from vertical using roll and pitch:

The function uses the formula: acos(cos(roll) × cos(pitch)) to compute the angle from vertical.

Calibration Support

The driver provides comprehensive calibration capabilities to improve sensor accuracy:

Automatic Calibration (Recommended)

Manual Offset Setting

Manual offset adjustment is available for both accelerometer and gyroscope:

NVS Persistence

Calibration data can be saved to and loaded from NVS (Non-Volatile Storage) to persist across reboots:

Angle Zero Reference

The driver provides functionality to set reference angles (zero points) for roll, pitch, and yaw, allowing you to establish a custom reference orientation:

Usage in Other Projects

This driver is used in the following projects:

Important Considerations

Software Requirements

License

This project is licensed under the MIT License. Portions of this software incorporate code derived from STMicroelectronics' STMems_Standard_C_drivers, which are licensed under the BSD-3-Clause license.