SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_sync_mode.ino
Go to the documentation of this file.
1
40#include <stdarg.h>
41#include <ImuDrv.hpp>
42#include "DevicesPins.h"
43
44
45// Select one interface.
46// #define USE_I2C_INTERFACE
47// #define USE_SPI_INTERFACE
48
49#if !defined(USE_I2C_INTERFACE) && !defined(USE_SPI_INTERFACE)
50#define USE_I2C_INTERFACE
51#endif
52
53#if defined(USE_SPI_INTERFACE)
54
55#ifndef SPI_MOSI
56#define SPI_MOSI 35
57#endif
58
59#ifndef SPI_MISO
60#define SPI_MISO 37
61#endif
62
63#ifndef SPI_SCK
64#define SPI_SCK 36
65#endif
66
67#ifndef IMU_CS
68#define IMU_CS 34
69#endif
70
71#else
72
73#ifndef IMU_SDA
74#define IMU_SDA 17
75#endif
76
77#ifndef IMU_SCL
78#define IMU_SCL 18
79#endif
80
81#endif
82
83#ifndef IMU_IRQ
84#define IMU_IRQ 33
85#endif
86
87#ifdef ARDUINO_T_BEAM_S3_SUPREME
88#include <XPowersAXP2101.tpp>
89#endif
90
91static void serialPrintFmt(const char *fmt, ...)
92{
93 char buf[256];
94 va_list args;
95 va_start(args, fmt);
96 vsnprintf(buf, sizeof(buf), fmt, args);
97 va_end(args);
98 Serial.print(buf);
99}
100
102{
103#if defined(ARDUINO_T_BEAM_S3_SUPREME)
104 XPowersAXP2101 power;
105 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
106 power.disableALDO1();
107 power.disableALDO2();
108 delay(250);
109 power.setALDO1Voltage(3300);
110 power.enableALDO1();
111 power.setALDO2Voltage(3300);
112 power.enableALDO2();
113#endif
114}
115
117
118
119
121{
122 Serial.println("[SYNC] Data locked and ready!");
123}
124
125void setup()
126{
127 Serial.begin(115200);
128 while (!Serial);
129
130 setupPower();
131
132 Serial.println("QMI8658 Synchronous Mode Example");
133
134#ifdef USE_I2C_INTERFACE
135 if (!imu.begin(Wire, QMI8658_H_SLAVE_ADDRESS, IMU_SDA, IMU_SCL)) {
136 Serial.println("Failed to initialize QMI8658!");
137 while (1) {
138 delay(1000);
139 }
140 }
141#endif
142
143#ifdef USE_SPI_INTERFACE
144 // Using SPI interface
145 if (!imu.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK)) {
146 Serial.println("Failed to initialize QMI8658!");
147 while (1) {
148 delay(1000);
149 }
150 }
151#endif
152
154
155 // Accelerometer: FS_2G(000), FS_4G(001), FS_8G(010), FS_16G(011)
156 // ODR: 1000, 500, 250, 125, 62.5, 31.25, 128, 21, 11, 3 Hz (6DOF: 448/224/112/56/28 Hz)
158 1000.0f);
159
160 // Gyroscope: FS_125_DPS, FS_250_DPS, FS_500_DPS, FS_1000_DPS, FS_2000_DPS, FS_4000_DPS
161 // ODR: 7174/3587/1793/896/448/224/112/56/28 Hz
163 1000.0f);
164
166
168
169 // When ACC+GYR are both enabled, synchronized ODR base
170 // is derived from gyroscope natural frequency.
172 imu.enableGyro();
173
174 // In SyncSample mode, STATUSINT.bit1/bit0 reflect INT1/INT2 levels.
175 // DRDY routing rule to INT2 applies to Non-SyncSample mode only.
176 imu.enableDataReadyInterrupt(SensorQMI8658::IntPin::PIN2);
177
179
180 Serial.println("Synchronous mode enabled. Data is synchronized!");
181}
182
183void loop()
184{
185 if (imu.isDataReady()) {
188 uint32_t timestamp = imu.getTimestamp();
189
192
193 serialPrintFmt("[%u] Accel: %7.3f %7.3f %7.3f | Gyro: %8.3f %8.3f %8.3f\n",
194 timestamp,
195 accel.mps2.x, accel.mps2.y, accel.mps2.z,
196 gyro.dps.x, gyro.dps.y, gyro.dps.z);
197 }
198
199 delay(10);
200}
@license MIT License
@ FS_1000_DPS
±1000 °/s
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 configGyro(GyroFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the gyroscope with specified parameters.
bool readGyro(GyroscopeData &out) override
Read gyroscope data.
bool isDataReady(uint8_t mask=static_cast< uint8_t >(ImuBase::DataReadyMask::BOTH)) override
Check if requested IMU data is available.
void setDataLockingCallback(DataReadyCallback callback)
Set callback for data locking.
bool enableAccel() override
Enable the accelerometer.
bool enableSyncMode() override
Enable synchronous sampling mode.
bool readAccel(AccelerometerData &out) override
Read accelerometer data.
bool enableGyro() override
Enable the gyroscope.
bool enableDataReadyInterrupt(IntPin pin=IntPin::PIN2)
Enable data ready interrupt.
bool enableLockingMechanism()
Enable the data locking mechanism.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
uint32_t getTimestamp() override
Get the timestamp from the sensor.
void setPins(int pin)
Set interrupt pin.
char buf[64]
IMUdata gyro[buffer_size]
IMUdata accel[buffer_size]
void dataLockingCallback()
void setupPower()
void setup()
#define IMU_IRQ
#define IMU_SCL
SensorQMI8658 imu
#define IMU_SDA
void loop()
Structure representing accelerometer data.
Structure representing gyroscope data.