Advise a simple code for the record GPS NMEA

Hello!

For data recording with GPS on a flash card I tried to use various libraries, but they too heavy also eat a lot of memory.

Prompt, how it is possible most simply and reliably, for write data with GPS receiver on a SD card.

I tried to read the data byte by byte from UART port and write them to SD, but my version of code skips characters :frowning:

...and what does your version of code look like (post in code tags please!)?

Here is my code:

#include <SD.h>

File SDFile;

void setup() {
Serial.begin(9600);
SD.begin(6);
delay(1000);
}

void loop() {
char buffer;

if (Serial.available()>0)
{
buffer = Serial.read();
SDFile = SD.open("gps.nmea", FILE_WRITE); 
SDFile.write(buffer);
SDFile.close();
}}

Your program is extremely inefficient, because it opens the file, writes a single character, and closes the file.

Open the file once, in setup().

Read an entire line from the GPS unit before writing it to the file.

Close the file when you are done logging.

I don't completely agree with jremington. What I would do is see if there is serial data to read. If so, open the file, read and write all available serial data, and close the file.

This way, the file is open only as long as needed, so the risk of data loss is minimal. But, it is open long enough to read and write a lot of characters (to the file buffer), minimizing the risk of the serial buffer overflowing (which is why you lose characters).