A simple Ublox NEO-6M GPS Data Logger Example

The Ublox NEO-6M is an inexpensive GPS receiver available from multiple sources. It provides these NMEA
messages once a second:
GGA; Time, position and fix type data.

GSA; GPS receiver operating mode, satellites used in the position
solution, and DOP values

GSV; The number of GPS satellites in view satellite ID numbers,
elevation, azimuth, and SNR values.

RMC Time, date, position, course and speed data.

It uses a serial interface to transfer the messages with these parameters; 9600 baud, 8 bits, 1 stop, no parity.

This example stores the RMC message data on a SD card. Here is the example code:

/*
  Free for all uses except commercial
  This software is covered by a beerware license.  There is no warranty that this even works
  If does for you then great.  Nor is the author liable for any claim, damages
  or other liability, whether in an action of contract, tort, or otherwise,
  arising from, out of in connection with this software or the use or dealings in 
  this software.   I can not control your use of this software therefore I can not be
  liable for your problems.  The proceeding words should keep the lawyers happy.  
  If you use it for your purposes with success and we meet,then please 
  buy me a beer.  G. Majewski
 */

/*
 * 21 August 2015 version, 
 * 25 Augustversion with new way for file name and stop/start button
 * 26 August version eliminate the use of reset to start a new file after stop
 * This is for use with UBLOX NEO-6M GPS Receiver to see its RMC messages
 * with Arduino (Nano, Pro Mini, Pro Micro, Uno) processors
 * 
 * It is time/position/motion data logger to a micro SD card
 * The circuit for the SD card attached to SPI bus as follows:
 * MOSI - pin 11
 * MISO - pin 12
 * CLK - pin 13
 * CS - pin 10, normal SPI CS pin
 * 
 * start/stop button uses pin 5
 * start/stop led uses pin 8, two 220 ohm resistors with
 * red and green Led devices in anti-parallel configuration
 */
 
#include <SoftwareSerial.h>
const int RxPin = 4, TxPin = 3;
SoftwareSerial GPSerial(RxPin, TxPin); // Rx, Tx for Arduino Side
 /*
  * Arduino Rx pin 4 to GPS device TX needs to be at 3.3 volt I/O level
  * Ardunio TX pin 3 to GPS device RX needs to be at 3.3 volt I/O level
  */

#include <SPI.h>
#include <SD.h>
File myFile;

char temp[68];
char fileName[] ="        .cvs";

void setup() {
  // put your setup code here, to run once:
  pinMode(5, INPUT_PULLUP);  //test button for start and stop
  pinMode(8, OUTPUT); //led to show operation
  
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. This prevents program from running until serial available
  }
  GPSerial.begin(9600); // GPS device is at 9600
}

void loop() {
    // put your main code here, to run repeatedly:
  boolean dataCollect = false;
  boolean startStop = false; //false is stop
  boolean dataIsOk = false;

  Serial.println(F("Press Start/Stop Button"));

  while (!startStop)
   {
    startStop = CheckStart();
   }
  
  while(startStop)
  {
   while (!dataIsOk)
    {
    dataIsOk =  GPSerial.find(",A*"); 
    Serial.println(F("Waiting for good fix"));
    }

if (dataIsOk)
   {Serial.println(F("Satellite Fix available")); }
   if(GPSerial.find("RMC,"))
    {
    int charCount = GPSerial.readBytesUntil('\r', temp, 68);
    //now to creat file name date-time.csv
    fileName[0] = temp[(charCount -13)];  //day #
    fileName[1] = temp[(charCount -12)];
    for (int i = 0; i < 6; i++)
     {
      fileName[(i + 2)] = temp[i];
     }
    }

   //SD stuff for startup
  Serial.print("Initializing SD card...");
  if (!SD.begin(10))
  {
    Serial.println("initialization failed!");
  }
  else { Serial.println("initialization done."); }
   myFile = SD.open(fileName, FILE_WRITE);
   
   if (myFile) {
   Serial.println(F("File Opened, starting data collection"));
   dataCollect = true;
  } else {
    // if the file didn't open, print an error:
    Serial.println(F("error opening file"));
    digitalWrite(8, LOW);
    delay(30000);
   }     
  if (dataCollect)
  {
   while(startStop)
    {
      startStop = CheckStop();
    if (GPSerial.available() && GPSerial.find("RMC,"))
     {
      String Temp = GPSerial.readStringUntil('\r'); 
      myFile.println(Temp.substring(0, (Temp.length() -7)));
     }
     delay(950); //needed to slow to get data once a second
    }
    dataCollect = false;
  }
  myFile.close();
  Serial.println(F("File closed, done."));
 }
}

boolean CheckStart()
 {
  int test1 = HIGH;
  int test2 = LOW;
  test1 = digitalRead(5);
  delay(10); //for debounce
  test2 = digitalRead(5);
  if ((test1 == test2) && (test1 == LOW)) //set for start
   {
    digitalWrite(8, HIGH);
    Serial.println(F("Starting Collecting, Press Start/Stop to end"));
    return true;
   }
   else { return false; };
 }

 boolean CheckStop()
 {
  int test1 = HIGH;
  int test2 = LOW;
  test1 = digitalRead(5);
  delay(10); //for debounce
  test2 = digitalRead(5);
  if ((test1 == test2) && (test1 == LOW)) //set for start
   {
    digitalWrite(8, LOW);
    Serial.println(F("Stopping Data Collecting, Push Stop/Start for new file"));
    return false;
   }
   else { return true; };
 }

I hope this is a help to others.

Enjoy Life JustGreg
Live Well, Laugh Often, Love Much