Qwiic VR IMU (BNO080) Hookup Guide

Pages
Contributors: Englandsaurus
Favorited Favorite 3

Library Overview

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

Before we get into programming our IMU, let's download and check out the available functions in our library. SparkFun has written a library to control the Qwiic VR IMU. You can obtain these libraries through the Arduino Library Manager. Search for SparkFun BNO080 Cortex Based IMU and you should be able to install the latest version. If you prefer manually downloading the libraries from the GitHub repository, you can grab them here:

Let's get started by looking at the functions that set up the IMU.

Setup and Settings

  • boolean begin(uint8_t deviceAddress = BNO080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire); --- By default use the default I2C address, and use Wire port, otherwise, pass in a custom I2C address and wire port.

  • void enableDebugging(Stream &debugPort = Serial); --- Turn on debug printing. If user doesn't specify method of printing then Serial will be used.

  • void enableRotationVector(uint16_t timeBetweenReports); --- Enables the rotation vector to give a report every timeBetweenReports ms.
  • void enableGameRotationVector(uint16_t timeBetweenReports); --- Enables the game rotation vector to give a report every timeBetweenReports ms.
  • void enableAccelerometer(uint16_t timeBetweenReports); --- Enables the accelerometer with timeBetweenReports in ms.
  • void enableGyro(uint16_t timeBetweenReports); --- Enables the gyroscope with timeBetweenReports in ms.
  • **void enableMagnetometer(uint16_t timeBetweenReports); --- Enables the magnetometer with timeBetweenReports in ms.
  • void enableStepCounter(uint16_t timeBetweenReports); --- Enables the step counter with timeBetweenReports in ms.
  • void enableStabilityClassifier(uint16_t timeBetweenReports); --- Enables the stability classifier with timeBetweenReports in ms.
  • void enableActivityClassifier(uint16_t timeBetweenReports, uint32_t activitiesToEnable,
         uint8_t (&activityConfidences)[9]); --- Enables the activity classifier with a timeBetweenReports (in ms), the activitiesToEnable (0x1F to enable all activities) and the activityConfidences[9] array to store the IMU's confidence that the activity is occurring.

  • void softReset(); --- Try to reset the IMU via software

  • uint8_t resetReason(); --- Query the IMU for the reason it last reset

  • float qToFloat(int16_t fixedPointValue, uint8_t qPoint); --- Given a Q value, converts fixed point floating to regular floating point number

  • void setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports(); --- Used to enable different sensors and functions (features) of the IMU with to report with timeBetweenReports ms between reports.

  • void setFeatureCommand(uint8_t reportID, uint16_t timeBetweenReports, uint32_t specificConfig); --- Used to enable different sensors and functions (features) of the IMU with to report with timeBetweenReports ms between reports.
  • void sendCommand(uint8_t command); --- Sends a command to the sensor.
  • void sendCalibrateCommand(uint8_t thingToCalibrate); --- Sends calibrations commands to the sensor of choice. Possible arguments are listed below.
    • CALIBRATE_ACCEL
    • CALIBRATE_GYRO
    • CALIBRATE_MAG
    • CALIBRATE_PLANAR_ACCEL
    • CALIBRATE_ACCEL_GYRO_MAG --- Calibrates all sensors.
    • CALIBRATE_STOP --- Stops all calibration.

Communication and Data Handling

  • boolean waitForI2C(); --- Delay based polling for I2C traffic
  • boolean receivePacket(void); --- Receives an I2C packet from the IMU.
  • boolean getData(uint16_t bytesRemaining); --- Given a number of bytes, send the requests in I2C_BUFFER_LENGTH chunks
  • boolean sendPacket(uint8_t channelNumber, uint8_t dataLength); --- Sends a packet of length dataLength to channelNumber.
  • void printPacket(void); --- Prints the current shtp header and data packets

  • bool dataAvailable(void); --- Checks if new data is available from the IMU.

  • void parseInputReport(void); --- Takes the data from the IMu and places it into the proper variable so they can be properly read.

Getting Values

  • float getQuatI(); --- Retrieves the i-axis quaternion from the IMU.
  • float getQuatJ(); --- Retrieves the j-axis quaternion from the IMU.
  • float getQuatK(); --- Retrieves the k-axis quaternion from the IMU.
  • float getQuatReal(); --- Retrieves the real component of the quaternion from the IMU.
  • float getQuatRadianAccuracy(); --- Retrieves the accuracy of the quaternion from the IMU in radians.
  • uint8_t getQuatAccuracy(); --- Retrieves the accuracy of the quaternion from the IMU.

  • float getAccelX(); --- Retrieves the x-axis acceleration.

  • float getAccelY(); --- Retrieves the y-axis acceleration.
  • float getAccelZ(); --- Retrieves the z-axis acceleration.
  • uint8_t getAccelAccuracy(); --- Retrieves the accuracy of the accelerometer readings.

  • float getGyroX(); --- Retrieves the x-axis gyroscope reading.

  • float getGyroY(); --- Retrieves the y-axis gyroscope reading.
  • float getGyroZ(); --- Retrieves the z-axis gyroscope reading.
  • uint8_t getGyroAccuracy(); --- Retrieves the accuracy of the gyroscope reading.

  • float getMagX(); --- Retrieves the x-axis magnetometer reading.

  • float getMagY(); --- Retrieves the y-axis magnetometer reading.
  • float getMagZ(); --- Retrieves the z-axis magnetometer reading.
  • uint8_t getMagAccuracy(); --- Retrieves the accuracy of the magnetometer reading.

Sensor Calibration

Check the calibration procedure in order to calibrate the IMU with the functions listed below.

  • void calibrateAccelerometer(); --- Begins the calibration function for the IMU's accelerometer.
  • void calibrateGyro(); --- Begins the calibration function for the IMU's gyroscope.
  • void calibrateMagnetometer(); --- Begins the calibration function for the IMU's magnetometer.
  • void calibratePlanarAccelerometer(); --- Begins the planar calibration function for the IMU's accelerometer.
  • void calibrateAll(); --- Begins all calibration functions.
  • void endCalibration(); --- Ends the active calibration functions.
  • void saveCalibration(); --- Saves data from current calibration.

Special Functions

  • uint16_t getStepCount(); --- Gets the number of steps from the BNO080's onboard pedometer.
  • uint8_t getStabilityClassifier(); --- Retrieves the stability classification, a number between 0 and 6.
    • 0 --- Unknown classification
    • 1 --- On table
    • 2 --- Stationary
    • 3 --- Stable
    • 4 --- Motion
    • 5 --- Reserved
  • uint8_t getActivityClassifier(); --- Retrieves the Activity classification, a number between 0 and 8, based on a comparison of the confidence levels in each activity.
    • 0 --- Unknown
    • 1 --- In Vehicle
    • 2 --- On Bicycle
    • 3 --- On Foot
    • 4 --- Still
    • 5 --- Tilting
    • 6 --- Walking
    • 7 --- Running
    • 8 --- On stairs

Metadata Handling Functions

  • int16_t getQ1(uint16_t recordID); --- Given a record ID, read the Q1 value from the metaData record in the Flash Record System (FRS). Q1 is used for all sensor data calculations.
  • int16_t getQ2(uint16_t recordID); --- Given a record ID, read the Q2 value from the metaData record in the FRS. Q2 is used in sensor bias.
  • int16_t getQ3(uint16_t recordID); --- Given a record ID, read the Q3 value from the metaData record in the FRS. Q3 is used in sensor change sensitivity.
  • float getResolution(uint16_t recordID); --- Given a record ID, reads the resolution value from the sensors metadata
  • float getRange(uint16_t recordID); --- Given a record ID, read the range value from the metaData record in the FRS for a given sensor
  • ****uint32_t readFRSword(uint16_t recordID, uint8_t wordNumber);** --- Given a record ID and a word number, find the word data. Used in getQ1(), getResolution(), etc..
  • void frsReadRequest(uint16_t recordID, uint16_t readOffset, uint16_t blockSize); --- Ask the sensor for data from the Flash Record System.
  • bool readFRSdata(uint16_t recordID, uint8_t startLocation, uint8_t wordsToRead); --- Reads data from the Flash Record System.

Global Variables

  • uint8_t shtpHeader[4]; --- In Hillcrest's Sensor Hubtransfer Protocol, each packet has a header of 4 bytes
  • uint8_t shtpData[MAX_PACKET_SIZE]; --- Creates an array for SHTP data to be stored.
  • uint8_t sequenceNumber[6] = {0, 0, 0, 0, 0, 0}; --- There are 6 com channels. Each channel has its own sequence number.
  • uint8_t commandSequenceNumber = 0; --- Commands have a sequence number as well. These are inside command packet, the header uses its own sequence number for each channel.
  • uint32_t metaData[MAX_METADATA_SIZE]; --- There is more than 10 words in a metadata record but we'll stop at Q point 3