arduino and serial logging

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
btricha2
 
Posts: 1
Joined: Tue Oct 23, 2012 1:10 pm

arduino and serial logging

Post by btricha2 »

Hi everyone.

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();
  
 }
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: arduino and serial logging

Post by adafruit_support_bill »

You only print one character after you open the data file. In your loop lower down, you only echo to the serial.

Code: Select all

for (int i=0;i<4000;i++){
  if (nss.available()) {
     
      {
      
        Serial.print((char)nss.read());
        
       

      }
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”