How can save all the GPS data to a SD card once every minute?

#include <SD.h>
const int chipSelect = 10;
void setup()
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
void loop()
  char index = 0;
  char temp = 0;
  String dataString = "";
File dataFile ="datalog.txt", FILE_WRITE);
     temp =;
     dataString += String(temp);

With the sketch above it can save all the GPS data to a SD card once a second.

But if I just want to save all the data (the GPS recieves in a second) once a minute, how to modify?

I have tried add “delay(60000)” into the sketch, but this would make many data lost, so what could I do?


Hi there,

I have a question for you: What makes you think you are saving GPS data every second? It looks like you are continuously saving GPS data. I don't see the following code in your "loop" function:


This would make sure that things are being recorded every second.

If you want to save the data recorded every second every minute, you could do the follwoing: Create an array of 60 elements, and store the data in that array over the minute, then write out the contents of that array.

Hope this helps,


You would need a few changes.

Firstly, you would need to parse the serial input to detect when you had received a complete record rather than just writing everything you receive to the SD card whenever the buffer was full.

I'd recommend that you change the implementation to use c-strings rather than the String class. Not because Strings are causing you any trouble here, but just because they are a [u]potential[/u] source of stability problems and what you're doing with them could be done just as easily with c-strings instead. It's optional though - if you aren't experiencing any stability problems yet, I don't see any problem leaving it as it is. The moment you run into any weird bugs, though, the first advice you'll get is to stop using Strings.

You would need to use the technique demonstrated in the 'blink without delay' example sketch to record the time you last saved a complete record and discard subsequent records until a minute had elapsed.

Have you investigated the possibility of reconfiguring the GPS to output less frequently? This might be easier to do.