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);
118static void printAccelSample(
const char *tag)
122 serialPrintFmt(
"[%s] Accel: %7.3f %7.3f %7.3f\n",
130 Serial.begin(115200);
135 Serial.println(
"QMI8658 Self-Test Example");
137#ifdef USE_I2C_INTERFACE
139 Serial.println(
"Failed to initialize QMI8658!");
146#ifdef USE_SPI_INTERFACE
149 Serial.println(
"Failed to initialize QMI8658!");
158 Serial.println(
"\n=== Software Self-Test ===");
159 Serial.println(
"\n--- Accelerometer Self-Test ---");
161 Serial.println(
"Accelerometer self-test: PASSED");
163 Serial.println(
"Accelerometer self-test: FAILED");
166 Serial.println(
"\n--- Gyroscope Self-Test ---");
168 Serial.println(
"Gyroscope self-test: PASSED");
170 Serial.println(
"Gyroscope self-test: FAILED");
173 Serial.println(
"\n--- Combined Self-Test ---");
175 Serial.println(
"Combined self-test: PASSED");
177 Serial.println(
"Combined self-test: FAILED");
180 Serial.println(
"\n=== Hardware Self-Test ===");
181 Serial.println(
"Hardware self-test uses different methodology:");
182 Serial.println(
"- Uses internal test structures in the sensors");
183 Serial.println(
"- Returns raw output values for verification");
184 Serial.println(
"- Can test accel and gyro independently");
186 Serial.println(
"\nRunning hardware self-test (accel only)...");
188 Serial.println(
"Hardware self-test accel: PASSED");
189 float accel_result[3], gyro_result[3];
191 serialPrintFmt(
"Accel ST results: X=%.1f Y=%.1f Z=%.1f mg\n",
192 accel_result[0], accel_result[1], accel_result[2]);
194 Serial.println(
"Hardware self-test accel: FAILED");
197 Serial.println(
"\nRunning hardware self-test (gyro only)...");
199 Serial.println(
"Hardware self-test gyro: PASSED");
200 float accel_result[3], gyro_result[3];
202 serialPrintFmt(
"Gyro ST results: X=%.1f Y=%.1f Z=%.1f dps\n",
203 gyro_result[0], gyro_result[1], gyro_result[2]);
205 Serial.println(
"Hardware self-test gyro: FAILED");
208 Serial.println(
"\nSelf-test notes from QMI8658X:");
209 Serial.println(
"- Self-test result is read from dVX/dVY/dVZ (0x51~0x56), not normal data registers.");
210 Serial.println(
"- Accel self-test threshold: |dV*| > 200mg on all three axes.");
211 Serial.println(
"- Gyro self-test threshold: |dV*| > 300dps on all three axes.");
212 Serial.println(
"- During self-test, device internally controls FS/ODR and restores CTRL2/CTRL3 afterward.");
218 Serial.println(
"WARNING: reset after self-test failed");
231 serialPrintFmt(
"Runtime config: accel=%s gyro=%s enableA=%s enableG=%s\n",
232 cfgA ?
"OK" :
"FAIL",
233 cfgG ?
"OK" :
"FAIL",
235 enG ?
"OK" :
"FAIL");
241 int irq = digitalPinToInterrupt(
IMU_IRQ);
243 attachInterrupt(irq, +[]() {
246 serialPrintFmt(
"IRQ attached on pin %d (CHANGE trigger)\n",
IMU_IRQ);
248 serialPrintFmt(
"IRQ pin %d has no interrupt mapping, polling only\n",
IMU_IRQ);
251 Serial.println(
"\nData-ready interrupt enabled on INT2 (PIN2). Waiting for IRQ...");
252 Serial.println(
"Note: DRDY requires FIFO bypass mode; enabling FIFO will disable DRDY.");
253 Serial.println(
"Note: If your board only wires INT1, DRDY IRQ will not arrive; polling output is used.");
254 serialPrintFmt(
"DRDY enable result: %s\n", drdy_ok ?
"OK" :
"FAIL");
255 Serial.println(
"If no IRQ is seen, example will fallback to polling output.");
269 printAccelSample(
"IRQ");
274 printAccelSample(
"POLL");
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 reset() override
Reset the IMU sensor to its default state.
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 selfTestGyro()
Perform gyroscope self-test.
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 selfTest() override
Perform self-test on the IMU sensor.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
uint16_t update()
Update sensor status and process events.
void getHardwareSelfTestResults(float accel_result[3], float gyro_result[3])
Get hardware self-test results.
void setPins(int pin)
Set interrupt pin.
bool hardwareSelfTest(bool includeAccel=true, bool includeGyro=true)
Perform hardware self-test on both sensors.
bool selfTestAccel()
Perform accelerometer self-test.
IMUdata accel[buffer_size]
volatile bool isInterruptTriggered
Structure representing accelerometer data.