Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/Continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ jobs:
id: compile
uses: stm32duino/actions/compile-examples@main
with:
board-pattern: "NUCLEO_L476RG"

custom-config: "./extras/build_config.json"
board-pattern: "NUCLEO_L476RG|NUCLEO_H503RB|NUCLEO_C562RE"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# Use the output from the `Compilation` step
- name: Compilation Errors
if: failure()
Expand Down
57 changes: 43 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Arduino library to support the LSM6DSV16X 3D accelerometer and 3D gyroscope

## API

This sensor uses I2C or SPI to communicate.
This sensor uses I2C, I3C or SPI to communicate.
For I2C it is then required to create a TwoWire interface before accessing to the sensors:

TwoWire dev_i2c(I2C_SDA, I2C_SCL);
Expand All @@ -14,6 +14,10 @@ For SPI it is then required to create a SPI interface before accessing to the se
SPIClass dev_spi(SPI_MOSI, SPI_MISO, SPI_SCK);
dev_spi.begin();

For I3C it is then required to create an I3C interface before accessing to the sensors:

I3C.begin(I3C_SDA, I3C_SCL, 1000000U);

An instance can be created and enabled when the I2C bus is used following the procedure below:

LSM6DSV16XSensor AccGyr(&dev_i2c);
Expand All @@ -28,6 +32,27 @@ An instance can be created and enabled when the SPI bus is used following the pr
AccGyr.Enable_X();
AccGyr.Enable_G();


An instance can be created and enabled when the I3C bus is used with SETDASA (static-to-dynamic address assignment):
LSM6DSV16XSensor AccGyr(&I3C, LSM6DSV16X_I3C_ADD_H);
I3C.resetDynamicAddresses();
I3C.assignDynamicAddress(AccGyr.getStaticAddress(), LSM6DSV16X_DYNAMIC_ADDRESS);
AccGyr.begin(LSM6DSV16X_DYNAMIC_ADDRESS);
I3C.setClock(12500000);
AccGyr.Enable_X();
AccGyr.Enable_G();

An instance can be created and enabled when the I3C bus is used with ENTDAA (dynamic address discovery):

LSM6DSV16XSensor AccGyr(&I3C);
I3C.begin(I3C_SDA, I3C_SCL, 1000000U);
I3C.discover(devices, 8, &found);
// find dynAddr by matching LSM6DSV16X_I3C_PID_H in discovered devices
AccGyr.begin(dynAddr);
I3C.setClock(12500000);
AccGyr.Enable_X();
AccGyr.Enable_G();

The access to the sensor values is done as explained below:

Read accelerometer and gyroscope.
Expand All @@ -39,31 +64,35 @@ The access to the sensor values is done as explained below:

## Examples

* LSM6DSV16X_DataLog_Terminal: This application shows how to get data from LSM6DSV16X accelerometer and gyroscope and print them on terminal.
* LSM6DSV16X_DataLog_Terminal_I2C: This application shows how to get data from LSM6DSV16X accelerometer and gyroscope and print them on terminal over I2C.

* LSM6DSV16X_6D_Orientation_I2C: This application shows how to use LSM6DSV16X accelerometer to find out the 6D orientation and display data on a hyperterminal over I2C.

* LSM6DSV16X_Datalog_Terminal_I3C: This application shows how to use LSM6DSV16X accelerometer and gyroscope over I3C using SETDASA.

* LSM6DSV16X_6D_Orientation: This application shows how to use LSM6DSV16X accelerometer to find out the 6D orientation and display data on a hyperterminal.
* LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA: This application shows how to discover and use LSM6DSV16X dynamic address over I3C.

* LSM6DSV16X_Double_Tap_Detection: This application shows how to detect the double tap event using the LSM6DSV16X accelerometer.
* LSM6DSV16X_Double_Tap_Detection_I2C: This application shows how to detect the double tap event using the LSM6DSV16X accelerometer over I2C.

* LSM6DSV16X_Free_Fall_Detection: This application shows how to detect the free fall event using the LSM6DSV16X accelerometer.
* LSM6DSV16X_Free_Fall_Detection_I2C: This application shows how to detect the free fall event using the LSM6DSV16X accelerometer over I2C.

* LSM6DSV16X_MLC: This application shows how to detect the activity using the LSM6DSV16X Machine Learning Core.
* LSM6DSV16X_MLC_I2C: This application shows how to detect the activity using the LSM6DSV16X Machine Learning Core over I2C.

* LSM6DSV16X_Pedometer: This application shows how to use LSM6DSV16X accelerometer to count steps.
* LSM6DSV16X_Pedometer_I2C: This application shows how to use LSM6DSV16X accelerometer to count steps over I2C.

* LSM6DSV16X_Qvar_Polling: This application shows how to use LSM6DSV16X Qvar features in polling mode.
* LSM6DSV16X_Qvar_Polling_I2C: This application shows how to use LSM6DSV16X Qvar features in polling mode over I2C.

* LSM6DSV16X_Sensor_Fusion: This application shows how to use LSM6DSV16X Sensor Fusion features for reading quaternions.
* LSM6DSV16X_Sensor_Fusion_I2C: This application shows how to use LSM6DSV16X Sensor Fusion features for reading quaternions over I2C.

* LSM6DSV16X_Single_Tap_Detection: This application shows how to detect the single tap event using the LSM6DSV16X accelerometer.
* LSM6DSV16X_Single_Tap_Detection_I2C: This application shows how to detect the single tap event using the LSM6DSV16X accelerometer over I2C.

* LSM6DSV16X_Tilt_Detection: This application shows how to detect the tilt event using the LSM6DSV16X accelerometer.
* LSM6DSV16X_Tilt_Detection_I2C: This application shows how to detect the tilt event using the LSM6DSV16X accelerometer over I2C.

* LSM6DSV16X_Wake_Up_Detection: This application shows how to detect the wake-up event using the LSM6DSV16X accelerometer.
* LSM6DSV16X_Wake_Up_Detection_I2C: This application shows how to detect the wake-up event using the LSM6DSV16X accelerometer over I2C.

* LSM6DSV16X_FIFO_Polling: This application shows how to get accelerometer and gyroscope data from FIFO in pooling mode and print them on terminal.
* LSM6DSV16X_FIFO_Polling_I2C: This application shows how to get accelerometer and gyroscope data from FIFO in pooling mode and print them on terminal over I2C.

* LSM6DSV16X_FIFO_Interrupt: This application shows how to get accelerometer and gyroscope data from FIFO using interrupt and print them on terminal.
* LSM6DSV16X_FIFO_Interrupt_I2C: This application shows how to get accelerometer and gyroscope data from FIFO using interrupt and print them on terminal over I2C.
## Documentation

You can find the source files at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_HelloWorld.ino
@file LSM6DSV16X_6D_Orientation_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X 6D Orientation
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
@file LSM6DSV16X_DataLog_Terminal.ino
@file LSM6DSV16X_DataLog_Terminal_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X inertial measurement sensor
*******************************************************************************
Copyright (c) 2022, STMicroelectronics
Copyright (c) 2026, STMicroelectronics
All rights reserved.
This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
@file LSM6DSV16X_DataLog_Terminal_I3C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X sensor with I3C and SETDASA command
*******************************************************************************
Copyright (c) 2026, STMicroelectronics
All rights reserved.

This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause

*******************************************************************************
*/
#include "LSM6DSV16XSensor.h"

#define LSM6DSV16X_DYNAMIC_ADDRESS 0x30

LSM6DSV16XSensor sensor(&I3C, LSM6DSV16X_I3C_ADD_H);

void setup()
{
Serial.begin(115200);
while (!Serial) {}
delay(1000);

Serial.println("=== LSM6DSV16X SETDASA ===");

if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
Serial.println("begin() failed");
while (1) {}
}

if (!I3C.resetDynamicAddresses()) {
Serial.println("resetDynamicAddresses() failed");
while (1) {}
}

if (!I3C.assignDynamicAddress(sensor.getStaticAddress(), LSM6DSV16X_DYNAMIC_ADDRESS)) {
Serial.println("assignDynamicAddress() failed");
while (1) {}
}

if (sensor.begin(LSM6DSV16X_DYNAMIC_ADDRESS) != LSM6DSV16X_OK) {
Serial.println("sensor.begin() failed");
while (1) {}
}

if (!I3C.setClock(12500000)) {
Serial.println("setClock() failed");
while (1) {}
}

if (sensor.Enable_X() != LSM6DSV16X_OK) {
Serial.println("sensor.Enable_X() failed");
while (1) {}
}

if (sensor.Enable_G() != LSM6DSV16X_OK) {
Serial.println("sensor.Enable_G() failed");
while (1) {}
}

Serial.println("LSM6DSV16X ready");
}

void loop()
{
int32_t accel[3] = {0};
int32_t angrate[3] = {0};

if (sensor.Get_X_Axes(accel) == LSM6DSV16X_OK && sensor.Get_G_Axes(angrate) == LSM6DSV16X_OK) {
Serial.print("Accel-X[mg]:");
Serial.print(accel[0]);
Serial.print(",Accel-Y[mg]:");
Serial.print(accel[1]);
Serial.print(",Accel-Z[mg]:");
Serial.println(accel[2]);

Serial.print("AngRate-X[mdps]:");
Serial.print(angrate[0]);
Serial.print(",AngRate-Y[mdps]:");
Serial.print(angrate[1]);
Serial.print(",AngRate-Z[mdps]:");
Serial.println(angrate[2]);
} else {
Serial.println("Read failed");
}

delay(500);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
@file LSM6DSV16X_DataLog_Terminal_I3C_ENTDAA.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X sensor with I3C dynamic address assignment
*******************************************************************************
Copyright (c) 2026, STMicroelectronics
All rights reserved.

This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause

*******************************************************************************
*/

#include "LSM6DSV16XSensor.h"

LSM6DSV16XSensor sensor(&I3C);

void setup()
{
Serial.begin(115200);
while (!Serial) {}
delay(1000);

Serial.println("=== LSM6DSV16X DAA ===");

if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
Serial.println("begin() failed");
while (1) {}
}

if (!I3C.resetDynamicAddresses()) {
Serial.println("resetDynamicAddresses() failed");
while (1) {}
}

I3CDiscoveredDevice devices[8] = {};
size_t found = 0;

if (I3C.discover(devices, 8, &found)) {
Serial.println("discover() failed");
while (1) {}
}

uint8_t lsmDynAddr = 0U;

for (size_t i = 0; i < found; ++i) {
Serial.println(devices[i].pid, HEX);
if (devices[i].pid == LSM6DSV16X_I3C_PID_H) {
lsmDynAddr = devices[i].dynAddr;
Serial.print("lsmDynAddr=");
Serial.println(lsmDynAddr, HEX);
break;
}
}

if (lsmDynAddr == 0U) {
Serial.println("Sensor not found");
while (1) {}
}

if (sensor.begin(lsmDynAddr) != LSM6DSV16X_OK) {
Serial.println("sensor.begin() failed");
while (1) {}
}

if (!I3C.setClock(12500000)) {
Serial.println("setClock() failed");
while (1) {}
}

if (sensor.Enable_X() != LSM6DSV16X_OK) {
Serial.println("sensor.Enable_X() failed");
while (1) {}
}

if (sensor.Enable_G() != LSM6DSV16X_OK) {
Serial.println("sensor.Enable_G() failed");
while (1) {}
}

Serial.println("LSM6DSV16X ready");
}

void loop()
{
int32_t accel[3] = {0};
int32_t angrate[3] = {0};

if (sensor.Get_X_Axes(accel) == LSM6DSV16X_OK && sensor.Get_G_Axes(angrate) == LSM6DSV16X_OK) {
Serial.print("Accel-X[mg]:");
Serial.print(accel[0]);
Serial.print(",Accel-Y[mg]:");
Serial.print(accel[1]);
Serial.print(",Accel-Z[mg]:");
Serial.println(accel[2]);

Serial.print("AngRate-X[mdps]:");
Serial.print(angrate[0]);
Serial.print(",AngRate-Y[mdps]:");
Serial.print(angrate[1]);
Serial.print(",AngRate-Z[mdps]:");
Serial.println(angrate[2]);
} else {
Serial.println("Read failed");
}

delay(500);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Double_Tap_Detection.ino
@file LSM6DSV16X_Double_Tap_Detection_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X Double Tap Detection
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file STEVAL_MEMS_FIFO_Interrupt.ino
@file LSM6DSV16X_FIFO_Interrupt_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X library with FIFO status interrupts.
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file STEVAL_MEMS_FIFO_Interrupt.ino
@file LSM6DSV16X_FIFO_Polling_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X library with FIFO status interrupts.
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Free_Fall_Detection.ino
@file LSM6DSV16X_Free_Fall_Detection_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X Free Fall Detection
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_MLC.ino
@file LSM6DSV16X_MLC_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X Machine Learning Core
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Pedometer.ino
@file LSM6DSV16X_Pedometer_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X Pedometer
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Qvar.ino
@file LSM6DSV16X_Qvar_Polling_I2C.ino
@author STMicroelectronics
@brief Example to use LSM6DSV16X Qvar features
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Sensor_Fusion.ino
@file LSM6DSV16X_Sensor_Fusion_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X library with Sensor Fusion Low Power.
*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
@file LSM6DSV16X_Single_Tap_Detection.ino
@file LSM6DSV16X_Single_Tap_Detection_I2C.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X Single Tap Detection
*******************************************************************************
Expand Down
Loading