SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_basic_read.ino
Go to the documentation of this file.
1
41#include <stdarg.h>
42#include <ImuDrv.hpp>
43#include "DevicesPins.h"
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
120void setup()
121{
122 Serial.begin(115200);
123 while (!Serial);
124
125 setupPower();
126
127 Serial.println("QMI8658 Basic Read Example");
128
129#ifdef USE_I2C_INTERFACE
130 if (!imu.begin(Wire, QMI8658_H_SLAVE_ADDRESS, IMU_SDA, IMU_SCL)) {
131 Serial.println("Failed to initialize QMI8658!");
132 while (1) {
133 delay(1000);
134 }
135 }
136#endif
137
138#ifdef USE_SPI_INTERFACE
139 // Using SPI interface
140 if (!imu.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK)) {
141 Serial.println("Failed to initialize QMI8658!");
142 while (1) {
143 delay(1000);
144 }
145 }
146#endif
147
148 Serial.print("Firmware Version: 0x");
149 Serial.println(imu.getFirmwareVersion(), HEX);
150
151 // Accelerometer: FS_2G(000), FS_4G(001), FS_8G(010), FS_16G(011)
152 // ODR: 1000, 500, 250, 125, 62.5, 31.25, 128, 21, 11, 3 Hz (6DOF: 448/224/112/56/28 Hz)
154 1000.0f,
156
157 // Gyroscope: FS_125_DPS, FS_250_DPS, FS_500_DPS, FS_1000_DPS, FS_2000_DPS, FS_4000_DPS
158 // ODR: 7174/3587/1793/896/448/224/112/56/28 Hz
160 1000.0f,
162
163 // In 6DOF mode (ACC+GYR both enabled), synchronized ODR base
164 // is derived from gyroscope natural frequency.
166 imu.enableGyro();
167
168 Serial.println("\n--- Accelerometer & Gyroscope Data ---");
169 Serial.println("Format: ACCEL(m/s2) | GYRO(deg/s)");
170}
171
172void loop()
173{
174 if (imu.isDataReady(static_cast<uint8_t>(ImuBase::DataReadyMask::ACCEL))) {
177
180
181 serialPrintFmt("Accel: %7.3f %7.3f %7.3f | Gyro: %8.3f %8.3f %8.3f\n",
182 accel.mps2.x, accel.mps2.y, accel.mps2.z,
183 gyro.dps.x, gyro.dps.y, gyro.dps.z);
184 }
185
186 delay(10);
187}
@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.
bool enableAccel() override
Enable the accelerometer.
bool readAccel(AccelerometerData &out) override
Read accelerometer data.
bool enableGyro() override
Enable the gyroscope.
uint32_t getFirmwareVersion() override
Get the firmware version.
@ MODE_0
2.66% of output data rate
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
char buf[64]
void setupPower()
void setup()
#define IMU_SCL
SensorQMI8658 imu
#define IMU_SDA
void loop()
IMUdata gyro[buffer_size]
IMUdata accel[buffer_size]
Structure representing accelerometer data.
Structure representing gyroscope data.