Go Down

Topic: [Resolved] Random Error Codes (Read 2 times) previous topic - next topic

ahref

Nov 01, 2012, 03:04 am Last Edit: Nov 09, 2012, 12:48 am by ahref Reason: 1
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: https://www.sparkfun.com/products/9802
With: http://code.google.com/p/sdfatlib/

Although I also have the standard GPS Sheild kit installed Above the micro SD one.

Code is bellow:
Code: [Select]

#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 :D

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:
Code: [Select]

...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


el_supremo

My guess is that you are running out of SRAM. Which Arduino are you using?

Pete

ahref

Uno V3, is there a way to check free SRAM? I can chuck that out on the serial.


ahref

#4
Nov 01, 2012, 06:06 am Last Edit: Nov 01, 2012, 04:32 pm by ahref Reason: 1
Just occurred to me, i forgot to mention im hitting reset on errors there. Which may of given the "out of memory" idea as i know it recalls setup when out of memory. I'll still check out memory issues but any other ideas?

So ive added a Serial.print of free memory just before the file open call 525 is what its sitting on:
Code: [Select]

...waiting for lock...
525
2012/11/01/15_25_53.csv
error: Cannot Open File
SD errorCode: 0X4


That occurs now or:
Code: [Select]

...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0XF


then sometimes it just works:
Code: [Select]

...waiting for lock...
Invalid Age
525
2012/11/01/15_28_12.csv
201,5x.x,-2.x,2012-11-1 15:28:12,86.10,142.86,0.83



I used:
Code: [Select]

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

Go Up