SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_wake_on_motion_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}
97
99{
100 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
101#if defined(ARDUINO_T_BEAM_S3_SUPREME)
102 XPowersAXP2101 power;
103 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
104 power.disableALDO1();
105 power.disableALDO2();
106 delay(250);
107 power.setALDO1Voltage(3300); power.enableALDO1();
108 power.setALDO2Voltage(3300); power.enableALDO2();
109#endif
110}
111
112void setup()
113{
114 Serial.begin(115200);
115 while (!Serial);
116
117 beginPower();
118
119 bool ret = false;
120#ifdef USE_I2C
121 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
122#else
123#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
124 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
125#else
126 ret = qmi.begin(SPI, IMU_CS);
127#endif
128#endif
129
130 if (!ret) {
131 Serial.println("Failed to find QMI8658 - check your wiring!");
132 while (1) {
133 delay(1000);
134 }
135 }
136
137 /* Get chip id*/
138 Serial.print("Device ID:");
139 Serial.println(qmi.getChipID(), HEX);
140
141 // enabling wake on motion low power mode with a threshold of 120 mg and
142 // an accelerometer data rate of 128 Hz.
144
145 /*
146 * When the QMI8658 is configured as Wom, the interrupt level is arbitrary,
147 * not absolute high or low, and it is in the jump transition state
148 */
149 pinMode(IMU_IRQ, INPUT_PULLUP);
150
151 attachInterrupt(IMU_IRQ, setFlag, CHANGE);
152
153 // Print register configuration information
155}
156
157
158void loop()
159{
160
161 if (interruptFlag) {
162 interruptFlag = false;
163 uint8_t status = qmi.getStatusRegister();
164 Serial.print("STATUS:"); Serial.print(status);
165 Serial.print(" BIN:"); Serial.println(status, BIN);
166
168 Serial.println("EVENT_SIGNIFICANT_MOTION");
169 } else if (status & SensorQMI8658::EVENT_NO_MOTION) {
170 Serial.println("EVENT_NO_MOTION");
171 } else if (status & SensorQMI8658::EVENT_ANY_MOTION) {
172 Serial.println("EVENT_ANY_MOTION");
173 } else if (status & SensorQMI8658::EVENT_PEDOMETER_MOTION) {
174 Serial.println("EVENT_PEDOMETER_MOTION");
175 } else if (status & SensorQMI8658::EVENT_WOM_MOTION) {
176 Serial.println("EVENT_WOM_MOTION");
177 } else if (status & SensorQMI8658::EVENT_TAP_MOTION) {
178 Serial.println("EVENT_TAP_MOTION");
179 }
180 }
181}
182
183
184
#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.
int getStatusRegister()
Get the Pedometer counter.
bool configWakeOnMotion(uint8_t threshold=200, float odr_hz=128.0f, IntPin pin=IntPin::PIN2)
Configure wake-on-motion (WoM) feature.