I'm working on a gps logger, and I need to log short bursts of full gps sentences. The sentences in my gps are all of different lengths. I would like to log it as I see it on the com port. Here is some code that I have been working with. The code prints nicely in short bursts and assigns a counter to each burst.
The problem, however, is in logging it. The log only prints a character every few sentences. Does anyone know how I can record full sentences, or groups of sentences without missing characters? Any help is much appreciated!
Code: Select all
#include <NewSoftSerial.h>
#include <SD.h>
#include <stdlib.h>
NewSoftSerial nss(3,4);
int CS=8;
int j=0;
void setup()
{
pinMode(CS, OUTPUT);
Serial.begin(115200);
nss.begin(9600);
Serial.print("Start");
if(!SD.begin(CS))
{
Serial.println("Card Failure");
return;
}
}
void loop()
{
while (j<10000000){j++;
File dataFile =SD.open("LOG.txt", FILE_WRITE);
if (dataFile)
{dataFile.print((char)nss.read());
dataFile.close();
}
else
{
Serial.println("Couldn't open the log file!");
}
for (int i=0;i<4000;i++){
if (nss.available()) {
{
Serial.print((char)nss.read());
}
}
}
delay (7000);
Serial.println();
Serial.println();
Serial.println();
Serial.print("COUNTER:");
Serial.print(j);
Serial.println();
Serial.println();
Serial.println();
}
}