|
| 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 configure the sensor with different I2C address and different Wire ports. |
| 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 | + Wire.setClock(400000); //Increase I2C data rate to 400kHz |
| 35 | + |
| 36 | + //The first argument is the I2C address of the sensor, either 0x4B (default) or 0x4A |
| 37 | + //The second is the I2C port to use. Wire, Wire1, softWire, etc. |
| 38 | + myIMU.begin(0x4A, Wire1); |
| 39 | + |
| 40 | + myIMU.enableRotationVector(50); //Send data update every 50ms |
| 41 | + |
| 42 | + Serial.println(F("Rotation vector enabled")); |
| 43 | + Serial.println(F("Output in form i, j, k, real, accuracy")); |
| 44 | +} |
| 45 | + |
| 46 | +void loop() |
| 47 | +{ |
| 48 | + //Look for reports from the IMU |
| 49 | + if (myIMU.dataAvailable() == true) |
| 50 | + { |
| 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(quatI, 2); |
| 58 | + Serial.print(F(",")); |
| 59 | + Serial.print(quatJ, 2); |
| 60 | + Serial.print(F(",")); |
| 61 | + Serial.print(quatK, 2); |
| 62 | + Serial.print(F(",")); |
| 63 | + Serial.print(quatReal, 2); |
| 64 | + Serial.print(F(",")); |
| 65 | + Serial.print(quatRadianAccuracy, 2); |
| 66 | + Serial.print(F(",")); |
| 67 | + |
| 68 | + Serial.println(); |
| 69 | + } |
| 70 | +} |
| 71 | + |
0 commit comments