Skip to content

Commit e34566c

Browse files
committed
Add datalogging, fix output format a little, remove a few extra comments
1 parent 0dcdcc8 commit e34566c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

mobile-sense/mobile-sense.ino

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define UPDATE_PERIOD_IN_MILLISECONDS 2000
1111

1212
#define TIMESTAMP_LENGTH 20
13-
#define LOCATION_LENGTH 18
14-
#define TEMPERATURE_LENGTH 21
13+
#define LOCATION_LENGTH 19
14+
#define TEMPERATURE_LENGTH 24
1515

1616
// For hardware serial 1 (recommended):
1717
// GPS TX to Arduino Due Serial1 RX pin 19
@@ -146,11 +146,8 @@ void loop()
146146
// if a sentence is received, we can check the checksum, parse it...
147147
if (GPS.newNMEAreceived()) {
148148
// a tricky thing here is if we print the NMEA sentence, or data
149-
// we end up not listening and catching other sentences!
150-
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
151-
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
152-
153-
if (!GPS.parse(GPS.lastNMEA())) { // this also sets the newNMEAreceived() flag to false
149+
// we end up not listening and catching other sentences!
150+
if (!GPS.parse(GPS.lastNMEA())) { // this also sets the newNMEAreceived() flag to false
154151
return; // we can fail to parse a sentence in which case we should just wait for another
155152
}
156153
}
@@ -174,13 +171,18 @@ void loop()
174171
char temperatures[TEMPERATURE_LENGTH + 1];
175172
char output[100];
176173

174+
File dataFile = SD.open("datalog.txt", FILE_WRITE);
175+
if(!dataFile) {
176+
Serial.print("Couldn't open log file for writing.\r\n");
177+
}
178+
177179
timestamp_len = sprintf(timestamp, "20%02d-%02d-%02dT%02d:%02d:%02dZ", GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds);
178180
if(GPS.fix) {
179-
location_len = sprintf(location, "%4f%c | %4f%c", GPS.latitude, GPS.lat, GPS.longitude, GPS.lon);
181+
location_len = sprintf(location, "%6.2f%c | %6.2f%c", GPS.latitude, GPS.lat, GPS.longitude, GPS.lon);
180182
} else {
181-
location_len = sprintf(location, "Location | unknown");
183+
location_len = sprintf(location, "Location | unknown ");
182184
}
183-
temperature_len = sprintf(temperatures, "%03.2f | %03.2f | %03.2f", readThermocouple(CS0), readThermocouple(CS1), readThermocouple(CS2));
185+
temperature_len = sprintf(temperatures, "%6.2f | %6.2f | %6.2f", readThermocouple(CS0), readThermocouple(CS1), readThermocouple(CS2));
184186

185187
if(timestamp_len == TIMESTAMP_LENGTH && location_len == LOCATION_LENGTH && temperature_len == TEMPERATURE_LENGTH) {
186188
output_len = sprintf(output, "%s | %s | %s\r\n", timestamp, location, temperatures);
@@ -189,5 +191,9 @@ void loop()
189191
}
190192
Serial.print(output);
191193
Serial2.print(output); // send to XBee
194+
if(dataFile) {
195+
dataFile.println(output);
196+
dataFile.close();
197+
}
192198
}
193199
}

0 commit comments

Comments
 (0)