Toyomasa Watarai
/
Adafruit-BNO055-test
Adafruit BNO055 test code
main.cpp@2:a062f3e0b04f, 2021-03-16 (annotated)
- Committer:
- MACRUM
- Date:
- Tue Mar 16 05:42:35 2021 +0000
- Revision:
- 2:a062f3e0b04f
- Parent:
- 1:6fbffee6db13
Mbed OS 6.x port
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 | 1:6fbffee6db13 | 9 | I2C i2c(D7, D6); |
simonscott | 0:6d1d015173a3 | 10 | Adafruit_BNO055 bno = Adafruit_BNO055(-1, BNO055_ADDRESS_A, &i2c); |
simonscott | 0:6d1d015173a3 | 11 | |
simonscott | 0:6d1d015173a3 | 12 | void loop(); |
simonscott | 0:6d1d015173a3 | 13 | |
simonscott | 0:6d1d015173a3 | 14 | /**************************************************************************/ |
simonscott | 0:6d1d015173a3 | 15 | /* |
simonscott | 0:6d1d015173a3 | 16 | Arduino setup function (automatically called at startup) |
simonscott | 0:6d1d015173a3 | 17 | */ |
simonscott | 0:6d1d015173a3 | 18 | /**************************************************************************/ |
simonscott | 0:6d1d015173a3 | 19 | int main() |
simonscott | 0:6d1d015173a3 | 20 | { |
MACRUM | 2:a062f3e0b04f | 21 | printf("Orientation Sensor Raw Data Test\r\n"); |
simonscott | 0:6d1d015173a3 | 22 | |
simonscott | 0:6d1d015173a3 | 23 | /* Initialise the sensor */ |
simonscott | 0:6d1d015173a3 | 24 | if(!bno.begin()) |
simonscott | 0:6d1d015173a3 | 25 | { |
simonscott | 0:6d1d015173a3 | 26 | /* There was a problem detecting the BNO055 ... check your connections */ |
MACRUM | 2:a062f3e0b04f | 27 | printf("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!\r\n"); |
simonscott | 0:6d1d015173a3 | 28 | while(1); |
simonscott | 0:6d1d015173a3 | 29 | } |
simonscott | 1:6fbffee6db13 | 30 | else |
MACRUM | 2:a062f3e0b04f | 31 | printf("BNO055 was detected!\r\n"); |
simonscott | 0:6d1d015173a3 | 32 | |
MACRUM | 2:a062f3e0b04f | 33 | thread_sleep_for(1000); |
simonscott | 0:6d1d015173a3 | 34 | |
simonscott | 0:6d1d015173a3 | 35 | /* Display the current temperature */ |
simonscott | 0:6d1d015173a3 | 36 | int8_t temp = bno.getTemp(); |
MACRUM | 2:a062f3e0b04f | 37 | printf("Current Temperature: %d C\r\n", temp); |
simonscott | 0:6d1d015173a3 | 38 | bno.setExtCrystalUse(true); |
simonscott | 0:6d1d015173a3 | 39 | |
MACRUM | 2:a062f3e0b04f | 40 | 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 */ |
MACRUM | 2:a062f3e0b04f | 64 | 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); |
MACRUM | 2:a062f3e0b04f | 83 | printf("CALIBRATION: Sys=%d, Gyro=%d, Accel=%d, Mag=%d\r\n", (int)(system), (int)(gyro), (int)(accel), (int)(mag)); |
MACRUM | 2:a062f3e0b04f | 84 | thread_sleep_for(BNO055_SAMPLERATE_DELAY_MS); |
simonscott | 0:6d1d015173a3 | 85 | } |