48#if !defined(USE_I2C_INTERFACE) && !defined(USE_SPI_INTERFACE)
49#define USE_I2C_INTERFACE
52#if defined(USE_SPI_INTERFACE)
86#ifdef ARDUINO_T_BEAM_S3_SUPREME
87#include <XPowersAXP2101.tpp>
90static void serialPrintFmt(
const char *fmt, ...)
95 vsnprintf(
buf,
sizeof(
buf), fmt, args);
102#if defined(ARDUINO_T_BEAM_S3_SUPREME)
103 XPowersAXP2101 power;
104 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
105 power.disableALDO1();
106 power.disableALDO2();
108 power.setALDO1Voltage(3300);
110 power.setALDO2Voltage(3300);
121 Serial.
begin(115200);
126 Serial.println(
"QMI8658 Advanced Features Example");
128#ifdef USE_I2C_INTERFACE
130 Serial.println(
"Failed to initialize QMI8658!");
137#ifdef USE_SPI_INTERFACE
140 Serial.println(
"Failed to initialize QMI8658!");
147 Serial.println(
"\n=== Hardware Self-Test ===");
148 Serial.println(
"Running hardware self-test...");
150 Serial.println(
"Hardware self-test: PASSED");
151 float accel_result[3], gyro_result[3];
153 serialPrintFmt(
"Accel ST results: X=%.1f Y=%.1f Z=%.1f mg\n",
154 accel_result[0], accel_result[1], accel_result[2]);
155 serialPrintFmt(
"Gyro ST results: X=%.1f Y=%.1f Z=%.1f dps\n",
156 gyro_result[0], gyro_result[1], gyro_result[2]);
158 Serial.println(
"Hardware self-test: FAILED");
161 Serial.println(
"\n=== Helper Configuration Functions ===");
162 Serial.println(
"configMotionDetectDefault() - Auto-configure motion detection");
164 Serial.println(
"configTapDefault() - Auto-configure tap detection");
166 Serial.println(
"configPedometerDefault(125) - Auto-configure pedometer at 125Hz");
168 Serial.println(
"Helper functions configured successfully!\n");
170 Serial.println(
"\n=== Axis Layout Configuration ===");
171 Serial.println(
"Current layout: DEFAULT");
175 Serial.println(
"\nSupported layouts:");
176 Serial.println(
" 0 = DEFAULT (X=right, Y=forward, Z=up)");
177 Serial.println(
" 1 = ROTATE_90 (X=forward, Y=left, Z=up)");
178 Serial.println(
" 2 = ROTATE_180 (X=left, Y=backward, Z=up)");
179 Serial.println(
" 3 = ROTATE_270 (X=backward, Y=right, Z=up)");
180 Serial.println(
" 4 = FLIP_Z (X=right, Y=backward, Z=down)");
181 Serial.println(
" 5 = FLIP_Z_90 (X=backward, Y=left, Z=down)");
182 Serial.println(
" 6 = FLIP_Z_180 (X=left, Y=forward, Z=down)");
183 Serial.println(
" 7 = FLIP_Z_270 (X=forward, Y=right, Z=down)");
185 Serial.println(
"\n=== Static Calibration ===");
186 Serial.println(
"Place sensor in stable position and keep it still!");
187 Serial.println(
"Static calibration will run for ~100 samples (blocking)...");
203 uint32_t cali_start = millis();
204 uint32_t last_progress = 0;
213 uint32_t now = millis();
214 if (now - last_progress >= 250) {
219 if (now - cali_start > 10000) {
220 Serial.println(
"\nStatic calibration timeout, continue with current offsets.");
226 int16_t accel_offset[3], gyro_offset[3];
228 Serial.println(
"\nStatic calibration done.");
229 serialPrintFmt(
"Static Cal Offsets - Accel: %d %d %d Gyro: %d %d %d\n",
230 accel_offset[0], accel_offset[1], accel_offset[2],
231 gyro_offset[0], gyro_offset[1], gyro_offset[2]);
233 Serial.println(
"\n=== Dynamic Gyroscope Calibration ===");
234 Serial.println(
"Dynamic gyro calibration enabled.");
235 Serial.println(
"Offsets will be updated when sensor is stationary.");
238 Serial.println(
"\n=== Data Output ===");
239 Serial.println(
"Accel(m/s2) | Gyro(dps) | Calibrated");
240 Serial.println(
"X Y Z | X Y Z | Accel Gyro");
251 serialPrintFmt(
"%7.3f %7.3f %7.3f | %7.3f %7.3f %7.3f | %s %s\n",
258 int16_t accel_offset[3], gyro_offset[3];
260 serialPrintFmt(
"\nStatic Cal Offsets - Accel: %d %d %d Gyro: %d %d %d\n",
261 accel_offset[0], accel_offset[1], accel_offset[2],
262 gyro_offset[0], gyro_offset[1], gyro_offset[2]);
264 int16_t dyn_gyro_offset[3];
266 serialPrintFmt(
"Dynamic Gyro Offsets: %d %d %d\n",
267 dyn_gyro_offset[0], dyn_gyro_offset[1], dyn_gyro_offset[2]);
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.
void getStaticCalibrationOffsets(int16_t accel_offset[3], int16_t gyro_offset[3])
Get static calibration offsets.
bool isDataReady(uint8_t mask=static_cast< uint8_t >(ImuBase::DataReadyMask::BOTH)) override
Check if requested IMU data is available.
bool configMotionDetectDefault(MotionType type)
Configure motion detection with default parameters.
bool enableAccel() override
Enable the accelerometer.
bool isStaticCalibrationComplete() const
Get the current static calibration status.
void enableStaticCalibration(bool enable)
Start static calibration.
bool readAccel(AccelerometerData &out) override
Read accelerometer data.
void getDynamicGyroCalibrationOffsets(int16_t gyro_offset[3])
Get dynamic gyroscope calibration offsets.
bool enableGyro() override
Enable the gyroscope.
void enableDynamicGyroCalibration(bool enable)
Enable dynamic gyroscope calibration.
Layout getAxisLayout() const
Get the current axis layout setting.
bool isDynamicGyroCalibrationEnabled() const
Check if dynamic gyro calibration is enabled.
@ ANY_MOTION
Any motion detection.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
void getHardwareSelfTestResults(float accel_result[3], float gyro_result[3])
Get hardware self-test results.
bool configTapDefault(TapPriority priority=TapPriority::X_GT_Y_GT_Z)
Configure tap detection with default parameters.
bool configPedometerDefault(float odr=125.0f)
Configure pedometer with default parameters.
bool hardwareSelfTest(bool includeAccel=true, bool includeGyro=true)
Perform hardware self-test on both sensors.
void setAxisLayout(Layout layout)
Set the sensor axis layout for coordinate transformation.
@ LAYOUT_DEFAULT
Default orientation: X=right, Y=forward, Z=up.
IMUdata gyro[buffer_size]
IMUdata accel[buffer_size]
Structure representing accelerometer data.
Structure representing gyroscope data.