Skip to content

Commit

Permalink
Merge pull request #20 from cparata/main
Browse files Browse the repository at this point in the history
Improve FIFO examples
  • Loading branch information
cparata authored Nov 18, 2022
2 parents 790a1e3 + 5ff786d commit 56b211b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 9 additions & 3 deletions examples/LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

#include "LSM6DSOXSensor.h"

#define SR 417.0f // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz
#define WTM_LV 102 // Watermark threshold level. Max samples in this FIFO configuration is 512 (accel and gyro only).
#define SR 104.0f // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz
#define WTM_LV 199 // Watermark threshold level. Max samples in this FIFO configuration is 512 (accel and gyro only).

// Define interrupt pins according to MCU board and sensor wiring.
#define INT1_pin A0 // MCU input pin connected to sensor INT1 output pin
Expand Down Expand Up @@ -150,6 +150,7 @@ void loop() {
lsm6dsoxSensor.Get_FIFO_Num_Samples(&numSamples);
Serial.print("Samples in FIFO: ");
Serial.println(numSamples);
Serial.flush();

// Check if FIFO threshold level was reached.
if (fullFlag != 0) {
Expand All @@ -159,11 +160,13 @@ void loop() {

if(fullStatus) {
Serial.println("-- FIFO Watermark level reached!, fetching data.");
Serial.flush();

lsm6dsoxSensor.Get_FIFO_Num_Samples(&numSamples);

Serial.print("numSamples=");
Serial.println(numSamples);
Serial.flush();

// fetch data from FIFO
for (uint16_t i = 0; i < numSamples; i++) {
Expand All @@ -179,6 +182,7 @@ void loop() {
Serial.print(", "); Serial.print(rotation[1]);
Serial.print(", "); Serial.print(rotation[2]);
Serial.println();
Serial.flush();
#endif
}

Expand All @@ -191,6 +195,7 @@ void loop() {
Serial.print(", "); Serial.print(acceleration[1]);
Serial.print(", "); Serial.print(acceleration[2]);
Serial.println();
Serial.flush();
#endif
}

Expand All @@ -206,6 +211,7 @@ void loop() {
Serial.println(count_gyro_samples);
Serial.print("Dummy Samples: ");
Serial.println(count_dummy_samples);
Serial.flush();
}
}
}
}
15 changes: 10 additions & 5 deletions examples/LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

#include "LSM6DSOXSensor.h"

#define SR 417 // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz.
#define WTM_LV 500 // Watermark threshold level. Max samples in this FIFO configuration is 512 (accel and gyro only).
#define SR 104 // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz.
#define WTM_LV 199 // Watermark threshold level. Max samples in this FIFO configuration is 512 (accel and gyro only).

/** LSM6DSOX i2c address:
* LSM6DSOX_I2C_ADD_L: 0x6A (default)
Expand All @@ -55,7 +55,7 @@ LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire, LSM6DSOX_I2C_ADD_L);

void setup() {

Serial.begin(115200);
Serial.begin(921600);
// Comment this line to skip waiting for serial:
while(!Serial) delay(10);

Expand Down Expand Up @@ -127,12 +127,14 @@ void loop() {
// Get number of samples in buffer
lsm6dsoxSensor.Get_FIFO_Num_Samples(&numSamples);
Serial.print("Samples in FIFO: "); Serial.println(numSamples);
Serial.flush();

// Check if FIFO threshold level was reached.
lsm6dsoxSensor.Get_FIFO_Watermark_Status(&wtmStatus);

if (wtmStatus != 0) {
Serial.println("-- FIFO Watermark level reached!, fetching data.");
Serial.flush();

// fetch data from FIFO
for (uint16_t i = 0; i < WTM_LV; i++) {
Expand All @@ -142,22 +144,24 @@ void loop() {
// Get gyroscope data
if (Tag == 1) {
lsm6dsoxSensor.Get_FIFO_G_Axes(rotation);
#if 0 // set to 1 for printing values
#if 1 // set to 1 for printing values
Serial.print("mdps: "); Serial.print(rotation[0]);
Serial.print(", "); Serial.print(rotation[1]);
Serial.print(", "); Serial.print(rotation[2]);
Serial.println();
Serial.flush();
#endif
}

// Get accelerometer data
else if (Tag == 2) {
lsm6dsoxSensor.Get_FIFO_X_Axes(acceleration);
#if 0 // set to 1 for printing values
#if 1 // set to 1 for printing values
Serial.print("mG: "); Serial.print(acceleration[0]);
Serial.print(", "); Serial.print(acceleration[1]);
Serial.print(", "); Serial.print(acceleration[2]);
Serial.println();
Serial.flush();
#endif
}
}
Expand All @@ -168,6 +172,7 @@ void loop() {

if (fullStatus != 0) {
Serial.println("-- FIFO is full!, consider reducing Watermark Level or Buffer Data Rate.\nFlushing data from FIFO.");
Serial.flush();
lsm6dsoxSensor.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); // flush FIFO data
lsm6dsoxSensor.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); // continue batching
}
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 LSM6DSOX
version=2.3.1
version=2.3.2
author=SRA
maintainer=stm32duino
sentence=Ultra Low Power inertial measurement unit.
Expand Down

0 comments on commit 56b211b

Please sign in to comment.