### Personal Activity Classifier for Activity Detection Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt This example demonstrates how to use the Personal Activity Classifier (PAC) to detect user activities like walking, running, or cycling, providing confidence scores for each class. Ensure `SH2_PERSONAL_ACTIVITY_CLASSIFIER` is enabled. ```cpp #include Adafruit_BNO08x bno08x(-1); sh2_SensorValue_t sensorValue; const char* activityName(uint8_t id) { switch (id) { case PAC_UNKNOWN: return "Unknown"; case PAC_IN_VEHICLE: return "In Vehicle"; case PAC_ON_BICYCLE: return "On Bicycle"; case PAC_ON_FOOT: return "On Foot"; case PAC_STILL: return "Still"; case PAC_TILTING: return "Tilting"; case PAC_WALKING: return "Walking"; case PAC_RUNNING: return "Running"; case PAC_ON_STAIRS: return "On Stairs"; default: return "N/A"; } } void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_I2C()) { while(1) delay(10); } bno08x.enableReport(SH2_PERSONAL_ACTIVITY_CLASSIFIER); } void loop() { if (bno08x.wasReset()) bno08x.enableReport(SH2_PERSONAL_ACTIVITY_CLASSIFIER); if (!bno08x.getSensorEvent(&sensorValue)) return; if (sensorValue.sensorId == SH2_PERSONAL_ACTIVITY_CLASSIFIER) { auto &pac = sensorValue.un.personalActivityClassifier; Serial.print("Most likely: "); Serial.println(activityName(pac.mostLikelyState)); for (uint8_t i = 0; i < PAC_OPTION_COUNT; i++) { Serial.print(" "); Serial.print(activityName(i)); Serial.print(": "); Serial.println(pac.confidence[i]); } // Output: // Most likely: Walking // Unknown: 0 // In Vehicle: 2 // Walking: 91 // Running: 7 // ... } } ``` -------------------------------- ### begin_I2C Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Sets up the sensor on the I2C bus. The default address is `0x4A` (`BNO08x_I2CADDR_DEFAULT`). Returns `true` on success. After a successful call, `bno08x.prodIds` is populated with firmware version information. ```APIDOC ## begin_I2C(uint8_t i2c_addr = BNO08x_I2CADDR_DEFAULT, TwoWire *wire = &Wire, int32_t sensor_id = 0) ### Description Sets up the sensor on the I2C bus. The default address is `0x4A` (`BNO08x_I2CADDR_DEFAULT`). Returns `true` on success. After a successful call, `bno08x.prodIds` is populated with firmware version information. ### Parameters #### Path Parameters - **i2c_addr** (uint8_t) - Optional - The I2C address of the BNO08x sensor. Defaults to `BNO08x_I2CADDR_DEFAULT` (0x4A). - **wire** (TwoWire *) - Optional - Pointer to the I2C bus object. Defaults to `&Wire`. - **sensor_id** (int32_t) - Optional - An identifier for the sensor. Defaults to 0. ``` -------------------------------- ### begin_SPI Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Sets up the sensor using hardware SPI at 1 MHz, SPI mode 3. Requires a chip-select pin and an interrupt pin (INT). The INT pin is configured as `INPUT_PULLUP`. ```APIDOC ## begin_SPI(uint8_t cs_pin, uint8_t int_pin, SPIClass *theSPI = &SPI, int32_t sensor_id = 0) ### Description Sets up the sensor using hardware SPI at 1 MHz, SPI mode 3. Requires a chip-select pin and an interrupt pin (INT). The INT pin is configured as `INPUT_PULLUP`. ### Parameters #### Path Parameters - **cs_pin** (uint8_t) - Required - The Arduino pin connected to the chip-select (CS) line. - **int_pin** (uint8_t) - Required - The Arduino pin connected to the interrupt (INT) line. - **theSPI** (SPIClass *) - Optional - Pointer to the SPI bus object. Defaults to `&SPI`. - **sensor_id** (int32_t) - Optional - An identifier for the sensor. Defaults to 0. ``` -------------------------------- ### Initialize BNO08x over I2C Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Sets up the sensor on the I2C bus. The default address is 0x4A. Returns true on success. After a successful call, bno08x.prodIds is populated with firmware version information. ```cpp #include Adafruit_BNO08x bno08x(-1); void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_I2C()) { // default addr 0x4A, Wire bus Serial.println("Failed to find BNO08x chip"); while (1) delay(10); } // Print firmware version from product IDs for (int n = 0; n < bno08x.prodIds.numEntries; n++) { Serial.print("Part "); Serial.print(bno08x.prodIds.entry[n].swPartNumber); Serial.print(" v"); Serial.print(bno08x.prodIds.entry[n].swVersionMajor); Serial.print("."); Serial.println(bno08x.prodIds.entry[n].swVersionMinor); } // Output: Part 10003608 v4.2 } ``` -------------------------------- ### Initialize BNO08x over SPI Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Sets up the sensor using hardware SPI at 1 MHz, SPI mode 3. Requires a chip-select pin and an interrupt pin (INT). The INT pin is configured as INPUT_PULLUP. ```cpp #include #define BNO08X_CS 10 #define BNO08X_INT 9 #define BNO08X_RESET 5 Adafruit_BNO08x bno08x(BNO08X_RESET); void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_SPI(BNO08X_CS, BNO08X_INT)) { Serial.println("BNO08x SPI init failed"); while (1) delay(10); } Serial.println("BNO08x ready via SPI"); } ``` -------------------------------- ### begin_UART Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Configures the sensor over a hardware UART at 3,000,000 baud. The connected serial port must have a receive buffer larger than 300 bytes (not available on Uno/Leonardo hardware UARTs). ```APIDOC ## begin_UART(HardwareSerial *serial, int32_t sensor_id = 0) ### Description Configures the sensor over a hardware UART at 3,000,000 baud. The connected serial port must have a receive buffer larger than 300 bytes (not available on Uno/Leonardo hardware UARTs). ### Parameters #### Path Parameters - **serial** (HardwareSerial *) - Required - Pointer to the hardware serial port object (e.g., `&Serial1`). - **sensor_id** (int32_t) - Optional - An identifier for the sensor. Defaults to 0. ``` -------------------------------- ### Initialize BNO08x over UART Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Configures the sensor over a hardware UART at 3,000,000 baud. The connected serial port must have a receive buffer larger than 300 bytes. ```cpp #include Adafruit_BNO08x bno08x(-1); void setup() { Serial.begin(115200); while (!Serial) delay(10); // Serial1 = hardware UART TX1/RX1 on boards like Feather M4 if (!bno08x.begin_UART(&Serial1)) { Serial.println("BNO08x UART init failed"); while (1) delay(10); } Serial.println("BNO08x ready via UART"); } ``` -------------------------------- ### Constructor for Adafruit_BNO08x Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Creates a sensor object. Pass -1 if the reset pin is not wired. ```cpp #include // Reset pin wired to Arduino pin 5 Adafruit_BNO08x bno08x(5); // No reset pin connected Adafruit_BNO08x bno08x(-1); ``` -------------------------------- ### Format C++ and Header Files with clang-format Source: https://github.com/adafruit/adafruit_bno08x/blob/master/README.md Use clang-format to standardize code formatting. The -i flag modifies files in place. Running without -i shows the formatted output for review. ```bash clang-format -i *.cpp *.h ``` -------------------------------- ### Enable Sensor Reports with Specific Intervals Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Activates specific sensor outputs and sets their update periods in microseconds. Must be called after `begin_*()` and re-called after any sensor reset. Returns `true` on success. ```cpp void setReports() { // Rotation vector at 100 Hz (10 ms) if (!bno08x.enableReport(SH2_ROTATION_VECTOR, 10000)) { Serial.println("Could not enable rotation vector"); } // Accelerometer at 50 Hz (20 ms) if (!bno08x.enableReport(SH2_ACCELEROMETER, 20000)) { Serial.println("Could not enable accelerometer"); } // Step counter (event-driven, interval is a hint) if (!bno08x.enableReport(SH2_STEP_COUNTER)) { Serial.println("Could not enable step counter"); } // AR/VR stabilized rotation at 200 Hz if (!bno08x.enableReport(SH2_ARVR_STABILIZED_RV, 5000)) { Serial.println("Could not enable AR/VR stabilized RV"); } } ``` -------------------------------- ### enableReport Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Activates a specific sensor output and sets the update period in microseconds. The default interval is 10000 µs (100 Hz). Must be called after `begin_*()` and re-called after any sensor reset. Returns `true` on success. ```APIDOC ## `enableReport(sh2_SensorId_t sensor, uint32_t interval_us)` — Enable a sensor report Activates a specific sensor output and sets the update period in microseconds. The default interval is `10000 µs` (100 Hz). Must be called after `begin_*()` and re-called after any sensor reset. Returns `true` on success. ### Parameters #### Path Parameters - **sensor** (sh2_SensorId_t) - Required - The ID of the sensor to enable. - **interval_us** (uint32_t) - Optional - The update period in microseconds. Defaults to 10000 µs if not provided. ### Returns - `true` on success, `false` on failure. ### Example ```cpp // Rotation vector at 100 Hz (10 ms) if (!bno08x.enableReport(SH2_ROTATION_VECTOR, 10000)) { Serial.println("Could not enable rotation vector"); } // Accelerometer at 50 Hz (20 ms) if (!bno08x.enableReport(SH2_ACCELEROMETER, 20000)) { Serial.println("Could not enable accelerometer"); } // Step counter (event-driven, interval is a hint) if (!bno08x.enableReport(SH2_STEP_COUNTER)) { Serial.println("Could not enable step counter"); } // AR/VR stabilized rotation at 200 Hz if (!bno08x.enableReport(SH2_ARVR_STABILIZED_RV, 5000)) { Serial.println("Could not enable AR/VR stabilized RV"); } ``` ### Available `sh2_SensorId_t` constants: | Constant | Description | |---|---| | `SH2_ACCELEROMETER` | Calibrated acceleration (m/s²) | | `SH2_GYROSCOPE_CALIBRATED` | Calibrated angular velocity (rad/s) | | `SH2_MAGNETIC_FIELD_CALIBRATED` | Calibrated magnetic field (µT) | | `SH2_ROTATION_VECTOR` | Full 9-DOF rotation quaternion + accuracy | | `SH2_GAME_ROTATION_VECTOR` | Gyro+accel rotation (no magnetometer) | | `SH2_GEOMAGNETIC_ROTATION_VECTOR` | Accel+mag rotation | | `SH2_ARVR_STABILIZED_RV` | AR/VR-optimized stabilized rotation | | `SH2_GYRO_INTEGRATED_RV` | High-rate gyro-integrated rotation (up to 1 kHz) | | `SH2_LINEAR_ACCELERATION` | Acceleration minus gravity | | `SH2_GRAVITY` | Gravity vector | | `SH2_STEP_COUNTER` | Cumulative step count | | `SH2_STEP_DETECTOR` | Single step event | | `SH2_SHAKE_DETECTOR` | Shake event on X/Y/Z axis | | `SH2_STABILITY_CLASSIFIER` | On-table / stationary / stable / motion | | `SH2_PERSONAL_ACTIVITY_CLASSIFIER` | Walking / running / cycling / vehicle / etc. | | `SH2_TAP_DETECTOR` | Single/double tap detection | | `SH2_RAW_ACCELEROMETER` | Raw ADC accelerometer counts | | `SH2_RAW_GYROSCOPE` | Raw ADC gyroscope counts | | `SH2_RAW_MAGNETOMETER` | Raw ADC magnetometer counts | ``` -------------------------------- ### Adafruit_BNO08x Constructor Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Creates a sensor object and optionally registers the Arduino pin connected to the BNO08x hardware reset line. Pass -1 if the reset pin is not wired. ```APIDOC ## Adafruit_BNO08x(int8_t reset_pin) ### Description Creates a sensor object and optionally registers the Arduino pin connected to the BNO08x hardware reset line. Pass `-1` if the reset pin is not wired. ### Parameters #### Path Parameters - **reset_pin** (int8_t) - Required - The Arduino pin connected to the BNO08x hardware reset line, or -1 if not wired. ``` -------------------------------- ### Trigger Hardware Reset with hardwareReset() Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Use `hardwareReset()` to force a full sensor restart by pulsing the reset pin. Ensure to re-initialize the sensor using `begin_I2C()` after the reset. ```cpp Adafruit_BNO08x bno08x(5); // reset pin = 5 void recoverSensor() { Serial.println("Resetting BNO08x..."); bno08x.hardwareReset(); delay(500); // Re-initialize after reset if (!bno08x.begin_I2C()) { Serial.println("Re-init failed after hardware reset"); } } ``` -------------------------------- ### Detect Sensor Reset with wasReset() Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Call `wasReset()` in your loop to detect if the BNO08x has reset. If a reset is detected, all enabled reports must be re-registered. ```cpp void loop() { if (bno08x.wasReset()) { Serial.println("BNO08x was reset — re-enabling reports"); setReports(); // re-enable all desired sensor reports } if (!bno08x.getSensorEvent(&sensorValue)) return; // ... process events } ``` -------------------------------- ### Convert Quaternion to Euler Angles Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt This utility converts quaternion components (from `SH2_ARVR_STABILIZED_RV` or `SH2_GYRO_INTEGRATED_RV`) to Euler yaw, pitch, and roll angles. The `degrees` parameter controls the output unit. ```cpp #include // #define FAST_MODE // uncomment for SH2_GYRO_INTEGRATED_RV struct euler_t { float yaw, pitch, roll; } ypr; Adafruit_BNO08x bno08x(-1); sh2_SensorValue_t sensorValue; #ifdef FAST_MODE sh2_SensorId_t reportType = SH2_GYRO_INTEGRATED_RV; long reportIntervalUs = 2000; // 500 Hz #else sh2_SensorId_t reportType = SH2_ARVR_STABILIZED_RV; long reportIntervalUs = 5000; // 200 Hz #endif void quaternionToEuler(float qr, float qi, float qj, float qk, euler_t* ypr, bool degrees = false) { float sqr = sq(qr), sqi = sq(qi), sqj = sq(qj), sqk = sq(qk); ypr->yaw = atan2(2.0*(qi*qj + qk*qr), (sqi - sqj - sqk + sqr)); ypr->pitch = asin(-2.0*(qi*qk - qj*qr) / (sqi + sqj + sqk + sqr)); ypr->roll = atan2(2.0*(qj*qk + qi*qr), (-sqi - sqj + sqk + sqr)); if (degrees) { ypr->yaw *= RAD_TO_DEG; ypr->pitch *= RAD_TO_DEG; ypr->roll *= RAD_TO_DEG; } } void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_I2C()) { Serial.println("Init failed"); while(1); } bno08x.enableReport(reportType, reportIntervalUs); } void loop() { if (bno08x.wasReset()) bno08x.enableReport(reportType, reportIntervalUs); if (bno08x.getSensorEvent(&sensorValue)) { if (sensorValue.sensorId == SH2_ARVR_STABILIZED_RV) { auto &rv = sensorValue.un.arvrStabilizedRV; quaternionToEuler(rv.real, rv.i, rv.j, rv.k, &ypr, true); } else if (sensorValue.sensorId == SH2_GYRO_INTEGRATED_RV) { auto &gi = sensorValue.un.gyroIntegratedRV; quaternionToEuler(gi.real, gi.i, gi.j, gi.k, &ypr, true); } // status: 0=unreliable, 1=low, 2=medium, 3=high accuracy Serial.print(sensorValue.status); Serial.print("\t"); Serial.print(ypr.yaw); Serial.print("\t"); Serial.println(ypr.roll); // Output: 3 45.12 -2.34 178.90 } } ``` -------------------------------- ### Quaternion to Euler Angles Conversion Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Converts quaternion components, natively output by the BNO08x, into Euler angles (yaw, pitch, roll). This utility is compatible with both `SH2_ARVR_STABILIZED_RV` and `SH2_GYRO_INTEGRATED_RV` sensor reports. ```APIDOC ## Quaternion to Euler Angles ### Description Converts quaternion components to Euler yaw/pitch/roll angles. This is useful for interpreting orientation data from the BNO08x, which natively outputs quaternions. Compatible with `SH2_ARVR_STABILIZED_RV` (accurate, ~250 Hz) and `SH2_GYRO_INTEGRATED_RV` (fast, up to 1 kHz). ### Function Signature `void quaternionToEuler(float qr, float qi, float qj, float qk, euler_t* ypr, bool degrees = false)` ### Parameters - `qr` (float): Real component of the quaternion. - `qi` (float): Imaginary component (i) of the quaternion. - `qj` (float): Imaginary component (j) of the quaternion. - `qk` (float): Imaginary component (k) of the quaternion. - `ypr` (euler_t*): Pointer to a structure to store the resulting yaw, pitch, and roll angles. - `degrees` (bool, optional): If true, angles are converted to degrees. Defaults to false (radians). ### Usage Example ```cpp #include struct euler_t { float yaw, pitch, roll; } ypr; Adafruit_BNO08x bno08x(-1); sh2_SensorValue_t sensorValue; void quaternionToEuler(float qr, float qi, float qj, float qk, euler_t* ypr, bool degrees = false) { float sqr = sq(qr), sqi = sq(qi), sqj = sq(qj), sqk = sq(qk); ypr->yaw = atan2(2.0*(qi*qj + qk*qr), (sqi - sqj - sqk + sqr)); ypr->pitch = asin(-2.0*(qi*qk - qj*qr) / (sqi + sqj + sqk + sqr)); ypr->roll = atan2(2.0*(qj*qk + qi*qr), (-sqi - sqj + sqk + sqr)); if (degrees) { ypr->yaw *= RAD_TO_DEG; ypr->pitch *= RAD_TO_DEG; ypr->roll *= RAD_TO_DEG; } } void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_I2C()) { Serial.println("Init failed"); while(1); } bno08x.enableReport(SH2_ARVR_STABILIZED_RV, 5000); } void loop() { if (bno08x.wasReset()) bno08x.enableReport(SH2_ARVR_STABILIZED_RV, 5000); if (bno08x.getSensorEvent(&sensorValue)) { if (sensorValue.sensorId == SH2_ARVR_STABILIZED_RV) { auto &rv = sensorValue.un.arvrStabilizedRV; quaternionToEuler(rv.real, rv.i, rv.j, rv.k, &ypr, true); } Serial.print(ypr.yaw); Serial.print("\t"); Serial.println(ypr.pitch); Serial.print("\t"); Serial.println(ypr.roll); } } ``` ``` -------------------------------- ### Personal Activity Classifier — Activity Detection Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Utilizes the BNO08x sensor to detect the user's current activity state (e.g., walking, running, still) and provides confidence scores for each detected activity. ```APIDOC ## Personal Activity Classifier ### Description Detects user activity state (walking, running, cycling, in vehicle, still, etc.) with per-class confidence scores from 0–100. ### Sensor Report `SH2_PERSONAL_ACTIVITY_CLASSIFIER` ### Data Structure `sh2_SensorValue_t.un.personalActivityClassifier` contains: - `mostLikelyState` (uint8_t): The ID of the most probable activity. - `confidence` (uint8_t[PAC_OPTION_COUNT]): An array of confidence scores (0-100) for each possible activity state. ### Activity State IDs - `PAC_UNKNOWN` - `PAC_IN_VEHICLE` - `PAC_ON_BICYCLE` - `PAC_ON_FOOT` - `PAC_STILL` - `PAC_TILTING` - `PAC_WALKING` - `PAC_RUNNING` - `PAC_ON_STAIRS` ### Usage Example ```cpp #include Adafruit_BNO08x bno08x(-1); sh2_SensorValue_t sensorValue; const char* activityName(uint8_t id) { switch (id) { case PAC_UNKNOWN: return "Unknown"; case PAC_IN_VEHICLE: return "In Vehicle"; case PAC_ON_BICYCLE: return "On Bicycle"; case PAC_ON_FOOT: return "On Foot"; case PAC_STILL: return "Still"; case PAC_TILTING: return "Tilting"; case PAC_WALKING: return "Walking"; case PAC_RUNNING: return "Running"; case PAC_ON_STAIRS: return "On Stairs"; default: return "N/A"; } } void setup() { Serial.begin(115200); while (!Serial) delay(10); if (!bno08x.begin_I2C()) { while(1) delay(10); } bno08x.enableReport(SH2_PERSONAL_ACTIVITY_CLASSIFIER); } void loop() { if (bno08x.wasReset()) bno08x.enableReport(SH2_PERSONAL_ACTIVITY_CLASSIFIER); if (!bno08x.getSensorEvent(&sensorValue)) return; if (sensorValue.sensorId == SH2_PERSONAL_ACTIVITY_CLASSIFIER) { auto &pac = sensorValue.un.personalActivityClassifier; Serial.print("Most likely: "); Serial.println(activityName(pac.mostLikelyState)); for (uint8_t i = 0; i < PAC_OPTION_COUNT; i++) { Serial.print(" "); Serial.print(activityName(i)); Serial.print(": "); Serial.println(pac.confidence[i]); } } } ``` ``` -------------------------------- ### hardwareReset() — Trigger hardware reset via reset pin Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Initiates a hardware reset of the BNO08x sensor by pulsing the reset pin. This method is effective only if a reset pin was configured during initialization. ```APIDOC ## hardwareReset() ### Description Pulses the hardware reset pin (configured in the constructor) HIGH→LOW→HIGH to force a full sensor restart. Has no effect if `reset_pin` was set to `-1`. ### Method Signature `void hardwareReset()` ### Usage Example ```cpp Adafruit_BNO08x bno08x(5); // reset pin = 5 void recoverSensor() { Serial.println("Resetting BNO08x..."); bno08x.hardwareReset(); delay(500); // Re-initialize after reset if (!bno08x.begin_I2C()) { Serial.println("Re-init failed after hardware reset"); } } ``` ``` -------------------------------- ### getSensorEvent Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Polls for a new sensor reading by calling `sh2_service()` internally and filling the provided `sh2_SensorValue_t` struct with the next available report. Returns `true` if a new event was received, `false` if none is available. The caller dispatches on `value.sensorId` to access the correct union member. ```APIDOC ## `getSensorEvent(sh2_SensorValue_t *value)` — Poll for a new sensor reading Calls `sh2_service()` internally and fills the provided `sh2_SensorValue_t` struct with the next available report. Returns `true` if a new event was received, `false` if none is available. The caller dispatches on `value.sensorId` to access the correct union member. ### Parameters #### Path Parameters - **value** (sh2_SensorValue_t *) - Required - A pointer to a `sh2_SensorValue_t` struct to be filled with the sensor data. ### Returns - `true` if a new event was received, `false` otherwise. ### Example ```cpp sh2_SensorValue_t sensorValue; void loop() { delay(10); if (!bno08x.getSensorEvent(&sensorValue)) { return; // no new data } switch (sensorValue.sensorId) { case SH2_ROTATION_VECTOR: // Accuracy in radians, quaternion components i/j/k/real Serial.print("RotVec r="); Serial.print(sensorValue.un.rotationVector.real); Serial.print(" i="); Serial.print(sensorValue.un.rotationVector.i); Serial.print(" j="); Serial.print(sensorValue.un.rotationVector.j); Serial.print(" k="); Serial.println(sensorValue.un.rotationVector.k); break; case SH2_ACCELEROMETER: Serial.print("Accel x="); Serial.print(sensorValue.un.accelerometer.x); Serial.print(" y="); Serial.print(sensorValue.un.accelerometer.y); Serial.print(" z="); Serial.println(sensorValue.un.accelerometer.z); break; case SH2_GYROSCOPE_CALIBRATED: Serial.print("Gyro x="); Serial.print(sensorValue.un.gyroscope.x); Serial.print(" y="); Serial.print(sensorValue.un.gyroscope.y); Serial.print(" z="); Serial.println(sensorValue.un.gyroscope.z); break; case SH2_STEP_COUNTER: Serial.print("Steps: "); Serial.println(sensorValue.un.stepCounter.steps); break; case SH2_STABILITY_CLASSIFIER: switch (sensorValue.un.stabilityClassifier.classification) { case STABILITY_CLASSIFIER_ON_TABLE: Serial.println("On Table"); break; case STABILITY_CLASSIFIER_STATIONARY: Serial.println("Stationary"); break; case STABILITY_CLASSIFIER_MOTION: Serial.println("In Motion"); break; default: Serial.println("Unknown"); break; } break; case SH2_SHAKE_DETECTOR: if (sensorValue.un.shakeDetector.shake & SHAKE_X) Serial.println("Shake on X"); if (sensorValue.un.shakeDetector.shake & SHAKE_Y) Serial.println("Shake on Y"); if (sensorValue.un.shakeDetector.shake & SHAKE_Z) Serial.println("Shake on Z"); break; } } ``` ``` -------------------------------- ### wasReset() — Detect sensor reset Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Detects if the BNO08x sensor has reset since the last call. If a reset is detected, all enabled reports must be re-registered. ```APIDOC ## wasReset() ### Description Detects if the BNO08x sensor has reset since the last call. Returns `true` if a reset occurred and clears the flag. When a reset is detected, all enabled reports must be re-registered using `enableReport()`. ### Method Signature `bool wasReset()` ### Usage Example ```cpp void loop() { if (bno08x.wasReset()) { Serial.println("BNO08x was reset — re-enabling reports"); setReports(); // re-enable all desired sensor reports } if (!bno08x.getSensorEvent(&sensorValue)) return; // ... process events } ``` ``` -------------------------------- ### Poll for New Sensor Events Source: https://context7.com/adafruit/adafruit_bno08x/llms.txt Polls for new sensor readings, calling `sh2_service()` internally. Fills a `sh2_SensorValue_t` struct with the next available report. Returns `true` if a new event was received, `false` otherwise. The caller dispatches on `value.sensorId` to access the correct union member. ```cpp sh2_SensorValue_t sensorValue; void loop() { delay(10); if (!bno08x.getSensorEvent(&sensorValue)) { return; // no new data } switch (sensorValue.sensorId) { case SH2_ROTATION_VECTOR: // Accuracy in radians, quaternion components i/j/k/real Serial.print("RotVec r="); Serial.print(sensorValue.un.rotationVector.real); Serial.print(" i="); Serial.print(sensorValue.un.rotationVector.i); Serial.print(" j="); Serial.print(sensorValue.un.rotationVector.j); Serial.print(" k="); Serial.println(sensorValue.un.rotationVector.k); break; case SH2_ACCELEROMETER: Serial.print("Accel x="); Serial.print(sensorValue.un.accelerometer.x); Serial.print(" y="); Serial.print(sensorValue.un.accelerometer.y); Serial.print(" z="); Serial.println(sensorValue.un.accelerometer.z); break; case SH2_GYROSCOPE_CALIBRATED: Serial.print("Gyro x="); Serial.print(sensorValue.un.gyroscope.x); Serial.print(" y="); Serial.print(sensorValue.un.gyroscope.y); Serial.print(" z="); Serial.println(sensorValue.un.gyroscope.z); break; case SH2_STEP_COUNTER: Serial.print("Steps: "); Serial.println(sensorValue.un.stepCounter.steps); break; case SH2_STABILITY_CLASSIFIER: switch (sensorValue.un.stabilityClassifier.classification) { case STABILITY_CLASSIFIER_ON_TABLE: Serial.println("On Table"); break; case STABILITY_CLASSIFIER_STATIONARY: Serial.println("Stationary"); break; case STABILITY_CLASSIFIER_MOTION: Serial.println("In Motion"); break; default: Serial.println("Unknown"); break; } break; case SH2_SHAKE_DETECTOR: if (sensorValue.un.shakeDetector.shake & SHAKE_X) Serial.println("Shake on X"); if (sensorValue.un.shakeDetector.shake & SHAKE_Y) Serial.println("Shake on Y"); if (sensorValue.un.shakeDetector.shake & SHAKE_Z) Serial.println("Shake on Z"); break; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.