Skip to content

Instantly share code, notes, and snippets.

@tstellanova
Last active April 20, 2020 02:00
Show Gist options
  • Save tstellanova/da82f78cfcc6c3b0a7c517f94d2ab97e to your computer and use it in GitHub Desktop.
Save tstellanova/da82f78cfcc6c3b0a7c517f94d2ab97e to your computer and use it in GitHub Desktop.
Testing bno080 with SPI on arduino micro pro
/**
Testing BNO080 arduino library from Sparkfun
With CY-BNO08x breakout board on SPI
Wiring instructions
- Remove three pull-up resistors on SDA, SCL, ADO/MOSI
- PS1 must be closed
- PS0 must be closed (in this example we hardwire WAK always on)
Arduino Micro Pro pin wiring:
15 = SCLK
14 = MISO
16 = MOSI
10 = CSN
9 = WAK (not connected)
8 = HINTN
7 = NRST
3.3V
GND
*/
#include <SPI.h>
#include "SparkFun_BNO080_Arduino_Library.h"
BNO080 myIMU;
//These pins can be any GPIO
byte imuCSPin = 10;
byte imuWAKPin = 9;
byte imuINTPin = 8;
byte imuRSTPin = 7;
unsigned long startTime; //Used for calc'ing Hz
long measurements = 0; //Used for calc'ing Hz
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("BNO080 SPI Read Example");
myIMU.enableDebugging(Serial); //Pipe debug messages to Serial port
if (!myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 3000000)) {
while(1) {
Serial.println("BNO080 beginSPI failed");
delay(25);
}
}
//You can also call begin with SPI clock speed and SPI port hardware
//myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 1000000);
//myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 1000000, SPI1);
//The IMU is now connected over SPI
//Please see the other examples for library functions that you can call
myIMU.enableRotationVector(1); //Send data update every n ms
Serial.println(F("Rotation vector enabled"));
Serial.println(F("Output in form i, j, k, real, accuracy"));
startTime = millis();
}
void loop()
{
if (myIMU.dataAvailable() == true) {
float quatI = myIMU.getQuatI();
float quatJ = myIMU.getQuatJ();
float quatK = myIMU.getQuatK();
float quatReal = myIMU.getQuatReal();
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
measurements++;
Serial.print(quatI, 2);
Serial.print(F(","));
Serial.print(quatJ, 2);
Serial.print(F(","));
Serial.print(quatK, 2);
Serial.print(F(","));
Serial.print(quatReal, 2);
Serial.print(F(","));
Serial.print(quatRadianAccuracy, 2);
Serial.print(F(","));
Serial.print((float)measurements / ((millis() - startTime) / 1000.0), 2);
Serial.print(F("Hz"));
Serial.println();
}
else {
delayMicroseconds(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment