Adafruit BNO055 test program.
Dependencies: Adafruit_BNO055 mbed
main.cpp@1:6fbffee6db13, 2015-09-16 (annotated)
- Committer:
- simonscott
- Date:
- Wed Sep 16 22:32:34 2015 +0000
- Revision:
- 1:6fbffee6db13
- Parent:
- 0:6d1d015173a3
Changed I2C pins
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:6fbffee6db13 | 10 | I2C i2c(D7, D6); |
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 | 1:6fbffee6db13 | 32 | else |
simonscott | 1:6fbffee6db13 | 33 | pc.printf("BNO055 was detected!\r\n"); |
simonscott | 0:6d1d015173a3 | 34 | |
simonscott | 0:6d1d015173a3 | 35 | wait(1); |
simonscott | 0:6d1d015173a3 | 36 | |
simonscott | 0:6d1d015173a3 | 37 | /* Display the current temperature */ |
simonscott | 0:6d1d015173a3 | 38 | int8_t temp = bno.getTemp(); |
simonscott | 0:6d1d015173a3 | 39 | pc.printf("Current Temperature: %d C\r\n", temp); |
simonscott | 0:6d1d015173a3 | 40 | bno.setExtCrystalUse(true); |
simonscott | 0:6d1d015173a3 | 41 | |
simonscott | 0:6d1d015173a3 | 42 | pc.printf("Calibration status values: 0=uncalibrated, 3=fully calibrated\r\n"); |
simonscott | 0:6d1d015173a3 | 43 | |
simonscott | 0:6d1d015173a3 | 44 | while(true) |
simonscott | 0:6d1d015173a3 | 45 | loop(); |
simonscott | 0:6d1d015173a3 | 46 | } |
simonscott | 0:6d1d015173a3 | 47 | |
simonscott | 0:6d1d015173a3 | 48 | /**************************************************************************/ |
simonscott | 0:6d1d015173a3 | 49 | /* |
simonscott | 0:6d1d015173a3 | 50 | Arduino loop function, called once 'setup' is complete (your own code |
simonscott | 0:6d1d015173a3 | 51 | should go here) |
simonscott | 0:6d1d015173a3 | 52 | */ |
simonscott | 0:6d1d015173a3 | 53 | /**************************************************************************/ |
simonscott | 0:6d1d015173a3 | 54 | void loop(void) |
simonscott | 0:6d1d015173a3 | 55 | { |
simonscott | 0:6d1d015173a3 | 56 | // Possible vector values can be: |
simonscott | 0:6d1d015173a3 | 57 | // - VECTOR_ACCELEROMETER - m/s^2 |
simonscott | 0:6d1d015173a3 | 58 | // - VECTOR_MAGNETOMETER - uT |
simonscott | 0:6d1d015173a3 | 59 | // - VECTOR_GYROSCOPE - rad/s |
simonscott | 0:6d1d015173a3 | 60 | // - VECTOR_EULER - degrees |
simonscott | 0:6d1d015173a3 | 61 | // - VECTOR_LINEARACCEL - m/s^2 |
simonscott | 0:6d1d015173a3 | 62 | // - VECTOR_GRAVITY - m/s^2 |
simonscott | 0:6d1d015173a3 | 63 | imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER); |
simonscott | 0:6d1d015173a3 | 64 | |
simonscott | 0:6d1d015173a3 | 65 | /* Display the floating point data */ |
simonscott | 0:6d1d015173a3 | 66 | pc.printf("X: %f Y: %f Z: %f\t\t", euler.x(), euler.y(), euler.z()); |
simonscott | 0:6d1d015173a3 | 67 | |
simonscott | 0:6d1d015173a3 | 68 | /* |
simonscott | 0:6d1d015173a3 | 69 | // Quaternion data |
simonscott | 0:6d1d015173a3 | 70 | imu::Quaternion quat = bno.getQuat(); |
simonscott | 0:6d1d015173a3 | 71 | Serial.print("qW: "); |
simonscott | 0:6d1d015173a3 | 72 | Serial.print(quat.w(), 4); |
simonscott | 0:6d1d015173a3 | 73 | Serial.print(" qX: "); |
simonscott | 0:6d1d015173a3 | 74 | Serial.print(quat.y(), 4); |
simonscott | 0:6d1d015173a3 | 75 | Serial.print(" qY: "); |
simonscott | 0:6d1d015173a3 | 76 | Serial.print(quat.x(), 4); |
simonscott | 0:6d1d015173a3 | 77 | Serial.print(" qZ: "); |
simonscott | 0:6d1d015173a3 | 78 | Serial.print(quat.z(), 4); |
simonscott | 0:6d1d015173a3 | 79 | Serial.print("\t\t"); |
simonscott | 0:6d1d015173a3 | 80 | */ |
simonscott | 0:6d1d015173a3 | 81 | |
simonscott | 0:6d1d015173a3 | 82 | /* Display calibration status for each sensor. */ |
simonscott | 0:6d1d015173a3 | 83 | uint8_t system, gyro, accel, mag = 0; |
simonscott | 0:6d1d015173a3 | 84 | bno.getCalibration(&system, &gyro, &accel, &mag); |
simonscott | 0:6d1d015173a3 | 85 | pc.printf("CALIBRATION: Sys=%d, Gyro=%d, Accel=%d, Mag=%d\r\n", (int)(system), (int)(gyro), (int)(accel), (int)(mag)); |
simonscott | 0:6d1d015173a3 | 86 | wait_ms(BNO055_SAMPLERATE_DELAY_MS); |
simonscott | 0:6d1d015173a3 | 87 | } |