Program to read data from sensors, write them to a file which can then be interpreted by software to help show the path of a bicycle as it travels around a field

Dependencies:   C12832_lcd FatFileSystemCpp MMA7660 CMPS03 GPS

Fork of MSCUsbHost by Igor Skochinsky

Program to link a compass and a GPS to an MBED to produce a CSV file which can be used to track a bicycle around a field

Results can be found here

Files at this revision

API Documentation at this revision

Comitter:
jrmswell
Date:
Sat Sep 12 14:47:28 2020 +0000
Parent:
21:1990400ca172
Commit message:
Updated to MbedOS5

Changed in this revision

main.cpp.orig Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
diff -r 1990400ca172 -r ffcfb0d9d490 main.cpp.orig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp.orig	Sat Sep 12 14:47:28 2020 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h" // mbed library
+#include "MMA7660.h" // Accelerometer library
+#include "GPS.h" // GPS library
+#include "CMPS03.h" // Compass library
+#include "C12832_lcd.h" // LCD screen library
+#include "MSCFileSystem.h"
+#define FSNAME "USB"
+#define LIM 300
+ 
+GPS gps(p9, p10); // GPS Connection
+CMPS03 compass(p28, p27, CMPS03_DEFAULT_I2C_ADDRESS); // Compass connection
+MMA7660 MMA(p28, p27); // Accelerometer connection
+C12832_LCD lcd;
+Serial pc(USBTX, USBRX);
+ 
+// Declarations
+float ax, ay, az;
+DigitalOut connectionLed(LED1);
+MSCFileSystem msc("USB"); // Mount USB stick under the name "USB"
+ 
+int main()
+{
+    if (MMA.testConnection())
+        connectionLed = 1; // Checking MMA connected correctly
+   
+    FILE *Accel = fopen("/USB/Accelerometer.csv", "w"); // Opens text file for Accelerometer                
+    FILE *GPS = fopen("/USB/GPS.csv", "w"); // Opens text file for GPS                      
+    FILE *Comp = fopen("/USB/Compass.csv", "w"); // Opens text file for Compass   
+    
+    int i;
+    float bearing;
+    
+    while(i < LIM)
+    {
+        //Accelerometer
+        Accel = fopen("/USB/Accelerometer.csv", "a");
+        ax=MMA.x();
+        ay=MMA.y();
+        az=MMA.z();
+        fprintf(Accel,"%f, %f, %f\r\n",ax,ay,az);
+        lcd.locate(1,21);
+        lcd.printf("Accel: %.2f, %.2f, %.2f", ax, ay, az);
+                
+        //GPS
+        GPS = fopen("/USB/GPS.csv", "a");
+        if (gps.sample())
+        {
+            fprintf(GPS, "%f, %f, %.1f\r\n", gps.latitude, gps.longitude, gps.rtime);
+            lcd.locate(1,1);
+            lcd.printf("GPS: %.4f, %.4f, %f", gps.latitude, gps.longitude, gps.rtime);
+        }       
+        else // For no signal
+        {
+            fprintf(GPS, "No Lock!\r\n");
+            lcd.locate(1,1);
+            lcd.printf("GPS: No Lock!");
+        }
+        
+        // Compass
+        Comp = fopen("/USB/Compass.csv", "a");
+        lcd.locate(1,11);
+        bearing = (compass.readBearing()/10) - 165; // (165 = predetermined offset to align with magnetic north)
+        if (bearing < 0)
+        {
+            bearing = 360 + bearing;
+        }
+        fprintf(Comp, "%.2f\r\n", bearing);
+        lcd.printf("Bearing: %.2f\n", bearing);
+        
+        i++;
+        fclose(Accel);
+        fclose(GPS);
+        fclose(Comp);
+    }
+}  
\ No newline at end of file
diff -r 1990400ca172 -r ffcfb0d9d490 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Sep 12 14:47:28 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/armmbed/mbed-os/
diff -r 1990400ca172 -r ffcfb0d9d490 mbed.bld
--- a/mbed.bld	Thu Mar 23 16:24:32 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file