
Originally Posted by
Don Kelly
3) After running this via I2C for awhile, I thought I'd try the SPI interface. I expected to see a huge speed increase, but don't think I'm seeing that. Maybe someone has a suggestion here. Is there a simple way for me to see how fast the I2C version is running vs. the SPI version? The Sparkfun lib sets the sensor speeds using "myIMU.enableGyro(5);" for example, to set the gyro to 5ms (200Hz) updates. How do I tell what I'm really getting? The sensors should be able to be run at 400Hz, but that'd be an input of "myIMU.enableGyro(2.5);" yet only integers are allowed by the lib it seems.
Hi Don,
I am also working with the BNO080 and also switched from I2C to SPI due to speed. The main difference you might see is the time it takes for pulling data from the sensor. Therefore you need to measure the time, which it takes to evaluate "myIMU.dataAvailable()".
The update rates should be similar for I2C and SPI, you can use the following code to check:
Code:
#include <SPI.h>
#include <SparkFun_BNO080_Arduino_Library.h>
BNO080 myIMU;
//These pins can be any GPIO
byte imuCSPin = 10;
byte imuWAKPin = 14;
byte imuINTPin = 16;
byte imuRSTPin = 15;
unsigned long lastUpdate; //Used for calc'ing Hz
void setup()
{
Serial.begin(115200);
while (!Serial) {delay(100);}
Serial.println("BNO080 SPI Read Example");
if(myIMU.beginSPI(imuCSPin, imuWAKPin, imuINTPin, imuRSTPin, 3000000) == false)
{
Serial.println("BNO080 over SPI not detected. Are you sure you have all 6 connections? Freezing...");
while(1);
}
//The IMU is now connected over SPI
//Please see the other examples for library functions that you can call
myIMU.enableRotationVector(10); //Send data update every 10ms
lastUpdate = micros();
}
void loop()
{
// Look for reports from the IMU
if (myIMU.dataAvailable() == true)
{
Serial.print(1000000.0/(float)(micros()-lastUpdate), 2);
// Serial.print(F("Hz"));
Serial.println();
lastUpdate = micros();
}
}
To enable the update rate of 400Hz, you need to do some minor changes in the sparkfun library. The sample time is converted to microseconds in the library and only this value is used, hence you can change the enableFunctions input to take microseconds instead of milliseconds. But only sample rates supported by the sensor will work. You need to replace these lines in the library
Code:
void BNO080::setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports, uint32_t specificConfig)
{
long microsBetweenReports = (long)timeBetweenReports * 1000L;
shtpData[0] = SHTP_REPORT_SET_FEATURE_COMMAND; //Set feature command. Reference page 55
shtpData[1] = reportID; //Feature Report ID. 0x01 = Accelerometer, 0x05 = Rotation vector
shtpData[2] = 0; //Feature flags
shtpData[3] = 0; //Change sensitivity (LSB)
shtpData[4] = 0; //Change sensitivity (MSB)
shtpData[5] = (microsBetweenReports >> 0) & 0xFF; //Report interval (LSB) in microseconds. 0x7A120 = 500ms
shtpData[6] = (microsBetweenReports >> 8) & 0xFF; //Report interval
shtpData[7] = (microsBetweenReports >> 16) & 0xFF; //Report interval
shtpData[8] = (microsBetweenReports >> 24) & 0xFF; //Report interval (MSB)
shtpData[9] = 0; //Batch Interval (LSB)
shtpData[10] = 0; //Batch Interval
shtpData[11] = 0; //Batch Interval
shtpData[12] = 0; //Batch Interval (MSB)
shtpData[13] = (specificConfig >> 0) & 0xFF; //Sensor-specific config (LSB)
shtpData[14] = (specificConfig >> 8) & 0xFF; //Sensor-specific config
shtpData[15] = (specificConfig >> 16) & 0xFF; //Sensor-specific config
shtpData[16] = (specificConfig >> 24) & 0xFF; //Sensor-specific config (MSB)
with
Code:
void BNO080::setFeatureCommand(uint8_t reportID, uint32_t timeBetweenReports, uint32_t specificConfig)
{
shtpData[0] = SHTP_REPORT_SET_FEATURE_COMMAND; //Set feature command. Reference page 55
shtpData[1] = reportID; //Feature Report ID. 0x01 = Accelerometer, 0x05 = Rotation vector
shtpData[2] = 0; //Feature flags
shtpData[3] = 0; //Change sensitivity (LSB)
shtpData[4] = 0; //Change sensitivity (MSB)
shtpData[5] = (timeBetweenReports >> 0) & 0xFF; //Report interval (LSB) in microseconds. 0x7A120 = 500ms
shtpData[6] = (timeBetweenReports >> 8) & 0xFF; //Report interval
shtpData[7] = (timeBetweenReports >> 16) & 0xFF; //Report interval
shtpData[8] = (timeBetweenReports >> 24) & 0xFF; //Report interval (MSB)
shtpData[9] = 0; //Batch Interval (LSB)
shtpData[10] = 0; //Batch Interval
shtpData[11] = 0; //Batch Interval
shtpData[12] = 0; //Batch Interval (MSB)
shtpData[13] = (specificConfig >> 0) & 0xFF; //Sensor-specific config (LSB)
shtpData[14] = (specificConfig >> 8) & 0xFF; //Sensor-specific config
shtpData[15] = (specificConfig >> 16) & 0xFF; //Sensor-specific config
shtpData[16] = (specificConfig >> 24) & 0xFF; //Sensor-specific config (MSB)
and you also need to change the type of "timeBetweenReports" in all function declarations and definitions from "uint16_t" to "uint32_t"