Advise a simple code for the record GPS NMEA


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() {

void loop() {
char buffer;

if (Serial.available()>0)
buffer =;
SDFile ="gps.nmea", FILE_WRITE); 

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).