Skip to content

Commit 24603cc

Browse files
authored
Merge pull request #94 from sparkfun/release-candidate
v1.1.11
2 parents f421f44 + 33c2091 commit 24603cc

File tree

7 files changed

+190
-26
lines changed

7 files changed

+190
-26
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Thanks to all those who have helped improve the library:
2323
* Filimindji for AR/VR Stabilized RotationVector and AR/VR Stabilized GameRotationVector support - [PR 46](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/46)
2424
* ya-mouse for the getreadings improvements - [PR 55](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/55)
2525
* Guillaume for the read-multiple-values helper functions and the interrupt example - [PR56](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/56) & [PR59](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/59)
26+
* aedancullen for the tap detector - [PR 64](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/64)
27+
* mattbradford83 for the hasReset code and example - [PR 92](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/92)
2628

2729
Repository Contents
2830
-------------------

examples/Example20-Sleep/Example20-Sleep.ino

+35-25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080
2727
BNO080 myIMU;
2828

29+
unsigned long lastMillis = 0; // Keep track of time
30+
bool lastPowerState = true; // Toggle between "On" and "Sleep"
31+
2932
void setup()
3033
{
3134
Serial.begin(115200);
@@ -44,46 +47,51 @@ void setup()
4447
// Wire.setClockStretchLimit(4000);
4548
// //=================================
4649

50+
//myIMU.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
51+
4752
if (myIMU.begin() == false)
4853
{
4954
Serial.println("BNO080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5055
while (1);
5156
}
5257

53-
Wire.setClock(400000); //Increase I2C data rate to 400kHz
58+
// Enable the Rotation Vector packet ** while the I2C bus is set to 100kHz **
59+
myIMU.enableRotationVector(50); //Send RV data update every 50ms
5460

55-
myIMU.enableRotationVector(50); //Send data update every 50ms
61+
Wire.setClock(400000); //Now increase I2C data rate to 400kHz
5662

5763
Serial.println(F("Rotation vector enabled"));
5864
Serial.println(F("Output in form i, j, k, real, accuracy"));
59-
}
6065

61-
unsigned long lastMillis = 0; // Keep track of time
62-
bool lastPowerState = true; // Toggle between "On" and "Sleep"
66+
lastMillis = millis(); // Keep track of time
67+
}
6368

6469
void loop()
6570
{
66-
//Look for reports from the IMU
67-
if (myIMU.dataAvailable() == true)
71+
//Look for reports from the IMU - ** but only when not asleep **
72+
if (lastPowerState) // Are we "On"? (Comment this if you are interested in how it effects the sleep current)
6873
{
69-
float quatI = myIMU.getQuatI();
70-
float quatJ = myIMU.getQuatJ();
71-
float quatK = myIMU.getQuatK();
72-
float quatReal = myIMU.getQuatReal();
73-
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
74-
75-
Serial.print(quatI, 2);
76-
Serial.print(F(","));
77-
Serial.print(quatJ, 2);
78-
Serial.print(F(","));
79-
Serial.print(quatK, 2);
80-
Serial.print(F(","));
81-
Serial.print(quatReal, 2);
82-
Serial.print(F(","));
83-
Serial.print(quatRadianAccuracy, 2);
84-
Serial.print(F(","));
85-
86-
Serial.println();
74+
if (myIMU.dataAvailable() == true) // Is fresh data available?
75+
{
76+
float quatI = myIMU.getQuatI();
77+
float quatJ = myIMU.getQuatJ();
78+
float quatK = myIMU.getQuatK();
79+
float quatReal = myIMU.getQuatReal();
80+
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
81+
82+
Serial.print(quatI, 2);
83+
Serial.print(F(","));
84+
Serial.print(quatJ, 2);
85+
Serial.print(F(","));
86+
Serial.print(quatK, 2);
87+
Serial.print(F(","));
88+
Serial.print(quatReal, 2);
89+
Serial.print(F(","));
90+
Serial.print(quatRadianAccuracy, 2);
91+
Serial.print(F(","));
92+
93+
Serial.println();
94+
}
8795
}
8896

8997
//Check if it is time to change the power state
@@ -102,4 +110,6 @@ void loop()
102110

103111
lastPowerState ^= 1; // Invert lastPowerState (using ex-or)
104112
}
113+
114+
delay(10); // Don't pound the bus too hard (Comment this if you are interested in how it effects the sleep current)
105115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Using the BNO080 IMU hasReset() function
3+
By: @mattbradford83
4+
Date: 1 August 2021
5+
SparkFun code, firmware, and software is released under the MIT License.
6+
Please see LICENSE.md for further details.
7+
8+
This example shows how check for a "Reset Complete" packet from the sensor,
9+
which is helpful when used in tandem with resetReason(). The sensor will be
10+
reset each time 25 readings are received to demonstrate.
11+
12+
*/
13+
14+
#include <Wire.h>
15+
16+
#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080
17+
18+
#define BNO08X_ADDR 0x4B // SparkFun BNO080 Breakout (Qwiic) defaults to 0x4B
19+
//#define BNO08X_ADDR 0x4A // Alternate address if ADR jumper is closed
20+
21+
BNO080 myIMU;
22+
23+
int cyclecount = 0;
24+
25+
26+
// After a reset, reports need to be re-enabled.
27+
void enableReports() {
28+
myIMU.enableGyro(50); //Send data update every 50ms
29+
}
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
Serial.println();
35+
Serial.println("BNO080 Read Example");
36+
37+
Wire.begin();
38+
Wire.flush();
39+
if (!myIMU.begin(BNO08X_ADDR)) {
40+
Serial.println("Could Not Enable BNO Sensor! Check your I2C Address.");
41+
return;
42+
}
43+
44+
enableReports();
45+
46+
Serial.println(F("Gyro enabled"));
47+
Serial.println(F("Output in form x, y, z, in radians per second"));
48+
}
49+
50+
void loop()
51+
{
52+
// One of these will appear at the very start because of the power on reset.
53+
// Check resetReason() for the difference between different resets.
54+
if (myIMU.hasReset()) {
55+
Serial.println(" ------------------ BNO085 has reset. ------------------ ");
56+
Serial.print(F(" Reason: "));
57+
Serial.println(myIMU.resetReason());
58+
enableReports(); // We'll need to re-enable reports after any reset.
59+
}
60+
61+
//Look for reports from the IMU
62+
if (myIMU.dataAvailable())
63+
{
64+
cyclecount++;
65+
66+
Serial.print(F("["));
67+
if (cyclecount < 10) Serial.print(F("0"));
68+
Serial.print(cyclecount);
69+
Serial.print(F("] "));
70+
71+
float x = myIMU.getGyroX();
72+
float y = myIMU.getGyroY();
73+
float z = myIMU.getGyroZ();
74+
75+
Serial.print(x, 2);
76+
Serial.print(F(","));
77+
Serial.print(y, 2);
78+
Serial.print(F(","));
79+
Serial.print(z, 2);
80+
Serial.print(F(","));
81+
82+
Serial.println();
83+
84+
if (cyclecount == 25) {
85+
myIMU.softReset();
86+
cyclecount=0;
87+
}
88+
89+
}
90+
}

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enableDebugging KEYWORD2
1919

2020
softReset KEYWORD2
2121
resetReason KEYWORD2
22+
hasReset KEYWORD2
2223
modeOn KEYWORD2
2324
modeSleep KEYWORD2
2425

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun BNO080 Cortex Based IMU
2-
version=1.1.10
2+
version=1.1.11
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the SparkFun Qwiic VR IMU - BNO080/BNO085

src/SparkFun_BNO080_Arduino_Library.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -504,20 +504,56 @@ void BNO080::getQuat(float &i, float &j, float &k, float &real, float &radAccura
504504
float BNO080::getQuatI()
505505
{
506506
float quat = qToFloat(rawQuatI, rotationVector_Q1);
507+
if (_printDebug == true)
508+
{
509+
if ((quat < -1.0) || (quat > 1.0))
510+
{
511+
_debugPort->print(F("getQuatI: quat: ")); // Debug the occasional non-unitary Quat
512+
_debugPort->print(quat, 2);
513+
_debugPort->print(F(" rawQuatI: "));
514+
_debugPort->print(rawQuatI);
515+
_debugPort->print(F(" rotationVector_Q1: "));
516+
_debugPort->println(rotationVector_Q1);
517+
}
518+
}
507519
return (quat);
508520
}
509521

510522
//Return the rotation vector quaternion J
511523
float BNO080::getQuatJ()
512524
{
513525
float quat = qToFloat(rawQuatJ, rotationVector_Q1);
526+
if (_printDebug == true)
527+
{
528+
if ((quat < -1.0) || (quat > 1.0)) // Debug the occasional non-unitary Quat
529+
{
530+
_debugPort->print(F("getQuatJ: quat: "));
531+
_debugPort->print(quat, 2);
532+
_debugPort->print(F(" rawQuatJ: "));
533+
_debugPort->print(rawQuatJ);
534+
_debugPort->print(F(" rotationVector_Q1: "));
535+
_debugPort->println(rotationVector_Q1);
536+
}
537+
}
514538
return (quat);
515539
}
516540

517541
//Return the rotation vector quaternion K
518542
float BNO080::getQuatK()
519543
{
520544
float quat = qToFloat(rawQuatK, rotationVector_Q1);
545+
if (_printDebug == true)
546+
{
547+
if ((quat < -1.0) || (quat > 1.0)) // Debug the occasional non-unitary Quat
548+
{
549+
_debugPort->print(F("getQuatK: quat: "));
550+
_debugPort->print(quat, 2);
551+
_debugPort->print(F(" rawQuatK: "));
552+
_debugPort->print(rawQuatK);
553+
_debugPort->print(F(" rotationVector_Q1: "));
554+
_debugPort->println(rotationVector_Q1);
555+
}
556+
}
521557
return (quat);
522558
}
523559

@@ -999,6 +1035,16 @@ void BNO080::modeSleep(void)
9991035
; //delay(1);
10001036
}
10011037

1038+
// Indicates if we've received a Reset Complete packet. Once it's been read,
1039+
// the state will reset to false until another Reset Complete packet is found.
1040+
bool BNO080::hasReset() {
1041+
if (_hasReset) {
1042+
_hasReset = false;
1043+
return true;
1044+
}
1045+
return false;
1046+
}
1047+
10021048
//Get the reason for the last reset
10031049
//1 = POR, 2 = Internal reset, 3 = Watchdog, 4 = External reset, 5 = Other
10041050
uint8_t BNO080::resetReason()
@@ -1447,6 +1493,15 @@ boolean BNO080::receivePacket(void)
14471493
getData(dataLength);
14481494
}
14491495

1496+
// Quickly check for reset complete packet. No need for a seperate parser.
1497+
// This function is also called after soft reset, so we need to catch this
1498+
// packet here otherwise we need to check for the reset packet in multiple
1499+
// places.
1500+
if (shtpHeader[2] == CHANNEL_EXECUTABLE && shtpData[0] == EXECUTABLE_RESET_COMPLETE)
1501+
{
1502+
_hasReset = true;
1503+
}
1504+
14501505
return (true); //We're done!
14511506
}
14521507

src/SparkFun_BNO080_Arduino_Library.h

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ const byte CHANNEL_GYRO = 5;
100100
#define FRS_RECORDID_MAGNETIC_FIELD_CALIBRATED 0xE309
101101
#define FRS_RECORDID_ROTATION_VECTOR 0xE30B
102102

103+
// Reset complete packet (BNO08X Datasheet p.24 Figure 1-27)
104+
#define EXECUTABLE_RESET_COMPLETE 0x1
105+
103106
//Command IDs from section 6.4, page 42
104107
//These are used to calibrate, initialize, set orientation, tare etc the sensor
105108
#define COMMAND_ERRORS 1
@@ -131,6 +134,7 @@ class BNO080
131134
void enableDebugging(Stream &debugPort = Serial); //Turn on debug printing. If user doesn't specify then Serial will be used.
132135

133136
void softReset(); //Try to reset the IMU via software
137+
bool hasReset(); //Returns true if the sensor has reported a reset. Reading this will unflag the reset.
134138
uint8_t resetReason(); //Query the IMU for the reason it last reset
135139
void modeOn(); //Use the executable channel to turn the BNO on
136140
void modeSleep(); //Use the executable channel to put the BNO to sleep
@@ -273,6 +277,8 @@ class BNO080
273277
uint8_t _int;
274278
uint8_t _rst;
275279

280+
bool _hasReset = false; // Keeps track of any Reset Complete packets we receive.
281+
276282
//These are the raw sensor values (without Q applied) pulled from the user requested Input Report
277283
uint16_t rawAccelX, rawAccelY, rawAccelZ, accelAccuracy;
278284
uint16_t rawLinAccelX, rawLinAccelY, rawLinAccelZ, accelLinAccuracy;

0 commit comments

Comments
 (0)