Code to take GPS, Accelerometer and Compass readings and print to USB for data analysis.

Dependencies:   CMPS03 FatFileSystemCpp GPS MMA7660 mbed C12832_lcd

Files at this revision

API Documentation at this revision

Comitter:
Alex4475
Date:
Wed May 07 10:22:15 2014 +0000
Parent:
2:64ff9d8b2aa1
Child:
4:db6f9f91a04b
Commit message:
Now prints to LCD for error checking.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed May 07 10:07:45 2014 +0000
+++ b/main.cpp	Wed May 07 10:22:15 2014 +0000
@@ -59,22 +59,29 @@
     pc.printf("Starting CMPS03 test...\n");
     float refPoint = 1.0; 
     float bearing;
-    int i = 0;
+    int i = 1;
     
     while (1)
     {
         refPoint = compass.readBearing();
         pc.printf("The reference bearing: %f\n\n", refPoint/10);
-        while(i < 20)
+        while(i == 1)
         {
+            FILE *CompassFile = fopen("/" FSNAME "/compass_file.txt", "a");
+            FILE *GPSFile = fopen("/" FSNAME "/gps_file.txt", "a");
+            FILE *AccelFile = fopen("/" FSNAME "/accel_file.txt", "a");
         // GPS code
             if(gps.sample()) 
             {
                 fprintf(GPSFile, "\n%f %f\r\n", gps.latitude, gps.longitude);
+                lcd.locate(1,1);
+                lcd.printf("GPS: %.4f %.4f", gps.latitude, gps.longitude);
             } 
             else 
             {
-                pc.printf("\nOh Dear! No lock :(\n") && fprintf(GPSFile, "\n0.000 0.000\r\n");
+                fprintf(GPSFIle, "\nNo lock!\r\n");
+                lcd.locate(1,1);
+                lcd.printf("GPS: No lock!");
             }
             
         // Accelerometer code
@@ -83,6 +90,8 @@
             ay=MMA.y(); 
             az=MMA.z(); 
             fprintf(AccelFile, "%f %f %f\r\n",ax,ay,az); 
+            lcd.locate(1,11);
+            lcd.printf("MMA: %.4f %.4f %.4f",ax,ay,az);
             
         // Compass code
             bearing = (compass.readBearing()/10 - refPoint/10);
@@ -90,36 +99,18 @@
             {
                 bearing = 360 + bearing;
                 fprintf(CompassFile, "Bearing : %f\r\n", bearing);
+                lcd.locate(1,21);
+                lcd.printf("CMP: %.2f",bearing);
             }
             else
             {
-                fprintf(CompassFile, "Bearing : %f\r\n" << endl, bearing);
+                fprintf(CompassFile, "Bearing : %f\r\n", bearing);
+                lcd.locate(1,21);
+                lcd.printf("CMP: %.2f",bearing);
             }
-            i = i + 1;
-        }
-        fclose(CompassFile);
-        fclose(AccelFile);
-        fclose(GPSFile);        
-    }
-    
-        
-   /* fclose(compassFile); 
-    printf("\n - OK\n");
-
-    printf("\nTesting file read:\n");
-    compassFile = fopen( "/" FSNAME "/compassfile.txt", "r");
-    if ( compassFile == NULL )
-    {
-        error("Could not open compass file for read\n");
-    }
-    char buf[256];
-    if ( NULL == fgets(buf, sizeof(buf), compassFile) )
-    {
-        error("Error reading from file\n");
-    }
-    fclose(compassFile); 
-    printf("\n - OK, read string: '%s'\n\n", buf);
-   */ 
-    
-    
+            fclose(CompassFile);
+            fclose(AccelFile);
+            fclose(GPSFile);  
+        }        
+    } 
 }
\ No newline at end of file