Hi there,
I've got a basic GPS data logger going and im randomly getting random SDCard Error codes. I was unable to find documentation on what each of these mean but so far ive had:
01
02
03
04
06
08
F
All of these seem to point to me that my hardware is at fault perhaps a dodgy pin or sd card holder But I do not know.
Using a: SparkFun microSD Shield - DEV-12761 - SparkFun Electronics
With: Google Code Archive - Long-term storage for Google Code Project Hosting.
Although I also have the standard GPS Sheild kit installed Above the micro SD one.
Code is bellow:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SdFat.h>
#include <PString.h>
#define RXPIN 2
#define TXPIN 3
//Defined in the specs for the module we are using
#define GPSBAUD 4800
#define error(s) sd.errorHalt_P(PSTR(s))
const uint8_t chipSelect = SS;
TinyGPS gps;
//Create the variables to be used by SdFat Library
SdFat sd;
SoftwareSerial uart_gps(RXPIN, TXPIN);
char buff[50];
char pbuff[100];
PString line(pbuff,sizeof pbuff);
void getgps(TinyGPS &gps);
ofstream sdout;
void setup()
{
Serial.begin(115200);
uart_gps.begin(GPSBAUD);
Serial.println("...waiting for lock...");
if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
}
void loop()
{
while(uart_gps.available()) { // While there is data on RX
int c = uart_gps.read();
if(gps.encode(c)) {
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths,&age); //Get the date from the GPS
unsigned long date;
gps.get_datetime(&date,0,0);
if(date == TinyGPS::GPS_INVALID_DATE){
Serial.println("Invalid Date");
continue;
}
if(age == TinyGPS::GPS_INVALID_AGE) {
Serial.println("Waiting for more valid data");
continue;
}
//Should only occur once per day
if(!sdout.is_open()) {
sprintf(buff, "%02d/%02d/%02d/",year,month,day);
if(!sd.exists(buff)){
sd.mkdir(buff);
}
*buff = '\0';
sprintf(buff, "%02d/%02d/%02d/%02d_%02d_%02d.csv",year,month,day,hour, minute, second);
sdout.open(buff,ios::out | ios::app);
Serial.println(buff);
if(!sdout) error("Cannot Open File");
}
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
line.begin();
line.print("201,");
line.print(latitude,8);
line.print(",");
line.print(longitude,8);
line.print(",");
line.print(year);
line.print("-");
line.print(month);
line.print("-");
line.print(day);
line.print(" ");
line.print(hour);
line.print(":");
line.print(minute);
line.print(":");
line.print(second);
line.print(",");
line.print(gps.f_altitude(),2);
line.print(",");
line.print(gps.f_course(),2);
line.print(",");
line.print(gps.f_speed_kmph(),2);
sdout << line << '\n' << flush;
Serial.println(line);
// Here you can print statistics on the sentences.
//unsigned long chars;
//unsigned short sentences, failed_checksum;
//gps.stats(&chars, &sentences, &failed_checksum);
//Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
//Serial.println(); Serial.println();
}
}
}
Feel free to poke holes in it, Jumped in at the deep end here
I have no idea what is going on and my back is starting to ache from transferring the microsd card from the shield into the adapter on the front of my pc.
Please help :D!
P.S. Some sample Serial Monitor output here:
...waiting for lock...
Invalid Age
2012/11/01/01_55_59.csv
201,5x.x,-2.x,2012-11-1 1:55:59,100.00,0.00,0.00
(continues for about 10 lines)
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X2
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X2
...waiting for lock...
Invalid Age
Invalid Age
2012/11/01/01_56_31.csv
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
Invalid Age
Invalid Age
2012/11/01/01_56_50.csv
error: Cannot Open File
SD errorCode: 0XF