diff --git a/examples/Example22-TareManufacturingCalibration/Example22-TareManufacturingCalibration.ino b/examples/Example22-TareManufacturingCalibration/Example22-TareManufacturingCalibration.ino new file mode 100644 index 0000000..9a998ac --- /dev/null +++ b/examples/Example22-TareManufacturingCalibration/Example22-TareManufacturingCalibration.ino @@ -0,0 +1,110 @@ +/* + 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(9600); + Serial.println(); + Serial.println("BNO080 Read 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")); +} + +void loop() +{ + if(Serial.available()) + { + byte incoming = Serial.read(); + + if(incoming == 't') + { + myIMU.tareAllAxes(); //tare x,y,z axes to calibrate device with default manufacturing + myIMU.saveTare(); //save tare + delay(1); + } + } + + //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(); + + /* See page 5 of Tare + * Determine North in your current environment + * a. You can either look at a physical compass, or look at the Rotation Vector to + * determine where North is. + * When the Rotation Vector reads W=1, X=0, Y=0, Z=0 the device is pointed North + + * w = real + * x = i + * y = j + * z = k + */ + + Serial.print(F(", W : ")); + Serial.print(quatReal, 2); + Serial.print(F(", x : ")); + Serial.print(quatI, 2); + Serial.print(F(", y: ")); + Serial.print(quatJ, 2); + Serial.print(F(", z: ")); + Serial.print(quatK, 2); + Serial.print(F(",")); + Serial.print(quatRadianAccuracy, 2); + Serial.print(F(",")); + + Serial.println(); + } +} diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 1ebdfe7..187afb1 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -1221,6 +1221,53 @@ boolean BNO080::calibrationComplete() return (false); } + +//See Tare Procedure Tare Function Usage Guide +//https://www.ceva-dsp.com/wp-content/uploads/2019/09/BNO080-BNO085-Tare-Function-Usage-Guide.pdf +void BNO080::tareAllAxes() +{ + /*shtpData[3] = 0; //P0 - P0 (Subcommand) + shtpData[4] = 0; //P1 - All 3 Axes(x,y,z) + shtpData[5] = 0; //P2 - Rotation vector + shtpData[6] = 0; //P3 - Reserved + shtpData[7] = 0; //P4 - Reserved + shtpData[8] = 0; //P5 - Reserved + shtpData[9] = 0; //P6 - Reserved + shtpData[10] = 0; //P7 - Reserved + shtpData[11] = 0; //P8 - Reserved*/ + + for (uint8_t x = 3; x < 12; x++) //Clear this section of the shtpData array + shtpData[x] = 0; + + shtpData[4] = 0x07; + + //Using this shtpData packet, send a command + sendCommand(COMMAND_TARE); //Save TARE command +} + +//See Tare Procedure Tare Function Usage Guide +//Run the Persist Tare +//https://www.ceva-dsp.com/wp-content/uploads/2019/09/BNO080-BNO085-Tare-Function-Usage-Guide.pdf +void BNO080::saveTare() +{ + /*shtpData[3] = 0; //P0 (Subcommand) + shtpData[4] = 0; //Reserved + shtpData[5] = 0; //Reserved + shtpData[6] = 0; //P3 - Reserved + shtpData[7] = 0; //P4 - Reserved + shtpData[8] = 0; //P5 - Reserved + shtpData[9] = 0; //P6 - Reserved + shtpData[10] = 0; //P7 - Reserved + shtpData[11] = 0; //P8 - Reserved*/ + + for (uint8_t x = 3; x < 12; x++) //Clear this section of the shtpData array + shtpData[x] = 0; + + shtpData[3] = 0x01; + + sendCommand(COMMAND_TARE); //Run TARE command +} + //Given a sensor's report ID, this tells the BNO080 to begin reporting the values void BNO080::setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports) { diff --git a/src/SparkFun_BNO080_Arduino_Library.h b/src/SparkFun_BNO080_Arduino_Library.h index 0b1c811..b2b490d 100644 --- a/src/SparkFun_BNO080_Arduino_Library.h +++ b/src/SparkFun_BNO080_Arduino_Library.h @@ -240,6 +240,9 @@ class BNO080 float getPitch(); float getYaw(); + void BNO080::tareAllAxes(); + void BNO080::saveTare(); + void setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports); void setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports, uint32_t specificConfig); void sendCommand(uint8_t command);