I’m using an Arduino Pro 3.3v 168 with the Micro SD Card shield from SFE. And a Venus 6 GPS unit hooked up on the Serial UART (pin 0). I’m writing log messages using a NewSoftSerial on pins 2/3, which is wired up to an FTDI. I’m using FileLogger V0.6, and a freshly formated micro SD card, with the text file “gpslog.txt” with a few bytes written to it.
So here is the problem. If I run the code below, absolutely nothing happens. I never get the “Start of Program” message or anything. If I comment out the FileLogger::append line, everything works as expected. (except obviously it doesn’t write to the card). It buffers the text from the GPS unit and prints out all of the log messages.
Now if I load the demo example program that came with FileLogger, it works great. But I can’t get anything else to work with it. Also I’ve tried several other Fat libraries without luck either.
Here is the code from my program. Please excuse all the delay and print statements.
#include "FileLogger.h"
#include "NewSoftSerial.h"
int rxPin = 2;
int txPin = 3;
NewSoftSerial logger(rxPin, txPin);
void setup(void)
{
delay(500);
logger.begin(9600);
delay(500);
logger.println("Start of program.\n");
delay(500);
Serial.begin(9600);
delay(500);
}
#define BUFFSIZE 200
unsigned long idx;
byte buffer[BUFFSIZE];
void loop(void)
{
delay(50);
logger.print(".\n");
if(Serial.available() > 0)
{
int readSize = Serial.available();
logger.print("Bytes available: ");
logger.println(readSize, DEC);
char inByte;
while(readSize > 0)
{
readSize--;
inByte = Serial.read();
buffer[idx++] = inByte;
if(idx >= (BUFFSIZE-2))
{
buffer[idx] = 0;
delay(50);
int result = FileLogger::append("gpslog.txt", buffer, idx);
//int result = 0;
delay(50);
logger.print("Result: ");
if( result == 0) {
logger.print("Ok, Wrote ");
logger.print(idx, DEC);
logger.println(" bytes");
} else if( result == 1) {
logger.println("Fail initializing");
} else if( result == 2) {
logger.println("Fail appending");
}
idx = 0;
}
}
}
}