Skip to content

Commit

Permalink
Add SFLP HW feature and relative example
Browse files Browse the repository at this point in the history
  • Loading branch information
davideq committed Sep 5, 2023
1 parent f588bc2 commit fbba26a
Show file tree
Hide file tree
Showing 10 changed files with 5,925 additions and 4,066 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ The access to the sensor values is done as explained below:

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

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

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

* LSM6DSV16X_Tilt_Detection: This application shows how to detect the tilt event using the LSM6DSV16X accelerometer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@file LSM6DSV16X_DataLog_Terminal.ino
@author Giuseppe Roberti <[email protected]>
@author STMicroelectronics
@brief Example to use the LSM6DSV16X inertial measurement sensor
*******************************************************************************
Copyright (c) 2022, STMicroelectronics
Expand Down
79 changes: 79 additions & 0 deletions examples/LSM6DSV16X_Sensor_Fusion/LSM6DSV16X_Sensor_Fusion.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
@file LSM6DSV16X_Sensor_Fusion.ino
@author STMicroelectronics
@brief Example to use the LSM6DSV16X library with Sensor Fusion Low Power.
*******************************************************************************
Copyright (c) 2022, 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 ALGO_FREQ 120U /* Algorithm frequency 120Hz */
#define ALGO_PERIOD (1000U / ALGO_FREQ) /* Algorithm period [ms] */
unsigned long startTime, elapsedTime;

LSM6DSV16XSensor AccGyr(&Wire);
uint8_t status = 0;
uint8_t tag = 0;
float quaternions[4]={0};

void setup() {

Serial.begin(115200);
while (!Serial) yield();

Wire.begin();
// Initialize LSM6DSV16X.
AccGyr.begin();

// Enable Sensor Fusion
status |= AccGyr.Enable_Rotation_Vector();

if(status != LSM6DSV16X_OK) {
Serial.println("LSM6DSV16X Sensor failed to init/configure");
while(1);
}
Serial.println("LSM6DSV16X SFLP Demo");
}

void loop() {
uint16_t fifo_samples;
// Get start time of loop cycle
startTime = millis();
// Check the number of samples inside FIFO
if(AccGyr.FIFO_Get_Num_Samples(&fifo_samples) != LSM6DSV16X_OK){
Serial.println("LSM6DSV16X Sensor failed to get number of samples inside FIFO");
while(1);
}

// Read the FIFO if there is one stored sample
if (fifo_samples > 0) {
for (int i = 0; i < fifo_samples; i++) {
AccGyr.FIFO_Get_Tag(&tag);
if(tag==0x13u){
AccGyr.FIFO_Get_Rotation_Vector(&quaternions[0]);

// Print Quaternion data
Serial.print("Quaternion: ");
Serial.print(quaternions[3], 4);
Serial.print(", ");
Serial.print(-quaternions[1], 4);
Serial.print(", ");
Serial.print(quaternions[0], 4);
Serial.print(", ");
Serial.println(quaternions[2], 4);

// Compute the elapsed time within loop cycle and wait
elapsedTime = millis() - startTime;
delay(ALGO_PERIOD - elapsedTime);
}
}
}
}
2 changes: 1 addition & 1 deletion extras/codespell-ignore-words-list.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ois
OIS
14 changes: 12 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#######################################

LSM6DSV16XSensor KEYWORD1
LSM6DSV16XStatusTypeDef KEYWORD1
LSM6DSV16XStatusTypeDef KEYWORD1
LSM6DSV16X_Event_Status_t KEYWORD1
LSM6DSV16X_SensorIntPin_t KEYWORD1
LSM6DSV16X_ACC_Operating_Mode_t KEYWORD1
Expand Down Expand Up @@ -90,12 +90,22 @@ FIFO_Set_X_BDR KEYWORD2
FIFO_Get_G_Axes KEYWORD2
FIFO_Set_G_BDR KEYWORD2
QVAR_Enable KEYWORD2
QVAR_Disable KEYWORD2
QVAR_GetStatus KEYWORD2
QVAR_GetImpedance KEYWORD2
QVAR_SetImpedance KEYWORD2
QVAR_GetData KEYWORD2
Get_MLC_Status KEYWORD2
Get_MLC_Output KEYWORD2

Enable_Rotation_Vector KEYWORD2
Disable_Rotation_Vector KEYWORD2
Enable_Gravity_Vector() KEYWORD2
Disable_Gravity_Vector KEYWORD2
Enable_Gyroscope_Bias KEYWORD2
Disable_Gyroscope_Bias KEYWORD2
FIFO_Get_Rotation_Vector KEYWORD2
FIFO_Get_Gravity_Vector KEYWORD2
FIFO_Get_Gyroscope_Bias KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino LSM6DSV16X
version=1.5.1
version=1.6.1
author=SRA
maintainer=stm32duino
sentence=Ultra Low Power inertial measurement unit.
Expand Down
Loading

0 comments on commit fbba26a

Please sign in to comment.