Hey,
I'm working on some code to log GPS data. Still in testing phase, but everything seems to work. Now I'm trying to save the stuff to an SD card, instead of sending it through the serial port.
Code looks like this:
#include <SD.h>
void setup() {
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
void data_parse() {
Serial.readBytes(read_data,400);
count_A = 0;
count_B = 0;
gps_blocks = 1;
while (read_data[count_A] != 0) {
//Serial.println("Not empty");
if ( (read_data[count_A] != ',') and (read_data[count_A] != 0x0A) and (read_data[count_A] != 0x0D) ) {
gps_data[count_B] += read_data[count_A];
//Serial.println("Add Char");
}
else {
count_B++;
gps_blocks++;
//Serial.println("Next Block");
}
count_A++;
}
if (read_data[count_A-1] == ',') {
gps_blocks--;
}
//Serial.println("No More data");
Serial.print("GPS Blocks: ");
Serial.println(gps_blocks);
for (count_A = 0; count_A < gps_blocks; count_A++) {
Serial.print("GPS Data ");
Serial.print(count_A);
Serial.print(": ");
Serial.println(gps_data[count_A]);
}
Serial.println("File open");
File dataFile = SD.open("datalog.txt", FILE_WRITE);
dataFile.print("GPS Blocks: ");
dataFile.println(gps_blocks);
for (count_A = 0; count_A < gps_blocks; count_A++) {
dataFile.print("GPS Data ");
dataFile.print(count_A);
dataFile.print(": ");
dataFile.println(gps_data[count_A]);
}
dataFile.close();
Serial.println("File close");
}
For some reason, when I add the part in between the Serial.print Open and Close file, the code doesn't work anymore and the Arduino 'locks'.
When the code is with the SD part, it outputs let's say 40 'gps blocks' (depending on the NMEA sentences I use). When the SD code is used, it stops at 38 and then hangs.
Any idea why this is happening? I'm using a Seedstudiob shield if that makes a difference.
Thanks!