SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_locking_mechanism_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
84
87
88bool interruptFlag = false;
89
90void setFlag(void)
91{
92 interruptFlag = true;
93}
94
95// Callback when data is locked
97{
98 if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) {
99 Serial.print("{ACCEL: ");
100 Serial.print(acc.x);
101 Serial.print(",");
102 Serial.print(acc.y);
103 Serial.print(",");
104 Serial.print(acc.z);
105 Serial.println("}");
106 }
107
108 if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) {
109 Serial.print("{GYRO: ");
110 Serial.print(gyr.x);
111 Serial.print(",");
112 Serial.print(gyr.y );
113 Serial.print(",");
114 Serial.print(gyr.z);
115 Serial.println("}");
116 }
117 Serial.print("\t\t\t\t > ");
118 Serial.print(qmi.getTimestamp());
119 Serial.print(" ");
120 Serial.print(qmi.getTemperature_C());
121 Serial.println("*C");
122}
123
124
126{
127 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
128#if defined(ARDUINO_T_BEAM_S3_SUPREME)
129 XPowersAXP2101 power;
130 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
131 power.disableALDO1();
132 power.disableALDO2();
133 delay(250);
134 power.setALDO1Voltage(3300); power.enableALDO1();
135 power.setALDO2Voltage(3300); power.enableALDO2();
136#endif
137}
138
139void setup()
140{
141 Serial.begin(115200);
142 while (!Serial);
143
144 beginPower();
145
146 bool ret = false;
147#ifdef USE_I2C
148 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
149#else
150#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
151 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
152#else
153 ret = qmi.begin(SPI, IMU_CS);
154#endif
155#endif
156
157 if (!ret) {
158 Serial.println("Failed to find QMI8658 - check your wiring!");
159 while (1) {
160 delay(1000);
161 }
162 }
163 /* Get chip id*/
164 Serial.print("Device ID:");
165 Serial.println(qmi.getChipID(), HEX);
166
168 /*
169 * ACC_RANGE_2G
170 * ACC_RANGE_4G
171 * ACC_RANGE_8G
172 * ACC_RANGE_16G
173 * */
175 /*
176 * ACC_ODR_1000H
177 * ACC_ODR_500Hz
178 * ACC_ODR_250Hz
179 * ACC_ODR_125Hz
180 * ACC_ODR_62_5Hz
181 * ACC_ODR_31_25Hz
182 * ACC_ODR_LOWPOWER_128Hz
183 * ACC_ODR_LOWPOWER_21Hz
184 * ACC_ODR_LOWPOWER_11Hz
185 * ACC_ODR_LOWPOWER_3H
186 * */
188 /*
189 * LPF_MODE_0 //2.66% of ODR
190 * LPF_MODE_1 //3.63% of ODR
191 * LPF_MODE_2 //5.39% of ODR
192 * LPF_MODE_3 //13.37% of ODR
193 * LPF_OFF // OFF Low-Pass Fitter
194 * */
196
197
198
199
201 /*
202 * GYR_RANGE_16DPS
203 * GYR_RANGE_32DPS
204 * GYR_RANGE_64DPS
205 * GYR_RANGE_128DPS
206 * GYR_RANGE_256DPS
207 * GYR_RANGE_512DPS
208 * GYR_RANGE_1024DPS
209 * */
211 /*
212 * GYR_ODR_7174_4Hz
213 * GYR_ODR_3587_2Hz
214 * GYR_ODR_1793_6Hz
215 * GYR_ODR_896_8Hz
216 * GYR_ODR_448_4Hz
217 * GYR_ODR_224_2Hz
218 * GYR_ODR_112_1Hz
219 * GYR_ODR_56_05Hz
220 * GYR_ODR_28_025H
221 * */
223 /*
224 * LPF_MODE_0 //2.66% of ODR
225 * LPF_MODE_1 //3.63% of ODR
226 * LPF_MODE_2 //5.39% of ODR
227 * LPF_MODE_3 //13.37% of ODR
228 * LPF_OFF // OFF Low-Pass Fitter
229 * */
231
232 /*
233 * If both the accelerometer and gyroscope sensors are turned on at the same time,
234 * the output frequency will be based on the gyroscope output frequency.
235 * The example configuration is 896.8HZ output frequency,
236 * so the acceleration output frequency is also limited to 896.8HZ
237 * */
240
241 //Enable Locking Mechanism
243
244 // Set locking data event callback
246
247
248 // Use interrupt .
249 // QMI8658 interrupt always outputs low level by default,
250 // and the interrupt is triggered when the rising edge
251 pinMode(IMU_IRQ, INPUT_PULLUP);
252
253 attachInterrupt(IMU_IRQ, setFlag, RISING);
254
255 // qmi.enableINT(SensorQMI8658::INTERRUPT_PIN_1); //no use
256 // Enable data ready to interrupt pin2
258
259
260 // Print register configuration information
262
263
264 Serial.println("Read data now...");
265}
266
267
268void loop()
269{
270 if (interruptFlag) {
271 interruptFlag = false;
272 qmi.update();
273 }
274 delay(100);
275}
276
277
278
279
#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 getChipID() override
Get the chip ID / WHO_AM_I value.
void enableINT(IntPin pin, bool enable=true)
Enable or disable the interrupt.
bool enableLockingMechanism()
Enable the data locking mechanism.
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.
uint16_t update()
Update sensor status and process events.
bool enableGyroscope()
Enable the gyroscope.
uint32_t getTimestamp() override
Get the timestamp from the sensor.
void setDataLockingEventCallBack(EventCallBack_t cb)
bool enableAccelerometer()
Enable the accelerometer.
bool getAccelerometer(float &x, float &y, float &z)
Get the accelerometer data.