Skip to content

Commit 90dd9ad

Browse files
committed
Adding example to address issue 18
1 parent 55bffa1 commit 90dd9ad

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Using the BNO080 IMU
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: July 27th, 2018
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/14686
10+
11+
This example shows how to use the SPI interface and print two records at the same time:
12+
Accel and Quat.
13+
14+
This example shows how to output the i/j/k/real parts of the rotation vector.
15+
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
16+
17+
Hardware modifications:
18+
The PS1 jumper must be closed
19+
The PS0 jumper must be open. PS0/WAKE is connected and the WAK pin is used to bring the IC out of sleep.
20+
The I2C pull up jumper must be cleared/open
21+
22+
Hardware Connections:
23+
Don't hook the BNO080 to a normal 5V Uno! Either use the Qwiic system or use a
24+
microcontroller that runs at 3.3V.
25+
Arduino 13 = BNO080 SCK
26+
12 = SO
27+
11 = SI
28+
10 = !CS
29+
9 = WAK
30+
8 = !INT
31+
7 = !RST
32+
3.3V = 3V3
33+
GND = GND
34+
*/
35+
36+
#include <SPI.h>
37+
38+
#include "SparkFun_BNO080_Arduino_Library.h"
39+
BNO080 myIMU;
40+
41+
//These pins can be any GPIO
42+
byte imuCSPin = 10;
43+
byte imuWAKPin = 9;
44+
byte imuINTPin = 8;
45+
byte imuRSTPin = 7;
46+
47+
void setup()
48+
{
49+
Serial.begin(115200);
50+
Serial.println();
51+
Serial.println("BNO080 SPI Read Example");
52+
53+
myIMU.enableDebugging(Serial); //Pipe debug messages to Serial port
54+
55+
if (myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin) == false)
56+
{
57+
Serial.println("BNO080 over SPI not detected. Are you sure you have all 6 connections? Freezing...");
58+
while (1);
59+
}
60+
61+
//You can also call begin with SPI clock speed and SPI port hardware
62+
//myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 1000000);
63+
//myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 1000000, SPI1);
64+
65+
//The IMU is now connected over SPI
66+
//Please see the other examples for library functions that you can call
67+
68+
myIMU.enableAccelerometer(10); //Send data update at 100Hz
69+
myIMU.enableRotationVector(10); //Send data update at 100Hz
70+
71+
Serial.println(F("Rotation vector enabled"));
72+
Serial.println(F("Output in form i, j, k, real, accuracy"));
73+
}
74+
75+
void loop()
76+
{
77+
//Look for reports from the IMU
78+
if (myIMU.dataAvailable() == true)
79+
{
80+
float x = myIMU.getAccelX();
81+
float y = myIMU.getAccelY();
82+
float z = myIMU.getAccelZ();
83+
84+
float quatI = myIMU.getQuatI();
85+
float quatJ = myIMU.getQuatJ();
86+
float quatK = myIMU.getQuatK();
87+
float quatReal = myIMU.getQuatReal();
88+
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
89+
90+
Serial.print(x, 2);
91+
Serial.print(F(","));
92+
Serial.print(y, 2);
93+
Serial.print(F(","));
94+
Serial.print(z, 2);
95+
96+
Serial.print(quatI, 2);
97+
Serial.print(F(","));
98+
Serial.print(quatJ, 2);
99+
Serial.print(F(","));
100+
Serial.print(quatK, 2);
101+
Serial.print(F(","));
102+
Serial.print(quatReal, 2);
103+
Serial.print(F(","));
104+
Serial.print(quatRadianAccuracy, 2);
105+
Serial.print(F(","));
106+
107+
Serial.println();
108+
}
109+
110+
}

0 commit comments

Comments
 (0)