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
5656void 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.\n Flushing 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 }
0 commit comments