49#if !defined(USE_I2C_INTERFACE) && !defined(USE_SPI_INTERFACE)
50#define USE_I2C_INTERFACE
53#if defined(USE_SPI_INTERFACE)
87#ifdef ARDUINO_T_BEAM_S3_SUPREME
88#include <XPowersAXP2101.tpp>
91static void serialPrintFmt(
const char *fmt, ...)
96 vsnprintf(
buf,
sizeof(
buf), fmt, args);
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();
109 power.setALDO1Voltage(3300);
111 power.setALDO2Voltage(3300);
121 Serial.
begin(115200);
126 Serial.println(
"QMI8658 Calibration 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!");
162 Serial.println(
"\n=== On-Demand Calibration ===");
163 Serial.println(
"\n--- Before Calibration ---");
164 for (
int i = 0;
i < 10; ++
i) {
167 serialPrintFmt(
"Gyro: %8.3f %8.3f %8.3f\n",
gyro.dps.
x,
gyro.dps.
y,
gyro.dps.
z);
171 Serial.println(
"\nStarting calibration... Please keep sensor motionless!");
174 uint16_t gyro_x, gyro_y, gyro_z;
176 Serial.println(
"Calibration successful!");
177 serialPrintFmt(
"Gyro gains - X: 0x%04X, Y: 0x%04X, Z: 0x%04X\n",
178 gyro_x, gyro_y, gyro_z);
183 Serial.println(
"Calibration gains applied!");
189 serialPrintFmt(
"Runtime re-enable: accel=%s gyro=%s\n", enA ?
"OK" :
"FAIL", enG ?
"OK" :
"FAIL");
191 Serial.println(
"Calibration failed!");
194 Serial.println(
"\n--- After Calibration ---");
195 for (
int i = 0;
i < 10; ++
i) {
198 serialPrintFmt(
"Gyro: %8.3f %8.3f %8.3f\n",
gyro.dps.
x,
gyro.dps.
y,
gyro.dps.
z);
202 Serial.println(
"\n=== Static Calibration (Software) ===");
203 Serial.println(
"Enable software-based static calibration:");
204 Serial.println(
"- Collects 100 samples when sensor is stationary");
205 Serial.println(
"- Calculates accelerometer and gyroscope offsets");
208 Serial.println(
"\n=== Dynamic Gyro Calibration ===");
209 Serial.println(
"Enable dynamic gyroscope calibration:");
210 Serial.println(
"- Continuously updates offsets when stationary detected");
211 Serial.println(
"- Uses accelerometer variance to detect stillness");
214 Serial.println(
"\nWaiting for static calibration to complete (about 10s @100ms loop)...");
216 Serial.println(
"\nCalibration complete. Data is now being processed.");
221 static uint32_t failCount = 0;
227 int16_t accelOff[3], gyroOff[3];
229 serialPrintFmt(
"[CAL] Static calibration complete. Gyro offsets: %d %d %d\n",
230 gyroOff[0], gyroOff[1], gyroOff[2]);
233 serialPrintFmt(
"Gyro: %8.3f %8.3f %8.3f\n",
gyro.dps.
x,
gyro.dps.
y,
gyro.dps.
z);
236 if ((failCount % 20) == 1) {
238 serialPrintFmt(
"[WARN] readGyro failed (%lu), trying enableGyro: %s\n",
239 static_cast<unsigned long>(failCount), enG ?
"OK" :
"FAIL");
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 enableAccel() override
Enable the accelerometer.
bool isStaticCalibrationComplete() const
Get the current static calibration status.
void enableStaticCalibration(bool enable)
Start static calibration.
bool enableGyro() override
Enable the gyroscope.
void enableDynamicGyroCalibration(bool enable)
Enable dynamic gyroscope calibration.
bool calibrate(uint16_t *gyro_x_gain=nullptr, uint16_t *gyro_y_gain=nullptr, uint16_t *gyro_z_gain=nullptr)
Perform on-demand calibration.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
bool writeCalibration(uint16_t gyro_x_gain, uint16_t gyro_y_gain, uint16_t gyro_z_gain)
Write previously saved gyro calibration gains.
bool staticCalDonePrinted
IMUdata gyro[buffer_size]
Structure representing gyroscope data.