|
| 1 | +/* |
| 2 | + Using the BNO080 IMU |
| 3 | + By: Bastien Boudet |
| 4 | + Date: February 3rd, 2022 |
| 5 | + SparkFun code, firmware, and software is released under the MIT License. |
| 6 | + Please see LICENSE.md for further details. |
| 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 parts of the uncalibrated gyro. |
| 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 115200 baud to serial monitor. |
| 20 | +*/ |
| 21 | + |
| 22 | +#include <Wire.h> |
| 23 | + |
| 24 | +#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080 |
| 25 | +BNO080 myIMU; |
| 26 | + |
| 27 | +void setup() |
| 28 | +{ |
| 29 | + Serial.begin(115200); |
| 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.enableUncalibratedGyro(50); //Send data update every 50ms |
| 40 | + |
| 41 | + Serial.println(F("Uncalibrated Gyro enabled")); |
| 42 | + Serial.println(F("Output in form x, y, z, bx, by, bz in radians per second")); |
| 43 | +} |
| 44 | + |
| 45 | +void loop() |
| 46 | +{ |
| 47 | + //Look for reports from the IMU |
| 48 | + if (myIMU.dataAvailable() == true) |
| 49 | + { |
| 50 | + float x = myIMU.getUncalibratedGyroX(); |
| 51 | + float y = myIMU.getUncalibratedGyroY(); |
| 52 | + float z = myIMU.getUncalibratedGyroZ(); |
| 53 | + float bx = myIMU.getUncalibratedGyroBiasX(); |
| 54 | + float by = myIMU.getUncalibratedGyroBiasY(); |
| 55 | + float bz = myIMU.getUncalibratedGyroBiasZ(); |
| 56 | + |
| 57 | + |
| 58 | + Serial.print(x, 2); |
| 59 | + Serial.print(F(",")); |
| 60 | + Serial.print(y, 2); |
| 61 | + Serial.print(F(",")); |
| 62 | + Serial.print(z, 2); |
| 63 | + Serial.print(F(",")); |
| 64 | + |
| 65 | + Serial.print(bx, 2); |
| 66 | + Serial.print(F(",")); |
| 67 | + Serial.print(by, 2); |
| 68 | + Serial.print(F(",")); |
| 69 | + Serial.print(bz, 2); |
| 70 | + Serial.print(F(",")); |
| 71 | + |
| 72 | + Serial.println(); |
| 73 | + } |
| 74 | +} |
0 commit comments