Skip to content

Commit 56b211b

Browse files
authored
Merge pull request #20 from cparata/main
Improve FIFO examples
2 parents 790a1e3 + 5ff786d commit 56b211b

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

examples/LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545

4646
#include "LSM6DSOXSensor.h"
4747

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

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

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

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

163165
lsm6dsoxSensor.Get_FIFO_Num_Samples(&numSamples);
164166

165167
Serial.print("numSamples=");
166168
Serial.println(numSamples);
169+
Serial.flush();
167170

168171
// fetch data from FIFO
169172
for (uint16_t i = 0; i < numSamples; i++) {
@@ -179,6 +182,7 @@ void loop() {
179182
Serial.print(", "); Serial.print(rotation[1]);
180183
Serial.print(", "); Serial.print(rotation[2]);
181184
Serial.println();
185+
Serial.flush();
182186
#endif
183187
}
184188

@@ -191,6 +195,7 @@ void loop() {
191195
Serial.print(", "); Serial.print(acceleration[1]);
192196
Serial.print(", "); Serial.print(acceleration[2]);
193197
Serial.println();
198+
Serial.flush();
194199
#endif
195200
}
196201

@@ -206,6 +211,7 @@ void loop() {
206211
Serial.println(count_gyro_samples);
207212
Serial.print("Dummy Samples: ");
208213
Serial.println(count_dummy_samples);
214+
Serial.flush();
209215
}
210216
}
211-
}
217+
}

examples/LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
#include "LSM6DSOXSensor.h"
4646

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

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

5656
void setup() {
5757

58-
Serial.begin(115200);
58+
Serial.begin(921600);
5959
// Comment this line to skip waiting for serial:
6060
while(!Serial) delay(10);
6161

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

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

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

137139
// fetch data from FIFO
138140
for (uint16_t i = 0; i < WTM_LV; i++) {
@@ -142,22 +144,24 @@ void loop() {
142144
// Get gyroscope data
143145
if (Tag == 1) {
144146
lsm6dsoxSensor.Get_FIFO_G_Axes(rotation);
145-
#if 0 // set to 1 for printing values
147+
#if 1 // set to 1 for printing values
146148
Serial.print("mdps: "); Serial.print(rotation[0]);
147149
Serial.print(", "); Serial.print(rotation[1]);
148150
Serial.print(", "); Serial.print(rotation[2]);
149151
Serial.println();
152+
Serial.flush();
150153
#endif
151154
}
152155

153156
// Get accelerometer data
154157
else if (Tag == 2) {
155158
lsm6dsoxSensor.Get_FIFO_X_Axes(acceleration);
156-
#if 0 // set to 1 for printing values
159+
#if 1 // set to 1 for printing values
157160
Serial.print("mG: "); Serial.print(acceleration[0]);
158161
Serial.print(", "); Serial.print(acceleration[1]);
159162
Serial.print(", "); Serial.print(acceleration[2]);
160163
Serial.println();
164+
Serial.flush();
161165
#endif
162166
}
163167
}
@@ -168,6 +172,7 @@ void loop() {
168172

169173
if (fullStatus != 0) {
170174
Serial.println("-- FIFO is full!, consider reducing Watermark Level or Buffer Data Rate.\nFlushing data from FIFO.");
175+
Serial.flush();
171176
lsm6dsoxSensor.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); // flush FIFO data
172177
lsm6dsoxSensor.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); // continue batching
173178
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino LSM6DSOX
2-
version=2.3.1
2+
version=2.3.2
33
author=SRA
44
maintainer=stm32duino
55
sentence=Ultra Low Power inertial measurement unit.

0 commit comments

Comments
 (0)