BNO044 Demo

Dependencies:   BNO055 mbed

Fork of BNO055_HelloWorld by Dave Turner

Files at this revision

API Documentation at this revision

Comitter:
5hel2l2y
Date:
Fri Jun 17 17:29:08 2016 +0000
Parent:
0:a8e6e26ebe0f
Commit message:
Initial commit for BNO055 demo

Changed in this revision

BNO055.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r a8e6e26ebe0f -r aa7766849e5d BNO055.lib
--- a/BNO055.lib	Sun May 31 07:23:02 2015 +0000
+++ b/BNO055.lib	Fri Jun 17 17:29:08 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/StressedDave/code/BNO055/#1db1628eb8b2
+http://mbed.org/users/StressedDave/code/BNO055/#1f722ffec323
diff -r a8e6e26ebe0f -r aa7766849e5d main.cpp
--- a/main.cpp	Sun May 31 07:23:02 2015 +0000
+++ b/main.cpp	Fri Jun 17 17:29:08 2016 +0000
@@ -1,40 +1,68 @@
+// BNO055 Demo
+
 #include "mbed.h"
 #include "BNO055.h"
 
-Serial pc(USBTX, USBRX);
-BNO055 imu(I2C_SDA,I2C_SCL);
-DigitalOut led(LED1);
+//Serial pc(USBTX, USBRX);
+Serial pc(p9, p11);
+//BNO055 imu(I2C_SDA,I2C_SCL);
+BNO055 imu(p30, p7);
+
+void setup() {
+    pc.baud(115200);
+    
+    pc.printf("\r\n------ BNO055 Demo -----------\r\n");
+      
+    // Reset the BNO055
+    imu.reset();
+    // Check that the BNO055 is connected and display info
+    if (imu.check())
+    {
+        pc.printf("BNO055 found\r\n\r\n");
+        pc.printf("Chip          ID: %d\r\n",imu.ID.id);
+        pc.printf("Accelerometer ID: %d\r\n",imu.ID.accel);
+        pc.printf("Gyroscope     ID: %d\r\n",imu.ID.gyro);
+        pc.printf("Magnetometer  ID: %d\r\n\r\n",imu.ID.mag);
+        pc.printf("Firmware version v%d.%0d\r\n",imu.ID.sw[0],imu.ID.sw[1]);
+        pc.printf("Bootloader version v%d\r\n\r\n",imu.ID.bootload);
+    }
+    
+    // Set power mode, POWER_MODE_NORMAL(default), POWER_MODE_LOWPOWER, or POWER_MODE_SUSPEND(sleep)
+    // By default, I2C will pull high when bus is free(pg90 of datasheet)
+    imu.setpowermode(POWER_MODE_SUSPEND);
+}
 
 int main() {
-    pc.baud(115200);
-    pc.printf("BNO055 Hello World\r\n\r\n");
-    led = 1;
-// Reset the BNO055
-    imu.reset();
-// Check that the BNO055 is connected and flash LED if not
-    if (!imu.check())
-        while (true){
-            led = !led;
-            wait(0.1);
-            }
-// Display sensor information
-    pc.printf("BNO055 found\r\n\r\n");
-    pc.printf("Chip          ID: %0z\r\n",imu.ID.id);
-    pc.printf("Accelerometer ID: %0z\r\n",imu.ID.accel);
-    pc.printf("Gyroscope     ID: %0z\r\n",imu.ID.gyro);
-    pc.printf("Magnetometer  ID: %0z\r\n\r\n",imu.ID.mag);
-    pc.printf("Firmware version v%d.%0d\r\n",imu.ID.sw[0],imu.ID.sw[1]);
-    pc.printf("Bootloader version v%d\r\n\r\n",imu.ID.bootload);
-// Display chip serial number
-    for (int i = 0; i<4; i++){
-        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]);
-    }
-    pc.printf("\r\n");
+    setup();
+    
     while (true) {
-        imu.setmode(OPERATION_MODE_NDOF);
-        imu.get_calib();
-        imu.get_angles();
-        pc.printf("%0z %5.1d %5.1d %5.1d\r\n",imu.calib,imu.euler.roll,imu.euler.pitch,imu.euler.yaw);
+        imu.setmode(OPERATION_MODE_AMG);
+        pc.printf("Temp:\r\n");
+        imu.set_temp_units(CENTIGRADE);
+        imu.get_temp();
+        pc.printf("TC: %d\r\n", imu.temperature);
+        imu.set_temp_units(FAHRENHEIT);
+        imu.get_temp();
+        pc.printf("TF: %d\r\n", imu.temperature);
+        
+        imu.get_accel();
+        pc.printf("Accel:\r\n");
+        pc.printf("AX: %2f\r\n", imu.accel.x);
+        pc.printf("AY: %2f\r\n", imu.accel.y);
+        pc.printf("AZ: %2f\r\n", imu.accel.z);
+        
+        imu.get_gyro();
+        pc.printf("Gyro:\r\n");
+        pc.printf("GX: %2f\r\n", imu.gyro.x);
+        pc.printf("GY: %2f\r\n", imu.gyro.y);
+        pc.printf("GZ: %2f\r\n", imu.gyro.z);
+        
+        imu.get_mag();
+        pc.printf("Mag:\r\n");
+        pc.printf("MX: %2f\r\n", imu.mag.x);
+        pc.printf("MY: %2f\r\n", imu.mag.y);
+        pc.printf("MZ: %2f\r\n\r\n", imu.mag.z);
+        
         wait(1.0);
     }
 }
diff -r a8e6e26ebe0f -r aa7766849e5d mbed.bld
--- a/mbed.bld	Sun May 31 07:23:02 2015 +0000
+++ b/mbed.bld	Fri Jun 17 17:29:08 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file