SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_get_data_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#endif /* USE_I2C*/
65
66#ifndef IMU_CS
67#define IMU_CS 34 // IMU CS PIN
68#endif
69
70#ifndef IMU_IRQ
71#define IMU_IRQ 33 // IMU INT PIN
72#endif
73
74#ifndef OLED_SDA
75#define OLED_SDA 22 // Display Wire SDA Pin
76#endif
77
78#ifndef OLED_SCL
79#define OLED_SCL 21 // Display Wire SCL Pin
80#endif
81
82
84
87
88
90{
91 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
92#if defined(ARDUINO_T_BEAM_S3_SUPREME)
93 XPowersAXP2101 power;
94 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
95 power.disableALDO1();
96 power.disableALDO2();
97 delay(250);
98 power.setALDO1Voltage(3300); power.enableALDO1();
99 power.setALDO2Voltage(3300); power.enableALDO2();
100#endif
101}
102
103void setup()
104{
105 Serial.begin(115200);
106 while (!Serial);
107
108 beginPower();
109
110 bool ret = false;
111#ifdef USE_I2C
112 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
113#else
114#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
115 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
116#else
117 ret = qmi.begin(SPI, IMU_CS);
118#endif
119#endif
120
121 if (!ret) {
122 Serial.println("Failed to find QMI8658 - check your wiring!");
123 while (1) {
124 delay(1000);
125 }
126 }
127
128 /* Get chip id*/
129 Serial.print("Device ID:");
130 Serial.println(qmi.getChipID(), HEX);
131
132
133 if (qmi.selfTestAccel()) {
134 Serial.println("Accelerometer self-test successful");
135 } else {
136 Serial.println("Accelerometer self-test failed!");
137 }
138
139 if (qmi.selfTestGyro()) {
140 Serial.println("Gyroscope self-test successful");
141 } else {
142 Serial.println("Gyroscope self-test failed!");
143 }
144
145
147 /*
148 * ACC_RANGE_2G
149 * ACC_RANGE_4G
150 * ACC_RANGE_8G
151 * ACC_RANGE_16G
152 * */
154 /*
155 * ACC_ODR_1000H
156 * ACC_ODR_500Hz
157 * ACC_ODR_250Hz
158 * ACC_ODR_125Hz
159 * ACC_ODR_62_5Hz
160 * ACC_ODR_31_25Hz
161 * ACC_ODR_LOWPOWER_128Hz
162 * ACC_ODR_LOWPOWER_21Hz
163 * ACC_ODR_LOWPOWER_11Hz
164 * ACC_ODR_LOWPOWER_3H
165 * */
167 /*
168 * LPF_MODE_0 //2.66% of ODR
169 * LPF_MODE_1 //3.63% of ODR
170 * LPF_MODE_2 //5.39% of ODR
171 * LPF_MODE_3 //13.37% of ODR
172 * LPF_OFF // OFF Low-Pass Fitter
173 * */
175
176
177
178
180 /*
181 * GYR_RANGE_16DPS
182 * GYR_RANGE_32DPS
183 * GYR_RANGE_64DPS
184 * GYR_RANGE_128DPS
185 * GYR_RANGE_256DPS
186 * GYR_RANGE_512DPS
187 * GYR_RANGE_1024DPS
188 * */
190 /*
191 * GYR_ODR_7174_4Hz
192 * GYR_ODR_3587_2Hz
193 * GYR_ODR_1793_6Hz
194 * GYR_ODR_896_8Hz
195 * GYR_ODR_448_4Hz
196 * GYR_ODR_224_2Hz
197 * GYR_ODR_112_1Hz
198 * GYR_ODR_56_05Hz
199 * GYR_ODR_28_025H
200 * */
202 /*
203 * LPF_MODE_0 //2.66% of ODR
204 * LPF_MODE_1 //3.63% of ODR
205 * LPF_MODE_2 //5.39% of ODR
206 * LPF_MODE_3 //13.37% of ODR
207 * LPF_OFF // OFF Low-Pass Fitter
208 * */
210
211
212
213
214 /*
215 * If both the accelerometer and gyroscope sensors are turned on at the same time,
216 * the output frequency will be based on the gyroscope output frequency.
217 * The example configuration is 896.8HZ output frequency,
218 * so the acceleration output frequency is also limited to 896.8HZ
219 * */
222
223 // Print register configuration information
225
226
227
228#if IMU_IRQ > 0
229 // If you want to enable interrupts, then turn on the interrupt enable
232#endif
233
234 Serial.println("Read data now...");
235
236}
237
238
239void loop()
240{
241 // When the interrupt pin is passed in through setPin,
242 // the GPIO will be read to see if the data is ready.
243 if (qmi.getDataReady()) {
244
245 // Serial.print("Timestamp:");
246 // Serial.print(qmi.getTimestamp());
247
248 if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) {
249
250 // Print to serial plotter
251 Serial.print("ACCEL.x:"); Serial.print(acc.x); Serial.print(",");
252 Serial.print("ACCEL.y:"); Serial.print(acc.y); Serial.print(",");
253 Serial.print("ACCEL.z:"); Serial.print(acc.z); Serial.println();
254
255 /*
256 m2/s to mg
257 Serial.print(" ACCEL.x:"); Serial.print(acc.x * 1000); Serial.println(" mg");
258 Serial.print(",ACCEL.y:"); Serial.print(acc.y * 1000); Serial.println(" mg");
259 Serial.print(",ACCEL.z:"); Serial.print(acc.z * 1000); Serial.println(" mg");
260 */
261
262 }
263
264 if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) {
265
266
267 // Print to serial plotter
268 Serial.print("GYRO.x:"); Serial.print(gyr.x); Serial.print(",");
269 Serial.print("GYRO.y:"); Serial.print(gyr.y); Serial.print(",");
270 Serial.print("GYRO.z:"); Serial.print(gyr.z); Serial.println();
271
272
273 // Serial.print(" GYRO.x:"); Serial.print(gyr.x); Serial.println(" degrees/sec");
274 // Serial.print(",GYRO.y:"); Serial.print(gyr.y); Serial.println(" degrees/sec");
275 // Serial.print(",GYRO.z:"); Serial.print(gyr.z); Serial.println(" degrees/sec");
276
277 }
278
279 // Serial.print("Temperature:");
280 // Serial.print(qmi.getTemperature_C());
281 // Serial.println(" degrees C");
282
283 }
284 // delay(100);
285}
286
287
288
#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.
bool getGyroscope(float &x, float &y, float &z)
Get the raw gyroscope data.
void dumpCtrlRegister()
Dump the control register values.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
void enableINT(IntPin pin, bool enable=true)
Enable or disable the interrupt.
bool selfTestGyro()
Perform gyroscope self-test.
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 enableGyroscope()
Enable the gyroscope.
bool enableAccelerometer()
Enable the accelerometer.
bool getDataReady()
Check if new data is available.
bool selfTestAccel()
Perform accelerometer self-test.
bool getAccelerometer(float &x, float &y, float &z)
Get the accelerometer data.
SensorQMI8658 qmi