Skip to content

Commit 957f73f

Browse files
committed
Adding timestamp function
1 parent e48171b commit 957f73f

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Using the BNO080 IMU
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: December 21st, 2017
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
Feel like supporting our work? Buy a board from SparkFun!
9+
https://www.sparkfun.com/products/14586
10+
11+
This example shows how to output the timestamp for each reading.
12+
13+
It takes about 1ms at 400kHz I2C to read a record from the sensor, but we are polling the sensor continually
14+
between updates from the sensor. Use the interrupt pin on the BNO080 breakout to avoid polling.
15+
16+
Hardware Connections:
17+
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
18+
Plug the sensor onto the shield
19+
Serial.print it out at 9600 baud to serial monitor.
20+
*/
21+
22+
#include <Wire.h>
23+
24+
#include "SparkFun_BNO080_Arduino_Library.h"
25+
BNO080 myIMU;
26+
27+
void setup()
28+
{
29+
Serial.begin(9600);
30+
Serial.println();
31+
Serial.println("BNO080 Read Example");
32+
33+
Wire.begin();
34+
35+
myIMU.begin();
36+
37+
Wire.setClock(400000); //Increase I2C data rate to 400kHz
38+
39+
myIMU.enableRotationVector(50); //Send data update every 50ms
40+
41+
Serial.println(F("Rotation vector enabled"));
42+
Serial.println(F("Output in form time, i, j, k, real, accuracy"));
43+
}
44+
45+
void loop()
46+
{
47+
//Look for reports from the IMU
48+
if (myIMU.dataAvailable() == true)
49+
{
50+
unsigned long timeStamp = myIMU.getTimeStamp();
51+
float quatI = myIMU.getQuatI();
52+
float quatJ = myIMU.getQuatJ();
53+
float quatK = myIMU.getQuatK();
54+
float quatReal = myIMU.getQuatReal();
55+
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
56+
57+
Serial.print(timeStamp);
58+
Serial.print(F(","));
59+
Serial.print(quatI, 2);
60+
Serial.print(F(","));
61+
Serial.print(quatJ, 2);
62+
Serial.print(F(","));
63+
Serial.print(quatK, 2);
64+
Serial.print(F(","));
65+
Serial.print(quatReal, 2);
66+
Serial.print(F(","));
67+
Serial.print(quatRadianAccuracy, 2);
68+
Serial.print(F(","));
69+
70+
Serial.println();
71+
}
72+
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ saveCalibration KEYWORD2
8080
requestCalibrationStatus KEYWORD2
8181
calibrationComplete KEYWORD2
8282

83+
getTimeStamp KEYWORD2
8384
getStepCount KEYWORD2
8485
getStabilityClassifier KEYWORD2
8586
getActivityClassifier KEYWORD2

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ void BNO080::parseInputReport(void)
218218

219219
dataLength -= 4; //Remove the header bytes from the data count
220220

221+
timeStamp = ((uint32_t)shtpData[4] << (8 * 3)) | (shtpData[3] << (8 * 2)) | (shtpData[2] << (8 * 1)) | (shtpData[1] << (8 * 0));
222+
221223
uint8_t status = shtpData[5 + 2] & 0x03; //Get status bits
222224
uint16_t data1 = (uint16_t)shtpData[5 + 5] << 8 | shtpData[5 + 4];
223225
uint16_t data2 = (uint16_t)shtpData[5 + 7] << 8 | shtpData[5 + 6];
@@ -478,6 +480,12 @@ uint8_t BNO080::getActivityClassifier()
478480
return (activityClassifier);
479481
}
480482

483+
//Return the time stamp
484+
uint32_t BNO080::getTimeStamp()
485+
{
486+
return (timeStamp);
487+
}
488+
481489
//Given a record ID, read the Q1 value from the metaData record in the FRS (ya, it's complicated)
482490
//Q1 is used for all sensor data calculations
483491
int16_t BNO080::getQ1(uint16_t recordID)

src/SparkFun_BNO080_Arduino_Library.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ class BNO080 {
203203
void requestCalibrationStatus(); //Sends command to get status
204204
boolean calibrationComplete(); //Checks ME Cal response for byte 5, R0 - Status
205205

206-
uint16_t getStepCount();
206+
uint32_t getTimeStamp();
207+
uint16_t getStepCount();
207208
uint8_t getStabilityClassifier();
208209
uint8_t getActivityClassifier();
209210

@@ -252,7 +253,8 @@ class BNO080 {
252253
uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy;
253254
uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy;
254255
uint16_t stepCount;
255-
uint8_t stabilityClassifier;
256+
uint32_t timeStamp;
257+
uint8_t stabilityClassifier;
256258
uint8_t activityClassifier;
257259
uint8_t *_activityConfidences; //Array that store the confidences of the 9 possible activities
258260
uint8_t calibrationStatus; //Byte R0 of ME Calibration Response

0 commit comments

Comments
 (0)