SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_interrupt_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// #define IMU_IRQ2 -1 //QMI IRQ NUM2
83
85
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
133 /*
134 * ACC_RANGE_2G
135 * ACC_RANGE_4G
136 * ACC_RANGE_8G
137 * ACC_RANGE_16G
138 * */
140 /*
141 * ACC_ODR_1000H
142 * ACC_ODR_500Hz
143 * ACC_ODR_250Hz
144 * ACC_ODR_125Hz
145 * ACC_ODR_62_5Hz
146 * ACC_ODR_31_25Hz
147 * ACC_ODR_LOWPOWER_128Hz
148 * ACC_ODR_LOWPOWER_21Hz
149 * ACC_ODR_LOWPOWER_11Hz
150 * ACC_ODR_LOWPOWER_3H
151 * */
153 /*
154 * LPF_MODE_0 //2.66% of ODR
155 * LPF_MODE_1 //3.63% of ODR
156 * LPF_MODE_2 //5.39% of ODR
157 * LPF_MODE_3 //13.37% of ODR
158 * LPF_OFF // OFF Low-Pass Fitter
159 * */
161
162
164 /*
165 * GYR_RANGE_16DPS
166 * GYR_RANGE_32DPS
167 * GYR_RANGE_64DPS
168 * GYR_RANGE_128DPS
169 * GYR_RANGE_256DPS
170 * GYR_RANGE_512DPS
171 * GYR_RANGE_1024DPS
172 * */
174 /*
175 * GYR_ODR_7174_4Hz
176 * GYR_ODR_3587_2Hz
177 * GYR_ODR_1793_6Hz
178 * GYR_ODR_896_8Hz
179 * GYR_ODR_448_4Hz
180 * GYR_ODR_224_2Hz
181 * GYR_ODR_112_1Hz
182 * GYR_ODR_56_05Hz
183 * GYR_ODR_28_025H
184 * */
186 /*
187 * LPF_MODE_0 //2.66% of ODR
188 * LPF_MODE_1 //3.63% of ODR
189 * LPF_MODE_2 //5.39% of ODR
190 * LPF_MODE_3 //13.37% of ODR
191 * LPF_OFF // OFF Low-Pass Fitter
192 * */
194
195
196 /*
197 * If both the accelerometer and gyroscope sensors are turned on at the same time,
198 * the output frequency will be based on the gyroscope output frequency.
199 * The example configuration is 896.8HZ output frequency,
200 * so the acceleration output frequency is also limited to 896.8HZ
201 * */
204
205
206 pinMode(IMU_IRQ, INPUT);
207
208#ifdef IMU_IRQ2
209 pinMode(IMU_IRQ2, INPUT);
210#endif
211 // qmi.enableINT(SensorQMI8658::INTERRUPT_PIN_1); //no use
212 // Enable data ready to interrupt pin2
215
216 // Print register configuration information
218
219 Serial.println("Read data now...");
220}
221
222void readSensorData(const char *name)
223{
224 uint8_t status = qmi.getIrqStatus();
225 // status == 0x01
226 // If syncSmpl (CTRL7.bit7) = 1:
227 // 0: Sensor Data is not available
228 // 1: Sensor Data is available for reading
229 // If syncSmpl = 0, this bit shows the same value of INT2 level
230 Serial.print(name);
231 Serial.print(" -> [");
232 Serial.print(millis());
233 Serial.print("]: -<HEX> ");
234 Serial.print(status);
235 Serial.print(" -<BIN> ");
236 Serial.println(status, BIN);
237 if (status & 0x01) {
238 if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) {
239 Serial.print("{ACCEL: ");
240 Serial.print(acc.x);
241 Serial.print(",");
242 Serial.print(acc.y);
243 Serial.print(",");
244 Serial.print(acc.z);
245 Serial.println("}");
246 }
247
248 if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) {
249 Serial.print("{GYRO: ");
250 Serial.print(gyr.x);
251 Serial.print(",");
252 Serial.print(gyr.y );
253 Serial.print(",");
254 Serial.print(gyr.z);
255 Serial.println("}");
256 }
257 Serial.print("\t\t\t\t > ");
258 Serial.print(qmi.getTimestamp());
259 Serial.print(" ");
260 Serial.print(qmi.getTemperature_C());
261 Serial.println("*C");
262 }
263
264}
265
266void loop()
267{
268 if (digitalRead(IMU_IRQ) == HIGH) {
269 readSensorData("INT1");
270 }
271
272#ifdef IMU_IRQ2
273 if (digitalRead(IMU_IRQ2) == HIGH) {
274 readSensorData("INT2");
275 }
276#endif
277}
278
279
280
281
#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.
float getTemperature_C()
Get the temperature in degree Celsius.
void dumpCtrlRegister()
Dump the control register values.
uint8_t getIrqStatus()
Get the IRQ status.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
void enableINT(IntPin pin, bool enable=true)
Enable or disable the interrupt.
void enableDataReadyINT(bool enable=true)
Enable or disable the Data Ready interrupt.
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.
uint32_t getTimestamp() override
Get the timestamp from the sensor.
bool enableAccelerometer()
Enable the accelerometer.
bool getAccelerometer(float &x, float &y, float &z)
Get the accelerometer data.
SensorQMI8658 qmi
void readSensorData(const char *name)