Works

Dependencies:   BMP180 BNO055_fusion Fonts GPSISR HTU21D SDFileSystem UniGraphic mbed uGUI

Fork of Bicycl_Computer_NUCLEO-F411RE by Darren Ulrich

Revision:
14:4f0ebc5a4f00
Parent:
13:1a9c0f9d7128
Child:
15:b174ec6e3ca0
--- a/main.cpp	Wed Mar 01 03:39:33 2017 +0000
+++ b/main.cpp	Fri Mar 03 02:56:25 2017 +0000
@@ -64,14 +64,6 @@
 
 #define PI                  3.14159265358979f
 
-
-BNO055_ID_INF_TypeDef       bno055_id_inf;
-BNO055_EULER_TypeDef        euler_angles;
-BNO055_QUATERNION_TypeDef   quaternion;
-BNO055_LIN_ACC_TypeDef      linear_acc;
-BNO055_GRAVITY_TypeDef      gravity;
-BNO055_TEMPERATURE_TypeDef  chip_temp;
-
 #define DEVICE_NAME     "F411RE"
 
 #ifndef TARGET_NECLEO_F411RE
@@ -93,7 +85,7 @@
 TouchScreen TSC(PIN_XP, PIN_XM, PIN_YP, PIN_YM);
 
 // 3 Axis IMU
-BNO055 imu(I2C_SDA, I2C_SCL, PIN_RESET);  // Reset =D7, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default
+BNO055 imu(I2C_SDA, I2C_SCL);  // New Library Adafruit
 
 // Humidity and Temperature
 HTU21D humid(I2C_SDA, I2C_SCL);
@@ -142,58 +134,58 @@
         
     while (1) { 
              
-                TFT.set_font((unsigned char*) ArialR20x20);
-                //check if we recieved a new message from GPS, if so, attempt to parse it,
+        TFT.set_font((unsigned char*) ArialR20x20);
+        //check if we recieved a new message from GPS, if so, attempt to parse it,
         if (refresh_Timer.read_ms() >= refresh_Time) {
             refresh_Timer.reset();
                         
-                        if (bmp180.init() != 0) {
-                                //pc.printf("Error communicating with BMP180\n");
-                                } else {
-                                //pc.printf("Initialized BMP180\n");
-                                bmp180.startTemperature();
-                                wait(0.1);     // Wait for conversion to complete
-                                float temp;
-                                if(bmp180.getTemperature(&temp) != 0) {
-                                        //pc.printf("Error getting temperature\n");
-                                }
-                        //pc.printf("Temperature is : %f", temp);
-                        TFT.locate(4, 26) ;
-                        TFT.printf("%.1fF", ((temp* 9.0) / 5.0 + 32));
-                        }
-                        int ftemp = humid.sample_ftemp();
-                        int humidity = humid.sample_humid();
-                        TFT.locate(140, 26) ;
-                        TFT.printf("%d%%RH",humidity);
-                        //pc.printf("HTU21D Temp: %d",ftemp);
-                        //pc.printf("HTU21D Humidity: %d",humidity);
+            if (bmp180.init() != 0) {
+                //pc.printf("Error communicating with BMP180\n");
+            } else {
+                //pc.printf("Initialized BMP180\n");
+                bmp180.startTemperature();
+                wait(0.1);     // Wait for conversion to complete
+                float temp;
+                if(bmp180.getTemperature(&temp) != 0) {
+                    //pc.printf("Error getting temperature\n");
+                }
+                //pc.printf("Temperature is : %f", temp);
+                TFT.locate(4, 26) ;
+                TFT.printf("%.1fF", ((temp* 9.0) / 5.0 + 32));
+            }
+            int ftemp = humid.sample_ftemp();
+            int humidity = humid.sample_humid();
+            TFT.locate(140, 26) ;
+            TFT.printf("%d%%RH",humidity);
+            //pc.printf("HTU21D Temp: %d",ftemp);
+            //pc.printf("HTU21D Humidity: %d",humidity);
     
-                        if (imu.chip_ready() == 0){
-                            pc.printf("Bosch BNO055 is NOT avirable!!\r\n");
+            if (imu.check() == 0){
+                pc.printf("Bosch BNO055 is NOT avirable!!\r\n");
+            } else {
+                //printf("Cal %d", imu.read_calib_status());
+                imu.get_calib();
+                if (imu.cal.system > 0x0){
+                    TFT.foreground(White);
+                    TFT.locate(4, 260) ;
+                    TFT.printf("No Data");
+                    TFT.foreground(Blue);
+                    imu.get_angles();
+                    TFT.locate(4, 260) ;
+                    TFT.printf("%.1f",imu.euler.yaw);
+                    //pc.printf("H %.1f",euler_angles.h);
+                    //pc.printf("R %.1f",euler_angles.r);
+                    //pc.printf("P %.1f",euler_angles.p);
+                            
                 } else {
-                            //printf("Cal %d", imu.read_calib_status());
-                            if (imu.read_calib_status() > 0x0){
-                                TFT.foreground(White);
-                                TFT.locate(4, 260) ;
-                                TFT.printf("No Data");
-                                TFT.foreground(Blue);
-                                imu.get_Euler_Angles(&euler_angles);
-                                imu.get_quaternion(&quaternion);
-                                TFT.locate(4, 260) ;
-                                TFT.printf("%.1f",euler_angles.h);
-                                //pc.printf("H %.1f",euler_angles.h);
-                                //pc.printf("R %.1f",euler_angles.r);
-                                //pc.printf("P %.1f",euler_angles.p);
-                            
-                            } else {
-                                    TFT.locate(4, 260) ;
-                                    TFT.printf("No Data");
-                            }
-                        }
+                    TFT.locate(4, 260) ;
+                    TFT.printf("No Data");
+                }
+            }
 
-                         float angle = int(euler_angles.h); // * 180/PI); // Convert radians to degrees for more a more usual result
-                         // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions
-                         float dx = (0.7*radius * cos((angle-90)*PI/180)) + centreX;  // calculate X position for the screen coordinates - can be confusing!
+             float angle = int(imu.euler.yaw); // * 180/PI); // Convert radians to degrees for more a more usual result
+             // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions
+             float dx = (0.7*radius * cos((angle-90)*PI/180)) + centreX;  // calculate X position for the screen coordinates - can be confusing!
              float dy = (0.7*radius * sin((angle-90)*PI/180)) + centreY;  // calculate Y position for the screen coordinates - can be confusing!
              arrow(last_dx,last_dy, centreX, centreY, 2,2,White);      // Erase last arrow      
              arrow(dx,dy, centreX, centreY, 2, 2,Blue);               // Draw arrow in new position
@@ -207,45 +199,42 @@
                 //pc.printf("%d-%d-%d\n", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
                 //pc.printf("%d:%d:%d\n", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
                 
-                                TFT.foreground(White);
-                                TFT.locate(4, 2) ;
-                                TFT.printf("No Data");
+                TFT.foreground(White);
+                TFT.locate(4, 2) ;
+                TFT.printf("No Data");
                 TFT.foreground(Blue);
                 TFT.locate(4, 2) ;
                 TFT.printf("%d-%d-%d", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
-                                TFT.locate(4, 50) ;
-                                double waypoint = nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon)/double(1609.344);
-                                TFT.printf("%.1fMI From Perry", waypoint);
+                TFT.locate(4, 50) ;
+                double waypoint = nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon)/double(1609.344);
+                TFT.printf("%.1fMI From Perry", waypoint);
                 TFT.locate(140, 2) ;
                 TFT.printf("%d:%d:%d", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
-                                TFT.locate(140, 260) ;
+                TFT.locate(140, 260) ;
                 TFT.printf("%.1fft", MyGPS.buffer.altitude/0.3048);
-                                TFT.locate(4, 280) ;
-                                int degree;
-                                int minutes;
-                                int seconds;
-                                degree = (int)abs(MyGPS.buffer.longitude);
+                TFT.locate(4, 280) ;
+                int degree;
+                int minutes;
+                int seconds;
+                degree = (int)abs(MyGPS.buffer.longitude);
                 minutes = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree) * 60.0);
                 seconds = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
                 TFT.printf("%d %d' %d\" %c lon", degree, minutes,seconds, MyGPS.buffer.lonc);
-                                TFT.locate(4, 300) ;
-                                TFT.locate(4, 300) ;
+                TFT.locate(4, 300) ;
                 degree = (int)abs(MyGPS.buffer.latitude);
                 minutes = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree) * 60.0);
                 seconds = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
                 TFT.printf("%d %d' %d\" %c lat", degree, minutes,seconds, MyGPS.buffer.latc);
-                                TFT.set_font((unsigned char*) SCProSB31x55);     
+                TFT.set_font((unsigned char*) SCProSB31x55);     
                 TFT.locate(120, 200) ;
                 TFT.printf("%.1f", MyGPS.buffer.speed);    
-                                
-                                
-                                
-                                //pc.printf("Dist to Perry %.4f ", nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon));
+                                 
+                //pc.printf("Dist to Perry %.4f ", nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon));
                                 
             }
             else {
-                                TFT.locate(4, 2) ;
-                                TFT.printf("No Data");
+                TFT.locate(4, 2) ;
+                TFT.printf("No Data");
                 //pc.printf("NMEA has no valid data");
             }     
         }