From b80732307998c9a351ab54186b14eb33aa79cce5 Mon Sep 17 00:00:00 2001 From: Aedan Cullen Date: Sat, 26 Dec 2020 16:12:11 -0500 Subject: [PATCH 1/5] Add tap detector --- src/SparkFun_BNO080_Arduino_Library.cpp | 18 ++++++++++++++++++ src/SparkFun_BNO080_Arduino_Library.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 16ce758..4d3a903 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -345,6 +345,10 @@ uint16_t BNO080::parseInputReport(void) // not game rot vector and not ar/vr stabilized rotation vector rawQuatRadianAccuracy = data5; } + else if (shtpData[5] == SENSOR_REPORTID_TAP_DETECTOR) + { + tapDetector = shtpData[5 + 4]; //Byte 4 only + } else if (shtpData[5] == SENSOR_REPORTID_STEP_COUNTER) { stepCount = data3; //Bytes 8/9 @@ -717,6 +721,14 @@ float BNO080::getFastGyroZ() return (gyro); } +//Return the tap detector +uint8_t BNO080::getTapDetector() +{ + uint8_t previousTapDetector = tapDetector; + tapDetector = 0; //Reset so user code sees exactly one tap + return (previousTapDetector); +} + //Return the step count uint16_t BNO080::getStepCount() { @@ -1036,6 +1048,12 @@ void BNO080::enableGyroIntegratedRotationVector(uint16_t timeBetweenReports) setFeatureCommand(SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR, timeBetweenReports); } +//Sends the packet to enable the tap detector +void BNO080::enableTapDetector(uint16_t timeBetweenReports) +{ + setFeatureCommand(SENSOR_REPORTID_TAP_DETECTOR, timeBetweenReports); +} + //Sends the packet to enable the step counter void BNO080::enableStepCounter(uint16_t timeBetweenReports) { diff --git a/src/SparkFun_BNO080_Arduino_Library.h b/src/SparkFun_BNO080_Arduino_Library.h index 201d896..ebcbdd7 100644 --- a/src/SparkFun_BNO080_Arduino_Library.h +++ b/src/SparkFun_BNO080_Arduino_Library.h @@ -151,6 +151,7 @@ class BNO080 void enableLinearAccelerometer(uint16_t timeBetweenReports); void enableGyro(uint16_t timeBetweenReports); void enableMagnetometer(uint16_t timeBetweenReports); + void enableTapDetector(uint16_t timeBetweenReports); void enableStepCounter(uint16_t timeBetweenReports); void enableStabilityClassifier(uint16_t timeBetweenReports); void enableActivityClassifier(uint16_t timeBetweenReports, uint32_t activitiesToEnable, uint8_t (&activityConfidences)[9]); @@ -211,6 +212,7 @@ class BNO080 void requestCalibrationStatus(); //Sends command to get status boolean calibrationComplete(); //Checks ME Cal response for byte 5, R0 - Status + uint8_t getTapDetector(); uint32_t getTimeStamp(); uint16_t getStepCount(); uint8_t getStabilityClassifier(); @@ -276,6 +278,7 @@ class BNO080 uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy; uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy; uint16_t rawFastGyroX, rawFastGyroY, rawFastGyroZ; + uint8_t tapDetector; uint16_t stepCount; uint32_t timeStamp; uint8_t stabilityClassifier; From 26559d916ab47b403d91d42e5db2d598a1513060 Mon Sep 17 00:00:00 2001 From: Aedan Cullen Date: Sat, 26 Dec 2020 16:17:07 -0500 Subject: [PATCH 2/5] Update keywords.txt --- keywords.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keywords.txt b/keywords.txt index 40771b2..c0ccb51 100644 --- a/keywords.txt +++ b/keywords.txt @@ -37,6 +37,7 @@ enableARVRStabilizedGameRotationVector KEYWORD2 enableAccelerometer KEYWORD2 enableGyro KEYWORD2 enableMagnetometer KEYWORD2 +enableTapDetector KEYWORD2 enableStepCounter KEYWORD2 enableStabilityClassifier KEYWORD2 enableActivityClassifier KEYWORD2 @@ -98,6 +99,7 @@ saveCalibration KEYWORD2 requestCalibrationStatus KEYWORD2 calibrationComplete KEYWORD2 +getTapDetector KEYWORD2 getTimeStamp KEYWORD2 getStepCount KEYWORD2 getStabilityClassifier KEYWORD2 From a6ee3ca0d27cf27282ce9a10fa203d076df5df0b Mon Sep 17 00:00:00 2001 From: PaulZC Date: Thu, 7 Jan 2021 16:15:50 +0000 Subject: [PATCH 3/5] Update SparkFun_BNO080_Arduino_Library.cpp --- src/SparkFun_BNO080_Arduino_Library.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 16ce758..d8a8399 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -897,7 +897,7 @@ bool BNO080::readFRSdata(uint16_t recordID, uint8_t startLocation, uint8_t words //We have the packet, inspect it for the right contents //See page 40. Report ID should be 0xF3 and the FRS types should match the thing we requested if (shtpData[0] == SHTP_REPORT_FRS_READ_RESPONSE) - if (((uint16_t)shtpData[13] << 8 | shtpData[12]) == recordID) + if (((((uint16_t)shtpData[13]) << 8) | shtpData[12]) == recordID) break; //This packet is one we are looking for } From f17bb4196129358398d308032d60a189b1968375 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Thu, 18 Feb 2021 10:19:38 +0000 Subject: [PATCH 4/5] Adding modeOn and modeSleep --- examples/Example20-Sleep/Example20-Sleep.ino | 105 +++++++++++++++++++ keywords.txt | 2 + src/SparkFun_BNO080_Arduino_Library.cpp | 36 +++++++ src/SparkFun_BNO080_Arduino_Library.h | 2 + 4 files changed, 145 insertions(+) create mode 100644 examples/Example20-Sleep/Example20-Sleep.ino diff --git a/examples/Example20-Sleep/Example20-Sleep.ino b/examples/Example20-Sleep/Example20-Sleep.ino new file mode 100644 index 0000000..ca93525 --- /dev/null +++ b/examples/Example20-Sleep/Example20-Sleep.ino @@ -0,0 +1,105 @@ +/* + Using the BNO080 IMU + By: Nathan Seidle + SparkFun Electronics + Date: December 21st, 2017 + SparkFun code, firmware, and software is released under the MIT License. + Please see LICENSE.md for further details. + + Feel like supporting our work? Buy a board from SparkFun! + https://www.sparkfun.com/products/14586 + + This example shows how to output the i/j/k/real parts of the rotation vector. + https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation + + It takes about 1ms at 400kHz I2C to read a record from the sensor, but we are polling the sensor continually + between updates from the sensor. Use the interrupt pin on the BNO080 breakout to avoid polling. + + Hardware Connections: + Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other + Plug the sensor onto the shield + Serial.print it out at 9600 baud to serial monitor. +*/ + +#include + +#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080 +BNO080 myIMU; + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println("BNO080 Sleep Example"); + + Wire.begin(); + + //Are you using a ESP? Check this issue for more information: https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/issues/16 +// //================================= +// delay(100); // Wait for BNO to boot +// // Start i2c and BNO080 +// Wire.flush(); // Reset I2C +// IMU.begin(BNO080_DEFAULT_ADDRESS, Wire); +// Wire.begin(4, 5); +// Wire.setClockStretchLimit(4000); +// //================================= + + if (myIMU.begin() == false) + { + Serial.println("BNO080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing..."); + while (1); + } + + Wire.setClock(400000); //Increase I2C data rate to 400kHz + + myIMU.enableRotationVector(50); //Send data update every 50ms + + Serial.println(F("Rotation vector enabled")); + Serial.println(F("Output in form i, j, k, real, accuracy")); +} + +unsigned long lastMillis = 0; // Keep track of time +bool lastPowerState = true; // Toggle between "On" and "Sleep" + +void loop() +{ + //Look for reports from the IMU + if (myIMU.dataAvailable() == true) + { + float quatI = myIMU.getQuatI(); + float quatJ = myIMU.getQuatJ(); + float quatK = myIMU.getQuatK(); + float quatReal = myIMU.getQuatReal(); + float quatRadianAccuracy = myIMU.getQuatRadianAccuracy(); + + Serial.print(quatI, 2); + Serial.print(F(",")); + Serial.print(quatJ, 2); + Serial.print(F(",")); + Serial.print(quatK, 2); + Serial.print(F(",")); + Serial.print(quatReal, 2); + Serial.print(F(",")); + Serial.print(quatRadianAccuracy, 2); + Serial.print(F(",")); + + Serial.println(); + } + + //Check if it is time to change the power state + if (millis() > (lastMillis + 5000)) // Change state every 5 seconds + { + lastMillis = millis(); // Keep track of time + + if (lastPowerState) // Are we "On"? + { + myIMU.modeSleep(); // Put BNO to sleep + } + else + { + myIMU.modeOn(); // Turn BNO back on + } + + lastPowerState ^= 1; // Invert lastPowerState (using ex-or) + } +} diff --git a/keywords.txt b/keywords.txt index c0ccb51..89dc28e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -19,6 +19,8 @@ enableDebugging KEYWORD2 softReset KEYWORD2 resetReason KEYWORD2 +modeOn KEYWORD2 +modeSleep KEYWORD2 qToFloat KEYWORD2 diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 3e69780..179f624 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -963,6 +963,42 @@ void BNO080::softReset(void) ; //delay(1); } +//Set the operating mode to "On" +//(This one is for @jerabaul29) +void BNO080::modeOn(void) +{ + shtpData[0] = 2; //On + + //Attempt to start communication with sensor + sendPacket(CHANNEL_EXECUTABLE, 1); //Transmit packet on channel 1, 1 byte + + //Read all incoming data and flush it + delay(50); + while (receivePacket() == true) + ; //delay(1); + delay(50); + while (receivePacket() == true) + ; //delay(1); +} + +//Set the operating mode to "Sleep" +//(This one is for @jerabaul29) +void BNO080::modeSleep(void) +{ + shtpData[0] = 3; //Sleep + + //Attempt to start communication with sensor + sendPacket(CHANNEL_EXECUTABLE, 1); //Transmit packet on channel 1, 1 byte + + //Read all incoming data and flush it + delay(50); + while (receivePacket() == true) + ; //delay(1); + delay(50); + while (receivePacket() == true) + ; //delay(1); +} + //Get the reason for the last reset //1 = POR, 2 = Internal reset, 3 = Watchdog, 4 = External reset, 5 = Other uint8_t BNO080::resetReason() diff --git a/src/SparkFun_BNO080_Arduino_Library.h b/src/SparkFun_BNO080_Arduino_Library.h index ebcbdd7..025f9c8 100644 --- a/src/SparkFun_BNO080_Arduino_Library.h +++ b/src/SparkFun_BNO080_Arduino_Library.h @@ -132,6 +132,8 @@ class BNO080 void softReset(); //Try to reset the IMU via software uint8_t resetReason(); //Query the IMU for the reason it last reset + void modeOn(); //Use the executable channel to turn the BNO on + void modeSleep(); //Use the executable channel to put the BNO to sleep float qToFloat(int16_t fixedPointValue, uint8_t qPoint); //Given a Q value, converts fixed point floating to regular floating point number From e74a234974705f37418c9d35d1cf0e67230afc91 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Thu, 18 Feb 2021 10:20:22 +0000 Subject: [PATCH 5/5] v1.1.10 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 45e863d..5615a31 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun BNO080 Cortex Based IMU -version=1.1.9 +version=1.1.10 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Qwiic VR IMU - BNO080/BNO085