Adafruit BNO055 test program.

Dependencies:   Adafruit_BNO055 mbed

Committer:
simonscott
Date:
Wed Sep 16 19:49:13 2015 +0000
Revision:
0:6d1d015173a3
Child:
1:6fbffee6db13
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simonscott 0:6d1d015173a3 1 #include <Adafruit_Sensor.h>
simonscott 0:6d1d015173a3 2 #include <Adafruit_BNO055.h>
simonscott 0:6d1d015173a3 3 #include <imumaths.h>
simonscott 0:6d1d015173a3 4 #include "mbed.h"
simonscott 0:6d1d015173a3 5
simonscott 0:6d1d015173a3 6 /* Set the delay between fresh samples */
simonscott 0:6d1d015173a3 7 #define BNO055_SAMPLERATE_DELAY_MS (100)
simonscott 0:6d1d015173a3 8
simonscott 0:6d1d015173a3 9 Serial pc(USBTX, USBRX);
simonscott 0:6d1d015173a3 10 I2C i2c(D14, D15);
simonscott 0:6d1d015173a3 11 Adafruit_BNO055 bno = Adafruit_BNO055(-1, BNO055_ADDRESS_A, &i2c);
simonscott 0:6d1d015173a3 12
simonscott 0:6d1d015173a3 13 void loop();
simonscott 0:6d1d015173a3 14
simonscott 0:6d1d015173a3 15 /**************************************************************************/
simonscott 0:6d1d015173a3 16 /*
simonscott 0:6d1d015173a3 17 Arduino setup function (automatically called at startup)
simonscott 0:6d1d015173a3 18 */
simonscott 0:6d1d015173a3 19 /**************************************************************************/
simonscott 0:6d1d015173a3 20 int main()
simonscott 0:6d1d015173a3 21 {
simonscott 0:6d1d015173a3 22 pc.baud(9600);
simonscott 0:6d1d015173a3 23 pc.printf("Orientation Sensor Raw Data Test\r\n");
simonscott 0:6d1d015173a3 24
simonscott 0:6d1d015173a3 25 /* Initialise the sensor */
simonscott 0:6d1d015173a3 26 if(!bno.begin())
simonscott 0:6d1d015173a3 27 {
simonscott 0:6d1d015173a3 28 /* There was a problem detecting the BNO055 ... check your connections */
simonscott 0:6d1d015173a3 29 pc.printf("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!\r\n");
simonscott 0:6d1d015173a3 30 while(1);
simonscott 0:6d1d015173a3 31 }
simonscott 0:6d1d015173a3 32
simonscott 0:6d1d015173a3 33 wait(1);
simonscott 0:6d1d015173a3 34
simonscott 0:6d1d015173a3 35 /* Display the current temperature */
simonscott 0:6d1d015173a3 36 int8_t temp = bno.getTemp();
simonscott 0:6d1d015173a3 37 pc.printf("Current Temperature: %d C\r\n", temp);
simonscott 0:6d1d015173a3 38 bno.setExtCrystalUse(true);
simonscott 0:6d1d015173a3 39
simonscott 0:6d1d015173a3 40 pc.printf("Calibration status values: 0=uncalibrated, 3=fully calibrated\r\n");
simonscott 0:6d1d015173a3 41
simonscott 0:6d1d015173a3 42 while(true)
simonscott 0:6d1d015173a3 43 loop();
simonscott 0:6d1d015173a3 44 }
simonscott 0:6d1d015173a3 45
simonscott 0:6d1d015173a3 46 /**************************************************************************/
simonscott 0:6d1d015173a3 47 /*
simonscott 0:6d1d015173a3 48 Arduino loop function, called once 'setup' is complete (your own code
simonscott 0:6d1d015173a3 49 should go here)
simonscott 0:6d1d015173a3 50 */
simonscott 0:6d1d015173a3 51 /**************************************************************************/
simonscott 0:6d1d015173a3 52 void loop(void)
simonscott 0:6d1d015173a3 53 {
simonscott 0:6d1d015173a3 54 // Possible vector values can be:
simonscott 0:6d1d015173a3 55 // - VECTOR_ACCELEROMETER - m/s^2
simonscott 0:6d1d015173a3 56 // - VECTOR_MAGNETOMETER - uT
simonscott 0:6d1d015173a3 57 // - VECTOR_GYROSCOPE - rad/s
simonscott 0:6d1d015173a3 58 // - VECTOR_EULER - degrees
simonscott 0:6d1d015173a3 59 // - VECTOR_LINEARACCEL - m/s^2
simonscott 0:6d1d015173a3 60 // - VECTOR_GRAVITY - m/s^2
simonscott 0:6d1d015173a3 61 imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
simonscott 0:6d1d015173a3 62
simonscott 0:6d1d015173a3 63 /* Display the floating point data */
simonscott 0:6d1d015173a3 64 pc.printf("X: %f Y: %f Z: %f\t\t", euler.x(), euler.y(), euler.z());
simonscott 0:6d1d015173a3 65
simonscott 0:6d1d015173a3 66 /*
simonscott 0:6d1d015173a3 67 // Quaternion data
simonscott 0:6d1d015173a3 68 imu::Quaternion quat = bno.getQuat();
simonscott 0:6d1d015173a3 69 Serial.print("qW: ");
simonscott 0:6d1d015173a3 70 Serial.print(quat.w(), 4);
simonscott 0:6d1d015173a3 71 Serial.print(" qX: ");
simonscott 0:6d1d015173a3 72 Serial.print(quat.y(), 4);
simonscott 0:6d1d015173a3 73 Serial.print(" qY: ");
simonscott 0:6d1d015173a3 74 Serial.print(quat.x(), 4);
simonscott 0:6d1d015173a3 75 Serial.print(" qZ: ");
simonscott 0:6d1d015173a3 76 Serial.print(quat.z(), 4);
simonscott 0:6d1d015173a3 77 Serial.print("\t\t");
simonscott 0:6d1d015173a3 78 */
simonscott 0:6d1d015173a3 79
simonscott 0:6d1d015173a3 80 /* Display calibration status for each sensor. */
simonscott 0:6d1d015173a3 81 uint8_t system, gyro, accel, mag = 0;
simonscott 0:6d1d015173a3 82 bno.getCalibration(&system, &gyro, &accel, &mag);
simonscott 0:6d1d015173a3 83 pc.printf("CALIBRATION: Sys=%d, Gyro=%d, Accel=%d, Mag=%d\r\n", (int)(system), (int)(gyro), (int)(accel), (int)(mag));
simonscott 0:6d1d015173a3 84 wait_ms(BNO055_SAMPLERATE_DELAY_MS);
simonscott 0:6d1d015173a3 85 }