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
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
Diff: main.cpp
- Revision:
- 7:c08305966384
- Parent:
- 6:09a0610af8b7
- Child:
- 8:f1679795e9ac
diff -r 09a0610af8b7 -r c08305966384 main.cpp --- a/main.cpp Sat Mar 11 18:43:08 2017 +0000 +++ b/main.cpp Tue Mar 14 16:00:12 2017 +0000 @@ -6,7 +6,7 @@ #include "MSCFileSystem.h" #define FSNAME "USB" -#define LIM 10 +#define LIM 60 GPS gps(p9, p10); // GPS Connection CMPS03 compass(p28, p27, CMPS03_DEFAULT_I2C_ADDRESS); // Compass connection @@ -34,9 +34,10 @@ FILE *GPS = fopen("/USB/GPS.txt", "w"); // Opens text file for GPS FILE *Comp = fopen("/USB/Compass.txt", "w"); // Opens text file for Compass - float Offset, GenBearing; + float Offset; + int i; - while(1) + while(i < LIM) { //Accelerometer Accel = fopen("/USB/Accelerometer.txt", "a"); @@ -46,6 +47,7 @@ fprintf(Accel,"%f, %f, %f,\r\n",ax,ay,az); lcd.locate(1,21); lcd.printf("Accel: %.2f, %.2f, %.2f", ax, ay, az); + wait (0.5); /* //GPS GPS = fopen("/USB/GPS.txt", "a"); @@ -53,7 +55,7 @@ { fprintf(GPS, "\n%f, %f\r\n", gps.latitude, gps.longitude); lcd.locate(1,1); - lcd.printf("GPS: %.4f, %.4f, %.4f", gps.latitude, gps.longitude); + lcd.printf("%.4f, %.4f, %.4f", gps.latitude, gps.longitude); } else // For no signal { @@ -61,21 +63,29 @@ lcd.locate(1,1); lcd.printf("GPS: No Lock!"); } - + */ // Compass - Offset = compass.readBearing(); // Initial definitions - GenBearing = (compass.readBearing()/10 - Offset/10); - Comp = fopen("/USB/Compass.txt", "a"); - if (GenBearing < 0) - { - GenBearing = 0 - GenBearing; - } - fprintf(Comp, "Bearing: %.2f\r\n", GenBearing); - lcd.locate(1,11); - lcd.printf("Offset: %.2f, CMP: %.2f", Offset/10, GenBearing); -*/ + //Offset = compass.readBearing(); // Initial definitions + // GenBearing = (compass.readBearing()/10 - Offset/10); + Comp = fopen("/USB/Compass.txt", "a"); + fprintf(Comp, "%f\r\n", compass.readBearing()); + lcd.locate(1,11); + lcd.printf("Offset: %f, CMP: %f", Offset, compass.readBearing()); + + + /* GenBearing = compass.readBearing()/10; + Comp = fopen("/USB/Compass.txt", "a"); + if (GenBearing < 0) + { + GenBearing = 0 - GenBearing; + } + fprintf(Comp, "%f\r\n", GenBearing); + lcd.locate(1,11); + lcd.printf("Offset: %.2f, CMP: %.2f", Offset/10.0, GenBearing); + */ fclose(Accel); //fclose(GPS); - //fclose(Comp); + fclose(Comp); + i++; } } \ No newline at end of file