SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_wake_on_motion_callback_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
88
89
90bool interruptFlag = false;
91
92void setFlag(void)
93{
94 interruptFlag = true;
95}
96
97void wakeUp()
98{
99 Serial.println("Awake!");
100}
101
103{
104 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
105#if defined(ARDUINO_T_BEAM_S3_SUPREME)
106 XPowersAXP2101 power;
107 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
108 power.disableALDO1();
109 power.disableALDO2();
110 delay(250);
111 power.setALDO1Voltage(3300); power.enableALDO1();
112 power.setALDO2Voltage(3300); power.enableALDO2();
113#endif
114}
115
116void setup()
117{
118 Serial.begin(115200);
119 while (!Serial);
120
121 beginPower();
122
123 bool ret = false;
124#ifdef USE_I2C
125 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
126#else
127#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
128 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
129#else
130 ret = qmi.begin(SPI, IMU_CS);
131#endif
132#endif
133
134 if (!ret) {
135 Serial.println("Failed to find QMI8658 - check your wiring!");
136 while (1) {
137 delay(1000);
138 }
139 }
140
141 /* Get chip id*/
142 Serial.print("Device ID:");
143 Serial.println(qmi.getChipID(), HEX);
144
145 // enabling wake on motion low power mode with a threshold of 200 mg and
146 // an accelerometer data rate of 128 Hz.
148
149
151
152 /*
153 * When the QMI8658 is configured as Wom, the interrupt level is arbitrary,
154 * not absolute high or low, and it is in the jump transition state
155 */
156 pinMode(IMU_IRQ, INPUT_PULLUP);
157 attachInterrupt(IMU_IRQ, setFlag, CHANGE);
158
159 // Print register configuration information
161}
162
163
164void loop()
165{
166 if (interruptFlag) {
167 interruptFlag = false;
168 qmi.update();
169 }
170}
171
172
173
#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.
void dumpCtrlRegister()
Dump the control register values.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
void setWakeupMotionEventCallBack(EventCallBack_t cb)
uint16_t update()
Update sensor status and process events.
bool configWakeOnMotion(uint8_t threshold=200, float odr_hz=128.0f, IntPin pin=IntPin::PIN2)
Configure wake-on-motion (WoM) feature.