Show Posts
Pages: 1 2 3 [4]
46  Using Arduino / Storage / Re: Random Error Codes on: November 01, 2012, 12:06:35 am
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:
...waiting for lock...
525
2012/11/01/15_25_53.csv
error: Cannot Open File
SD errorCode: 0X4

That occurs now or:
Code:
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0XF

then sometimes it just works:
Code:
...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:
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
47  Using Arduino / Storage / Re: Random Error Codes on: October 31, 2012, 09:34:10 pm
Uno V3, is there a way to check free SRAM? I can chuck that out on the serial.
48  Using Arduino / Storage / [Resolved] Random Error Codes on: October 31, 2012, 09:04:51 pm
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:
#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 smiley-grin

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 smiley-grin!

P.S. Some sample Serial Monitor output here:
Code:
...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
49  Using Arduino / Storage / Re: Keeping a File Open? on: October 30, 2012, 04:32:19 pm
The SD::begin method should be called ONCE, not every pass through loop.

I was aware of this, my entire post details that i tried that.

Many thanks to the both of you!
50  Using Arduino / Storage / Keeping a File Open? on: October 14, 2012, 09:00:46 pm
Hello all,

Using a: https://www.sparkfun.com/products/9802
With: http://code.google.com/p/sdfatlib/

on an Uno Rev3.

I'm doing some data logging out to a file on the sd card fine but part of it is making me twitchy.
Code:
void loop()
{
  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
  ofstream sdout("test.csv", ios::out | ios::app);
  //Do logging to sdout here
  //eg sdout << "test" << flush
  sdout.close();
}

Is there anyway to keep the file handle open between loops? This works fine I'm just concerned that this sort of behaviour seems inefficient/detrimental to the sd card.

I've tried declaring some of the stuff in setup()/ the main file body but this does not work, the examples with the library seem to agree that this is the only way to write to a file within loop()

Thanks smiley

Pages: 1 2 3 [4]