Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:e801e9081b04, 2015-09-15 (annotated)
- Committer:
- simonscott
- Date:
- Tue Sep 15 23:39:03 2015 +0000
- Revision:
- 0:e801e9081b04
First commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| simonscott | 0:e801e9081b04 | 1 | #include "mbed.h" |
| simonscott | 0:e801e9081b04 | 2 | #include "BNO055.h" |
| simonscott | 0:e801e9081b04 | 3 | |
| simonscott | 0:e801e9081b04 | 4 | Serial pc(USBTX, USBRX); |
| simonscott | 0:e801e9081b04 | 5 | BNO055 imu(D14, D15); |
| simonscott | 0:e801e9081b04 | 6 | DigitalOut led(LED1); |
| simonscott | 0:e801e9081b04 | 7 | DigitalOut imuResetPin(D12); |
| simonscott | 0:e801e9081b04 | 8 | |
| simonscott | 0:e801e9081b04 | 9 | int main() { |
| simonscott | 0:e801e9081b04 | 10 | pc.baud(9600); |
| simonscott | 0:e801e9081b04 | 11 | pc.printf("BNO055 Hello World\r\n\r\n"); |
| simonscott | 0:e801e9081b04 | 12 | led = 1; |
| simonscott | 0:e801e9081b04 | 13 | // Reset the BNO055 |
| simonscott | 0:e801e9081b04 | 14 | imuResetPin = 0; |
| simonscott | 0:e801e9081b04 | 15 | wait(0.1); |
| simonscott | 0:e801e9081b04 | 16 | imuResetPin = 1; |
| simonscott | 0:e801e9081b04 | 17 | wait(1); |
| simonscott | 0:e801e9081b04 | 18 | imu.reset(); |
| simonscott | 0:e801e9081b04 | 19 | // Check that the BNO055 is connected and flash LED if not |
| simonscott | 0:e801e9081b04 | 20 | while (!imu.check()){ |
| simonscott | 0:e801e9081b04 | 21 | led = !led; |
| simonscott | 0:e801e9081b04 | 22 | wait(1); |
| simonscott | 0:e801e9081b04 | 23 | } |
| simonscott | 0:e801e9081b04 | 24 | // Display sensor information |
| simonscott | 0:e801e9081b04 | 25 | pc.printf("BNO055 found\r\n\r\n"); |
| simonscott | 0:e801e9081b04 | 26 | pc.printf("Chip ID: %0z\r\n",imu.ID.id); |
| simonscott | 0:e801e9081b04 | 27 | pc.printf("Accelerometer ID: %0z\r\n",imu.ID.accel); |
| simonscott | 0:e801e9081b04 | 28 | pc.printf("Gyroscope ID: %0z\r\n",imu.ID.gyro); |
| simonscott | 0:e801e9081b04 | 29 | pc.printf("Magnetometer ID: %0z\r\n\r\n",imu.ID.mag); |
| simonscott | 0:e801e9081b04 | 30 | pc.printf("Firmware version v%d.%0d\r\n",imu.ID.sw[0],imu.ID.sw[1]); |
| simonscott | 0:e801e9081b04 | 31 | pc.printf("Bootloader version v%d\r\n\r\n",imu.ID.bootload); |
| simonscott | 0:e801e9081b04 | 32 | // Display chip serial number |
| simonscott | 0:e801e9081b04 | 33 | for (int i = 0; i<4; i++){ |
| simonscott | 0:e801e9081b04 | 34 | pc.printf("%0z.%0z.%0z.%0z\r\n",imu.ID.serial[i*4],imu.ID.serial[i*4+1],imu.ID.serial[i*4+2],imu.ID.serial[i*4+3]); |
| simonscott | 0:e801e9081b04 | 35 | } |
| simonscott | 0:e801e9081b04 | 36 | pc.printf("\r\n"); |
| simonscott | 0:e801e9081b04 | 37 | |
| simonscott | 0:e801e9081b04 | 38 | imu.SetExternalCrystal(true); |
| simonscott | 0:e801e9081b04 | 39 | |
| simonscott | 0:e801e9081b04 | 40 | while (true) { |
| simonscott | 0:e801e9081b04 | 41 | imu.setmode(OPERATION_MODE_NDOF); |
| simonscott | 0:e801e9081b04 | 42 | imu.get_calib(); |
| simonscott | 0:e801e9081b04 | 43 | imu.get_angles(); |
| simonscott | 0:e801e9081b04 | 44 | pc.printf("%0z %5.1d %5.1d %5.1d\r\n",imu.calib,imu.euler.roll,imu.euler.pitch,imu.euler.yaw); |
| simonscott | 0:e801e9081b04 | 45 | wait(1.0); |
| simonscott | 0:e801e9081b04 | 46 | } |
| simonscott | 0:e801e9081b04 | 47 | } |