SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_read_from_fifo_deprecated.ino
Go to the documentation of this file.
1
30#include <Arduino.h>
31#include <Wire.h>
32#include <SPI.h>
33#include "SensorQMI8658.hpp"
34#ifdef ARDUINO_T_BEAM_S3_SUPREME
35#include <XPowersAXP2101.tpp> //PMU Library https://github.com/lewisxhe/XPowersLib.git
36#endif
37
38
39// #define USE_I2C //Using the I2C interface
40
41#ifdef USE_I2C
42#ifndef SENSOR_SDA
43#define SENSOR_SDA 17
44#endif
45
46#ifndef SENSOR_SCL
47#define SENSOR_SCL 18
48#endif
49
50#else /* SPI interface */
51
52#ifndef SPI_MOSI
53#define SPI_MOSI (35)
54#endif
55
56#ifndef SPI_SCK
57#define SPI_SCK (36)
58#endif
59
60#ifndef SPI_MISO
61#define SPI_MISO (37)
62#endif
63
64#ifndef IMU_CS
65#define IMU_CS 34 // IMU CS PIN
66#endif
67
68#endif /* USE_I2C*/
69
70
71#ifndef IMU_IRQ
72#define IMU_IRQ 33 // IMU INT PIN
73#endif
74
75#ifndef OLED_SDA
76#define OLED_SDA 22 // Display Wire SDA Pin
77#endif
78
79#ifndef OLED_SCL
80#define OLED_SCL 21 // Display Wire SCL Pin
81#endif
82
83
85
86const uint16_t buffer_size = 128;
89bool disable_fifo = false;
90uint32_t timestamp = 0;
91
93{
94 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
95#if defined(ARDUINO_T_BEAM_S3_SUPREME)
96 XPowersAXP2101 power;
97 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
98 power.disableALDO1();
99 power.disableALDO2();
100 delay(250);
101 power.setALDO1Voltage(3300); power.enableALDO1();
102 power.setALDO2Voltage(3300); power.enableALDO2();
103#endif
104}
105
106void setup()
107{
108 Serial.begin(115200);
109 while (!Serial);
110
111 beginPower();
112
113 beginPower();
114
115 bool ret = false;
116#ifdef USE_I2C
117 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
118#else
119#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
120 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
121#else
122 ret = qmi.begin(SPI, IMU_CS);
123#endif
124#endif
125
126 if (!ret) {
127 Serial.println("Failed to find QMI8658 - check your wiring!");
128 while (1) {
129 delay(1000);
130 }
131 }
132
133 /*
134 * Get chip id
135 * */
136 Serial.print("Device ID:"); Serial.println(qmi.getChipID(), HEX);
137
138
140 /*
141 * ACC_RANGE_2G
142 * ACC_RANGE_4G
143 * ACC_RANGE_8G
144 * ACC_RANGE_16G
145 * */
147 /*
148 * ACC_ODR_1000H
149 * ACC_ODR_500Hz
150 * ACC_ODR_250Hz
151 * ACC_ODR_125Hz
152 * ACC_ODR_62_5Hz
153 * ACC_ODR_31_25Hz
154 * ACC_ODR_LOWPOWER_128Hz
155 * ACC_ODR_LOWPOWER_21Hz
156 * ACC_ODR_LOWPOWER_11Hz
157 * ACC_ODR_LOWPOWER_3H
158 * */
160 /*
161 * LPF_MODE_0 //2.66% of ODR
162 * LPF_MODE_1 //3.63% of ODR
163 * LPF_MODE_2 //5.39% of ODR
164 * LPF_MODE_3 //13.37% of ODR
165 * LPF_OFF // OFF Low-Pass Fitter
166 * */
168
169
170
171
173 /*
174 * GYR_RANGE_16DPS
175 * GYR_RANGE_32DPS
176 * GYR_RANGE_64DPS
177 * GYR_RANGE_128DPS
178 * GYR_RANGE_256DPS
179 * GYR_RANGE_512DPS
180 * GYR_RANGE_1024DPS
181 * */
183 /*
184 * GYR_ODR_7174_4Hz
185 * GYR_ODR_3587_2Hz
186 * GYR_ODR_1793_6Hz
187 * GYR_ODR_896_8Hz
188 * GYR_ODR_448_4Hz
189 * GYR_ODR_224_2Hz
190 * GYR_ODR_112_1Hz
191 * GYR_ODR_56_05Hz
192 * GYR_ODR_28_025Hz
193 * */
195 /*
196 * LPF_MODE_0 //2.66% of ODR
197 * LPF_MODE_1 //3.63% of ODR
198 * LPF_MODE_2 //5.39% of ODR
199 * LPF_MODE_3 //13.37% of ODR
200 * LPF_OFF // OFF Low-Pass Fitter
201 * */
203
204
205
207 /*
208 * FIFO_MODE_BYPASS -- Disable FIFO
209 * FIFO_MODE_FIFO -- Will not overwrite
210 * FIFO_MODE_STREAM -- Cover
211 */
213 /*
214 * FIFO_SAMPLES_16
215 * FIFO_SAMPLES_32
216 * FIFO_SAMPLES_64
217 * FIFO_SAMPLES_128
218 * */
220
221
222 /*
223 * INTERRUPT_PIN_1,
224 * INTERRUPT_PIN_2,
225 * INTERRUPT_PIN_DISABLE
226 * * */
227 SensorQMI8658::INTERRUPT_PIN_1, //*Route FIFO interrupt to INT1 Pin
228
229 //* Number of samples to trigger interrupt
230 16
231 );
232
233
234 /*
235 * If both the accelerometer and gyroscope sensors are turned on at the same time,
236 * the output frequency will be based on the gyroscope output frequency.
237 * The example configuration is 896.8HZ output frequency,
238 * so the acceleration output frequency is also limited to 896.8HZ
239 * */
240
242
244
245
246
247#if IMU_IRQ > 0
248 // If you want to enable interrupts, then turn on the interrupt enable
251#endif
252
253
254 delay(3000);
255
256
257 Serial.println("Read data now...");
258
259
260 // Close FIFO after sampling for 5 seconds
261 timestamp = millis() + 5000;
262}
263
264
265void loop()
266{
267 if (disable_fifo) {
268 return ;
269 }
270
271 if (millis() > timestamp) {
272 disable_fifo = true;
273 // Disable FIFO
275 Serial.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>> Disable FIFO...");
276 }
277
278 // Get the number of samples from the FIFO
279 uint16_t samples_num = qmi.readFromFifo(accel, buffer_size, gyro, buffer_size);
280 if (samples_num == 0) {
281 return;
282 }
283
284 Serial.print("--------------[");
285 Serial.print(millis());
286 Serial.print("]:data size:");
287 Serial.print(samples_num);
288 Serial.println("--------------");
289
290 for (int i = 0; i < buffer_size; ++i) {
291
292 Serial.print('[');
293 Serial.print(i);
294 Serial.println(']');
295
297 Serial.print("\t ACCEL.x:"); Serial.print(accel[i].x); Serial.println(" m2/s");
298 Serial.print("\t ACCEL.y:"); Serial.print(accel[i].y); Serial.println(" m2/s");
299 Serial.print("\t ACCEL.z:"); Serial.print(accel[i].z); Serial.println(" m2/s");
300 }
301
302
303 if (qmi.isEnableGyroscope()) {
304 Serial.print("\t GYRO.x:"); Serial.print(gyro[i].x); Serial.println(" degrees/sec");
305 Serial.print("\t GYRO.y:"); Serial.print(gyro[i].y); Serial.println(" degrees/sec");
306 Serial.print("\t GYRO.z:"); Serial.print(gyro[i].z); Serial.println(" degrees/sec");
307 }
308 }
309}
310
311
312
#define SENSOR_SCL
#define SENSOR_SDA
bool begin(CommInterface interface, SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr=0)
Initialize the sensor using custom callback interface.
QMI8658 IMU sensor driver class.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
void enableINT(IntPin pin, bool enable=true)
Enable or disable the interrupt.
uint16_t readFromFifo(AccelerometerData *accel_data, uint16_t accel_count, GyroscopeData *gyro_data, uint16_t gyro_count) override
Read data from FIFO buffer.
bool configAccelerometer(AccelRange range, AccelODR odr, LpfMode lpfOdr=LPF_MODE_0)
Configure the accelerometer.
bool configGyroscope(GyroRange range, GyroODR odr, LpfMode lpfOdr=LPF_MODE_0)
Configure the gyroscope.
bool isEnableAccelerometer()
Check if the accelerometer is enabled.
bool isEnableGyroscope()
Check if the gyroscope is enabled.
bool configFIFO(FIFO_Mode mode, FIFO_Samples samples=FIFO_SAMPLES_16, IntPin pin=INTERRUPT_PIN_DISABLE, uint8_t trigger_samples=16)
Configure the FIFO.
bool enableGyroscope()
Enable the gyroscope.
bool enableAccelerometer()
Enable the accelerometer.
uint8_t i
IMUdata gyro[buffer_size]
const uint16_t buffer_size
IMUdata accel[buffer_size]
int16_t x[5]
int16_t y[5]