IMU-pressure-tempreture sensors

Dependencies:   CMSIS_DSP_401 DHT22 MPU9150_DMP QuaternionMath MODSERIAL mbed-src FATFileSystem111 SDFileSystem11 Camera_LS_Y201_CANSAT

Dependents:   combined_F

Revision:
1:339ebc8786ca
Parent:
0:5f608863559a
Child:
3:598af964f16c
Child:
4:dbb8e901826d
--- a/main.cpp	Fri Aug 07 14:26:52 2015 +0000
+++ b/main.cpp	Tue Aug 11 16:56:59 2015 +0000
@@ -2,27 +2,47 @@
 #include "Quaternion.h"
 #include "BMP085.h"
 #include "DHT22.h"
+#include "main.h"
+  char ns, ew, tf, status;
+    int fq, nst, fix, date;                                     // fix quality, Number of satellites being tracked, 3D fix
+    float latitude, longitude, timefix, speed, altitude;
+
+
+
 DHT22 dht22(p23);
 BMP085 bmp085(p28, p27,BMP085_oss8);
-
+Serial xbee(p9,p10);
+DigitalOut rst(p11,PullUp);
 DigitalOut myled(LED1);
 
 Serial debug(USBTX, USBRX);
 MPU9150 imu(p27, p28, p15);
 
 DigitalOut led(LED1);
+void Init()
+{
+    gps.baud(9600);
+  //  pc.baud(115200);
+
+    xbee.printf("Init OK\n");
+    printf("Init OK\n");
+}
 
 char buffer[200];
-
+int e=6;
+int n=0;
 int main(){
     
-        
-debug.baud(115200);
+Init();
+    char c;        
+//debug.baud(115200);
     
     if(imu.isReady()){
-        debug.printf("MPU9150 is ready\r\n");
+        xbee.printf("MPU9150 is ready\r\n");
+        printf("MPU9150 is ready\r\n");
     } else {
-        debug.printf("MPU9150 initialisation failure\r\n");
+        xbee.printf("MPU9150 initialisation failure\r\n");
+        printf("MPU9150 initialisation failure\r\n");
     }
     
     imu.initialiseDMP();
@@ -34,17 +54,25 @@
     imu.setDMPEnabled(true);    
     
     Quaternion q1;
+
     float hum,temp;
+  //  int g=10;
     
     while(true){
-    wait(0.5);   
-        bmp085.update();
-        float altitude=bmp085.calcAltitude(bmp085.get_pressure()*100);
+      n++;  
+      // wait(0.5);   
+     bmp085.update();
+        float allltitude=bmp085.calcAltitude(bmp085.get_pressure()*100);
       //wait(0.2);
+       if(e==6)
+       {
         dht22.sample() ;
          hum=dht22.getHumidity()/10.0;
-          temp=dht22.getTemperature()/10.0;
+      temp=dht22.getTemperature()/10.0;
 
+      e=1;
+      }
+          
 
         if(imu.getFifoCount() >= 48){
             imu.getFifoBuffer(buffer,  48);
@@ -85,16 +113,63 @@
                 (float)((((int32_t)buffer[12] << 24) + ((int32_t)buffer[13] << 16) + ((int32_t)buffer[14] << 8) + buffer[15]))* (1.0 / (1<<30)));
             */
                 
-            q1.decode(buffer);
-            debug.printf("w:%f, v.x:%f, v.y:%f, v.z:%f\r\n", q1.w, q1.v.x, q1.v.y, q1.v.z);
+          q1.decode(buffer);
+         
+//wait(0.5);
 
-debug.printf("p:%f hPa / t:%f / altitude=%f \n\r",bmp085.get_pressure() , bmp085.get_temperature(),altitude);
-      
-      
-       debug.printf("temp: %f  , hum:%f    \n\r\n\n",temp,hum);
-imu.setFifoReset(true);    
-    imu.setDMPEnabled(true);
-    
+    if(gps.readable())
+        { 
+            if(gps.getc() == '$');           // wait a $
+            {
+                for(int i=0; i<sizeof(cDataBuffer); i++)
+                {
+                    c = gps.getc();
+                    if( c == '\r' )
+                    {
+                        //pc.printf("%s\n", cDataBuffer);
+                        parse(cDataBuffer, i);
+                        i = sizeof(cDataBuffer);
+                    }
+                    else
+                    {
+                        cDataBuffer[i] = c;
+                    }                 
+                }
+            }
+         }
+        
+        
+        if(n==10)
+        {
+        xbee.printf("w:%f, v.x:%f, v.y:%f, v.z:%f\r\n", q1.w, q1.v.x, q1.v.y, q1.v.z);
+          
+
+xbee.printf("p:%f hPa / t:%f / altitude=%f \n\r",bmp085.get_pressure() , bmp085.get_temperature(),allltitude);
+
+     xbee.printf("temp: %f  , hum:%f    \n\r",temp,hum);
+       
+       
+       xbee.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude);
+     xbee.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst);
+    xbee.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix);
+   xbee.printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n\n\r\n\n\n", timefix, status, latitude, ns, longitude, ew, speed, date); 
+n=1;
+     
+  }
+            
+      printf("w:%f, v.x:%f, v.y:%f, v.z:%f\r\n", q1.w, q1.v.x, q1.v.y, q1.v.z);
+printf("p:%f hPa / t:%f / altitude=%f \n\r",bmp085.get_pressure() , bmp085.get_temperature(),allltitude);
+     printf("temp: %f  , hum:%f    \n\r",temp,hum);
+        printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude);
+     printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst);
+    printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix);
+   printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n\n\r\n\n\n", timefix, status, latitude, ns, longitude, ew, speed, date); 
+  
+       
+       
+         
+ imu.setFifoReset(true);    
+    imu.setDMPEnabled(true);   
          //TeaPot Demo Packet for MotionFit SDK
             /*
             debug.putc('$'); //packet start
@@ -109,6 +184,51 @@
             */
        }   
     //wait(1);
-//e++;
+e++;
+//g++;
+ //xbee.printf("this is the end");
+    //rst=1;
+    //wait(0.001);
+    //rst=0;
     }
+
 }
+
+
+
+
+void parse(char *cmd, int n)
+{
+    
+  
+    
+    
+    // Global Positioning System Fix Data
+  if(strncmp(cmd,"$GPGGA", 6) == 0) 
+    {
+        sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude);
+        
+    }
+    
+    // Satellite status
+    if(strncmp(cmd,"$GPGSA", 6) == 0) 
+    {
+        sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst);
+       
+    }
+    
+    // Geographic position, Latitude and Longitude
+    if(strncmp(cmd,"$GPGLL", 6) == 0) 
+    {
+        sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix);
+        
+    }
+    
+    // Geographic position, Latitude and Longitude
+    if(strncmp(cmd,"$GPRMC", 6) == 0) 
+    {
+        sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date);
+        
+    }
+       
+     }
\ No newline at end of file