Go Down

Topic: SD card saving problems (Read 442 times) previous topic - next topic


Hey forum,

I'm busy building a gps logger. Im using an UP501 gps and a regular SD card slot.
In the code below everything works perfectly fine and without  a gps connection zeros get saved on the SD card as you would expect. When the gps gets a connection nothing gets saved on the SD card anymore and I have no idea how this comes. Can you please advise?




#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <SD.h>

File GPSFile;

TinyGPS gps;
SoftwareSerial nss(2, 3);
float flat=0;
float flon=0;
int year;
byte month, day, hour, minute, second, hundredths;
byte hourDiff=1;
byte minuteDiff=0;
byte secondDiff=0;

int stap=0;
int time=0;

void setup()
  pinMode(10, OUTPUT);
  if (!SD.begin(10)) {

void loop()


void writeToSD(void)
  GPSFile = SD.open("GPSFile.txt", FILE_WRITE);
  if (GPSFile) {
    ////Serial..print("Writing to GPSFile.txt");
    GPSFile.print(" ");
    GPSFile.print(" ");
    GPSFile.print(" ");
    GPSFile.print(" ");
    // close the file:
  else {
    // if the file didn't open, print an error:
    ////Serial..println("error opening GPSFile.txt");

static void gpsdump(TinyGPS &gps)

  unsigned long age, date, time, chars = 0;
  gps.f_get_position(&flat, &flon, &age);
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);

void startGPS(void)
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 1000)
    if (feedgps())
      newdata = true;


static bool feedgps()
  while (nss.available())
    if (gps.encode(nss.read()))
      return true;
  return false;


You are going about collecting data from the GPS all wrong. You should not have any kind of time limit on collecting data. What you should do is log the data whenever there is a complete sentence. If that is too much, change to record every third complete sentence, or every twelfth sentence (Or whatever value causes recording often enough).
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131