NEOGPS with GPS shield

Hello everyone,

I would like to use NEOGPS library with an uno board and an Elecrow GPS shield (GPS shield - Elecrow) to collect 10Hz GPS data (Longitude, Latitude, nb of satellites, nb of sample, Date, Time, Elapsed time) but I am really new with programming and in particular with Arduino. If I understand, I have to use NeoHWSerial.h with the NMEASDlog example. I would like to record and save in a microSD other data like heart rate, power output, cadence and speed thank to a ANT+ antenna and I don't understand the way to print data into the SD card. I also would like to record all this data at a 10Hz sample rate but I don't understand how to set this parameter in the different configuration folder in the library.

Thanks a lot

First, choose a format for your file. If you get 10 data samples per second and 1 GPS fix every second, what lines should be in the file? Or are you wanting to configure the GPS to output 10 fixes per second?

When you know what fields you want to write, and in what order, take a look at GPSloop. When a new fix is available, it prints to the logfile. This is just like printing to Serial, which you can see in the Serial Monitor Window.

Notice that you can simulate using an SD card. It is very convenient to see the data you are writing to logfile on the Serial Monitor Window. Just make sure this is not commented:

   //----------------------------------------------------------------
    // For testing, it may be more convenient to simply print the
    //   GPS fix fields to the Serial Monitor.  Simply uncomment
    //   this define to skip all SD operations.  An SD card module
    //   does not have to be connected.
    #define SIMULATE_SD

If you make changes to what is written to the file, you should be able to see different output on the Serial Monitor Window.

You should start by learning how to connect and get samples from each sensor, individually. When you have several different sketches, it will be fairly easy to combine them into NMEASDlog. You will read each sample in GPSloop, just after a new fix is available. Then write each sample to the logfile, just like the pieces of the GPS fix.

When you have specific questions, be sure to post (in code tags, like the #define above) or attach the sketch you tried, along with some output.

Cheers,
/dev

Hi -dev, thanks for your reply,

Yes, I would like to save file in CSV format for Excel post-prossessing…

Absolutely, 1 GPS fix per second is enough, 10Hz will be needed only for the other sensors like this (potentiometer steps positions) :

void setup() {
  Serial.begin(9600); 
}

void loop() {
    
  int potValue = analogRead(A0); 

  if (potValue<=100)
  {
    Serial.println(1);
    delay(1);
  }
  else if ((potValue<=200))
  {
    Serial.println(2);
    delay(1);
  }
  else if (potValue<=300)
  {
    Serial.println(3);
    delay(1);
  }
   else if (potValue<=400)
  {
    Serial.println(4);
    delay(1);
  }
   else if (potValue<=500)
  {
    Serial.println(5);
    delay(1);
  }
   else if (potValue<=600)
  {
    Serial.println(6);
    delay(1);
  }
   else if (potValue<=700)
  {
    Serial.println(7);
    delay(1);
  }
   else if (potValue<=800)
  {
    Serial.println(8);
    delay(1);
  }
   else if (potValue<=850)
  {
    Serial.println(9);
    delay(1);
  }
   else if (potValue<=900)
  {
    Serial.println(10);
    delay(1);
  }
   else if (potValue<=950)
  {
    Serial.println(11);
    delay(1);
  }
   else if (potValue<=1023)
  {
    Serial.println(12);
    delay(1);
  } 
  delay(10);
}

Thanks a lot !!

I don’t know how to set 10Hz and 1 GPS fix per second in this sketch (adapted NMEASDlog.ino) with a GPS shield with Neo-6m chip. I took a look at ubloxRate.ino but I don’t know how to implement it in the whole sketch.

Thanks

maxpsx:
in this sketch (adapted NMEASDlog.ino)

What sketch?

Hi -dev, thanks for reply.

It is the same as the original one but with adapted pin :

#include <Arduino.h>
#include <NMEAGPS.h>

#include <GPSport.h>

#include <Streamers.h>

//----------------------------------------------------------------
// Check configuration

#if !defined( GPS_FIX_TIME ) || !defined( GPS_FIX_LOCATION )
  #error You must define TIME and LOCATION in GPSfix_cfg.h
#endif

#if !defined( NMEAGPS_PARSE_RMC )
  #error You must define NMEAGPS_PARSE_RMC in NMEAGPS_cfg.h!
#endif

#ifndef NMEAGPS_INTERRUPT_PROCESSING
  #error You must define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
#endif

static const int LED = 13;

static NMEAGPS  gps; 

//----------------------------------------------------------------
// SD card includes and declarations

#include <SPI.h>
#include <SdFat.h>

SdFat SD;
const int chipSelect = 10;

//----------------------------------------------------------------
// For testing, it may be more convenient to simply print the
//   GPS fix fields to the Serial Monitor.  Simply uncomment
//   this define to skip all SD operations.  An SD card module
//   does not have to be connected.
#define SIMULATE_SD

#ifdef SIMULATE_SD

  auto &logfile = DEBUG_PORT;

#else

  File logfile;

#endif

//----------------------------------------------------------------
//  Utility to print a long integer like it's a float 
//    with 9 significant digits.

void printL( Print & outs, int32_t degE7 )
{
  // Extract and print negative sign
  if (degE7 < 0) {
    degE7 = -degE7;
    outs.print( '-' );
  }

  // Whole degrees
  int32_t deg = degE7 / 10000000L;
  outs.print( deg );
  outs.print( '.' );

  // Get fractional degrees
  degE7 -= deg*10000000L;

  // Print leading zeroes, if needed
  if (degE7 < 10L)
    outs.print( F("000000") );
  else if (degE7 < 100L)
    outs.print( F("00000") );
  else if (degE7 < 1000L)
    outs.print( F("0000") );
  else if (degE7 < 10000L)
    outs.print( F("000") );
  else if (degE7 < 100000L)
    outs.print( F("00") );
  else if (degE7 < 1000000L)
    outs.print( F("0") );
  
  // Print fractional degrees
  outs.print( degE7 );
}

//----------------------------------------------------------------

static void GPSloop()
{
  if (gps.available()) {

    gps_fix fix = gps.read();

    // Log the fix information if we have a location and time
    
    if (fix.valid.location && fix.valid.time) {

      static uint16_t lastLoggingTime  = 0;
             uint16_t startLoggingTime = millis();

      // If you like the CSV format implemented in Streamers.h,
      //   you could replace all these prints with 
      // trace_all( logFile, fix ); // uncomment include Streamers.h

      printL( logfile, fix.latitudeL() );
      logfile.print( ',' );
      printL( logfile, fix.longitudeL() );
      logfile.print(',');

      if (fix.dateTime.hours < 10)
        logfile.print( '0' );
      logfile.print(fix.dateTime.hours);
      logfile.print( ':' );
      if (fix.dateTime.minutes < 10)
        logfile.print( '0' );
      logfile.print(fix.dateTime.minutes);
      logfile.print( ':' );
      if (fix.dateTime.seconds < 10)
        logfile.print( '0' );
      logfile.print(fix.dateTime.seconds);
      logfile.print( '.' );
      if (fix.dateTime_cs < 10)
         logfile.print( '0' ); // leading zero for .05, for example
      logfile.print(fix.dateTime_cs);
      logfile.print(',');

      logfile.print( lastLoggingTime ); // write how long the previous logging took
      logfile.println();
      
   
      static uint16_t lastFlushTime = 0;

      if (startLoggingTime - lastFlushTime > 1000) {
        lastFlushTime = startLoggingTime; // close enough
        logfile.flush();
      }

      #ifdef SIMULATE_SD
        // Simulate the delay of writing to an SD card.  These times are
        //   very long.  This is intended to show (and test) the overrun detection.
        //
        // On a 1Hz GPS, delaying more than 2 seconds here, or more than
        //   2 seconds in two consecutive updates, will cause OVERRUN.
        //
        // Feel free to try different delays to simulate the actual behavior
        //   of your SD card.

        uint16_t t = random(0,5); // 0..4
        t += 3;                   // 3..7
        t = t*t*t*t;              // 81..2401ms
        delay( t ); // cause an OVERRUN
      #endif

      // All logging is finished, figure out how long that took.
      //   This will be written in the *next* record.    
      lastLoggingTime = (uint16_t) millis() - startLoggingTime;
    }
  }

} // GPSloop

//----------------------------------------------------------------

void GPSisr( uint8_t c )
{
  gps.handle( c );

} // GPSisr

//----------------------------------------------------------------
//  This routine waits for GPSisr to provide 
//  a fix that has a valid location.
//
//  The LED is slowly flashed while it's waiting.

static void waitForFix()
{
  DEBUG_PORT.print( F("Waiting for GPS fix...") );

  uint16_t lastToggle = millis();

  for (;;) {
    if (gps.available()) {
      if (gps.read().valid.location)
        break; // Got it!
    }

    // Slowly flash the LED until we get a fix
    if ((uint16_t) millis() - lastToggle > 500) {
      lastToggle += 500;
      digitalWrite( LED, !digitalRead(LED) );
      DEBUG_PORT.write( '.' );
    }
  }
  DEBUG_PORT.println();

  digitalWrite( LED, LOW );

  gps.overrun( false ); // we had to wait a while...

} // waitForFix

//----------------------------------------------------------------

void setup()
{
  DEBUG_PORT.begin(9600);
  while (!DEBUG_PORT)
    ; // wait for serial port to connect. 

  DEBUG_PORT.println( F("NMEASDlog.ino started!") );
  DEBUG_PORT.print( F("fix size = ") );
  DEBUG_PORT.println( sizeof(gps_fix) );
  DEBUG_PORT.print( NMEAGPS_FIX_MAX );
  DEBUG_PORT.println( F(" GPS updates can be buffered.") );
  
  if (gps.merging != NMEAGPS::EXPLICIT_MERGING)
    DEBUG_PORT.println( F("Warning: EXPLICIT_MERGING should be enabled for best results!") );

  gpsPort.attachInterrupt( GPSisr );
  gpsPort.begin( 9600 );

  //  Configure the GPS.  These are commands for MTK GPS devices.  Other
  //    brands will have different commands.
  gps.send_P( &gpsPort, F("PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); // RMC only for MTK GPS devices
  gps.send_P( &gpsPort, F("PMTK220,100") ); // 10Hz update rate for MTK GPS devices

  // Enable the LED for blinking feedback
  pinMode( LED, OUTPUT );

  initSD();

  waitForFix();

} // setup

//----------------------------------------------------------------

void loop()
{
  GPSloop();

  if (gps.overrun()) {
    gps.overrun( false );
    DEBUG_PORT.println( F("DATA OVERRUN: fix data lost!") );
  }
}

//----------------------------------------------------------------

void initSD()
{
  #ifdef SIMULATE_SD

    DEBUG_PORT.println( F("  Simulating SD.") );
    
  #else

    DEBUG_PORT.println( F("Initializing SD card...") );

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
      DEBUG_PORT.println( F("  SD card failed, or not present") );
      // don't do anything more:

      // Flicker the LED
      while (true) {
        digitalWrite(LED,HIGH);
        delay(75);
        digitalWrite(LED,LOW);
        delay(75);
      }
    }

    DEBUG_PORT.println( F("  SD card initialized.") );

    // Pick a numbered filename, 00 to 99.
    char filename[15] = "data_##.csv"; // Changer l'extension du fichier en .txt si cela ne fonctionne pas comme ca

    for (uint8_t i=0; i<100; i++) {
      filename[5] = '0' + i/10;
      filename[6] = '0' + i%10;
      if (!SD.exists(filename)) {
        // Use this one!
        break;
      }
    }

    logfile = SD.open(filename, FILE_WRITE);
    if (!logfile) {
      DEBUG_PORT.print( F("Couldn't create ") ); 
      DEBUG_PORT.println(filename);

      // If the file can't be created for some reason this leaves the LED on
      //   so I know there is a problem
      digitalWrite(LED,HIGH);

      while (true) {}
    }

    DEBUG_PORT.print( F("Writing to ") ); 
    DEBUG_PORT.println(filename);

    // GPS Visualizer requires a header to identify the CSV fields.
    // If you are saving other data or don't need this, simply remove/change it
    logfile.println( F("latitude,longitude,time,loggingTime") ); 

    //trace_header( logfile ); // and uncomment #include Streamers.h
    
  #endif
} // initSD

Yes, I would like to save file in CSV format

What fields? What order?

Show some example data of what you would expect.

Thanks -dev,

Ideally, I would like to have this kind of headers :

Number of sample,Date,Time, Elapsed Time,Longitude,Latitude,Altitude, Position of the Potentiometer

Position of the potentiometer will be computed with the following sketch :

void loop() {
    
  int potValue = analogRead(A0); 

  if (potValue<=100)
  {
    Serial.println(1);
    delay(1);
  }
  else if ((potValue<=200))
  {
    Serial.println(2);
    delay(1);
  }
  else if (potValue<=300)
  {
    Serial.println(3);
    delay(1);
  }
   else if (potValue<=400)
  {
    Serial.println(4);
    delay(1);
  }
   else if (potValue<=500)
  {
    Serial.println(5);
    delay(1);
  }
   else if (potValue<=600)
  {
    Serial.println(6);
    delay(1);
  }
   else if (potValue<=700)
  {
    Serial.println(7);
    delay(1);
  }
   else if (potValue<=800)
  {
    Serial.println(8);
    delay(1);
  }
   else if (potValue<=850)
  {
    Serial.println(9);
    delay(1);
  }
   else if (potValue<=900)
  {
    Serial.println(10);
    delay(1);
  }
   else if (potValue<=950)
  {
    Serial.println(11);
    delay(1);
  }
   else if (potValue<=1023)
  {
    Serial.println(12);
    delay(1);
  }

I did not understand how to set the update rate to 10Hz with 1 GPS fix per second

Thanks

Hi all, do you need more information about the project ?

Thanks

Sorry for the delay, I missed your reply.

I did not understand how to set the update rate to 10Hz

First, I would suggest coding the 10Hz pot samples. You will need to use millis() to take samples at 100ms intervals. This “sticky” post at the top of the Programming Questions subforum is a good place to start:

Using millis() for timing. A Beginner’s Guide.

Also, there are good tutorials on the Useful Links page. See the “Blink without delay” video link and the 2 “How to do several things” posts.

You must eliminate all the delay statements from the pot sampling code before you can merge it with the GPS code. I would suggest putting the sampling code into a separate routine, not all in loop:

void loop()
{
  potLoop();
}

void potLoop()
{
  int potValue = analogRead(A0); 

  if (potValue<=100)
  {
      ...

Then it will be easy to add the GPS code:

void loop()
{
  potLoop();
  GPSloop();
}

When you’ve got your samples working at 10Hz, post what you have, along with questions.

Cheers,
/dev

Don't worries, thanks a lot for your valuable help.

I will do that and come back to you

Thanks

Position of the potentiometer will be computed with the following sketch :

Why does that include a delay in every block?

Wanting to log data 10 times a second, and then littering your code with delay(), are just not compatible things.

Hello all, as a first step thanks a lot for your valuable help

Here is the code for the 10Hz pot samples, hope I am write :slight_smile:

#include <Arduino.h>

unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 100;  // period is set to 100 ms


void setup() {
  Serial.begin(9600);
  startMillis = millis();  //initial start time
}

void loop()
{
  currentMillis = millis();  //get the current time
  potLoop();
}

void potLoop()
{
  int potValue = analogRead(A0); // pin A0 for analog read

  if (currentMillis - startMillis >= period) //test whether the period has elapsed
  {
    
  if (potValue<=100)
  {
    Serial.println(1);
  }
  else if ((potValue<=200))
  {
   Serial.println(2);
  }
  else if (potValue<=300)
  {
   Serial.println(3);
  }
  else if (potValue<=400)
  {
   Serial.println(4);
  }
  else if (potValue<=500)
  {
   Serial.println(5);
  }
  else if (potValue<=600)
  {
   Serial.println(6);
  }
  else if (potValue<=700)
  {
   Serial.println(7);
  }
  else if (potValue<=800)
  {
   Serial.println(8);
  }
  else if (potValue<=850)
  {
   Serial.println(9);
  }
  else if (potValue<=900)
  {
   Serial.println(10);
  }
  else if (potValue<=950)
  {
   Serial.println(11);
  }
  else if (potValue<=1023)
  {
   Serial.println(12);
 }
}
}

@PaulS : it is a mistake, I am a very beginner

Thanks

void potLoop()

Can you point out the part of this function that loops?

PaulS:
Can you point out the part of this function that loops?

That's my fault, Paul. The OP is following the example I suggested, which follows the naming of GPSloop in all the NeoGPS examples.

checkGPS and checkPot might be better names...

hope I am write right :slight_smile:

Pretty close, except I would suggest moving the analogRead inside the timer test:

void checkPot()
{
  if (currentMillis - startMillis >= period) //test whether the period has elapsed
  {

    int potValue = analogRead(A0); // pin A0 for analog read

And be sure to indent properly. You can just press control-T in the IDE editor, and it will auto-format your sketch for you.

With that, you should be able to add the code for GPSloop (or checkGPS, if you prefer) to the sketch and call it from loop.

For now, just print the GPS data in for format you want. Later, you can simply replace the Serial variable with the logfile variable:

static void GPSloop()
{
  if (gps.available()) {

    gps_fix fix = gps.read();

    // Log the fix information if we have a location, date and time
    
    if (fix.valid.location && fix.valid.date && fix.valid.time) {

      //    FORMAT: Number of sample,Date,Time, Elapsed Time,Longitude,Latitude,Altitude, Position of the Potentiometer

      // print the sample number
      Serial.print( sampleNumber++ );
      Serial.print( ',' );

      // print the date

      // print the time
      if (fix.dateTime.hours < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.hours);
      Serial.print( ':' );
      if (fix.dateTime.minutes < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.minutes);
      Serial.print( ':' );
      if (fix.dateTime.seconds < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.seconds);
      Serial.print( '.' );
      if (fix.dateTime_cs < 10)
         Serial.print( '0' ); // leading zero for .05, for example
      Serial.print(fix.dateTime_cs);
      Serial.println();

      // calculate and print the elapsed time

      // print the location
      printL( Serial, fix.latitudeL() );
      Serial.print( ',' );
      printL( Serial, fix.longitudeL() );
      Serial.print(',');

      // print the altitude
      if (fix.valid.altitude) {
        Serial.print( fix.altitude() );
      }
      Serial.print( ',' );

      // print the potentiometer value
      //  Serial.print( potValue );  don't do this yet...

When you’ve got the basic format correct, you can print the pot value(s). However…

If you are getting 10 pot values for every GPS “value”, what does the format look like? Are you writing 10 records with the same GPS info? Are you writing one record with 10 pot samples at the end?

When you know what you want, you can try something and ask questions.

Cheers,
/dev

Thanks a lot for your great help !!

This is the modified code from the NMEASDlog.ino sketch :

#include <Arduino.h>
#include <NMEAGPS.h>

#include <GPSport.h>

//#include <Streamers.h>

//----------------------------------------------------------------
// Check configuration

#if !defined( GPS_FIX_TIME ) || !defined( GPS_FIX_LOCATION )
  #error You must define TIME and LOCATION in GPSfix_cfg.h
#endif

#if !defined( NMEAGPS_PARSE_RMC )
  #error You must define NMEAGPS_PARSE_RMC in NMEAGPS_cfg.h!
#endif

#ifndef NMEAGPS_INTERRUPT_PROCESSING
  #error You must define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
#endif

static const int LED = 13;

static NMEAGPS  gps; 

//----------------------------------------------------------------
// SD card includes and declarations

#include <SPI.h>
#include <SdFat.h>

SdFat SD;
const int chipSelect = 8;

#define SIMULATE_SD

#ifdef SIMULATE_SD

  auto &logfile = DEBUG_PORT;

#else

  File logfile;

#endif

//----------------------------------------------------------------
//  Utility to print a long integer like it's a float 
//    with 9 significant digits.

void printL( Print & outs, int32_t degE7 )
{
  // Extract and print negative sign
  if (degE7 < 0) {
    degE7 = -degE7;
    outs.print( '-' );
  }

  // Whole degrees
  int32_t deg = degE7 / 10000000L;
  outs.print( deg );
  outs.print( '.' );

  // Get fractional degrees
  degE7 -= deg*10000000L;

  // Print leading zeroes, if needed
  if (degE7 < 10L)
    outs.print( F("000000") );
  else if (degE7 < 100L)
    outs.print( F("00000") );
  else if (degE7 < 1000L)
    outs.print( F("0000") );
  else if (degE7 < 10000L)
    outs.print( F("000") );
  else if (degE7 < 100000L)
    outs.print( F("00") );
  else if (degE7 < 1000000L)
    outs.print( F("0") );
  
  // Print fractional degrees
  outs.print( degE7 );
}


static void GPSloop()
{
  if (gps.available()) {

    gps_fix fix = gps.read();

    
    if (fix.valid.location && fix.valid.date && fix.valid.time) {

      static uint16_t lastLoggingTime  = 0;
             uint16_t startLoggingTime = millis();

    
      uint16_t sampleNumber = 0;
      Serial.print( sampleNumber++ );
      Serial.print( ',' );

      // print the date

      // print the time
      if (fix.dateTime.hours < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.hours);
      Serial.print( ':' );
      if (fix.dateTime.minutes < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.minutes);
      Serial.print( ':' );
      if (fix.dateTime.seconds < 10)
        Serial.print( '0' );
      Serial.print(fix.dateTime.seconds);
      Serial.print( '.' );
      if (fix.dateTime_cs < 10)
         Serial.print( '0' ); // leading zero for .05, for example
      Serial.print(fix.dateTime_cs);
      Serial.println();

      // calculate and print the elapsed time

      // print the location
      printL( Serial, fix.latitudeL() );
      Serial.print( ',' );
      printL( Serial, fix.longitudeL() );
      Serial.print(',');

      // print the altitude
      if (fix.valid.altitude) {
        Serial.print( fix.altitude() );
      }
      Serial.print( ',' );

    
      static uint16_t lastFlushTime = 0;

      if (startLoggingTime - lastFlushTime > 1000) {
        lastFlushTime = startLoggingTime; // close enough
        logfile.flush();
      }

      #ifdef SIMULATE_SD
        // Simulate the delay of writing to an SD card.  These times are
        //   very long.  This is intended to show (and test) the overrun detection.
        //
        // On a 1Hz GPS, delaying more than 2 seconds here, or more than
        //   2 seconds in two consecutive updates, will cause OVERRUN.
        //
        // Feel free to try different delays to simulate the actual behavior
        //   of your SD card.

        uint16_t t = random(0,5); // 0..4
        t += 3;                   // 3..7
        t = t*t*t*t;              // 81..2401ms
        delay( t ); // cause an OVERRUN
      #endif

      // All logging is finished, figure out how long that took.
      //   This will be written in the *next* record.    
      lastLoggingTime = (uint16_t) millis() - startLoggingTime;
    }
  }

} // GPSloop

//----------------------------------------------------------------

void GPSisr( uint8_t c )
{
  gps.handle( c );

} // GPSisr



static void waitForFix()
{
  DEBUG_PORT.print( F("Waiting for GPS fix...") );

  uint16_t lastToggle = millis();

  for (;;) {
    if (gps.available()) {
      if (gps.read().valid.location)
        break; // Got it!
    }

    // Slowly flash the LED until we get a fix
    if ((uint16_t) millis() - lastToggle > 500) {
      lastToggle += 500;
      digitalWrite( LED, !digitalRead(LED) );
      DEBUG_PORT.write( '.' );
    }
  }
  DEBUG_PORT.println();

  digitalWrite( LED, LOW );

  gps.overrun( false ); // we had to wait a while...

} // waitForFix

//----------------------------------------------------------------

void setup()
{
  DEBUG_PORT.begin(9600);
  while (!DEBUG_PORT)
    ; // wait for serial port to connect. 

  DEBUG_PORT.println( F("NMEASDlog.ino started!") );
  DEBUG_PORT.print( F("fix size = ") );
  DEBUG_PORT.println( sizeof(gps_fix) );
  DEBUG_PORT.print( NMEAGPS_FIX_MAX );
  DEBUG_PORT.println( F(" GPS updates can be buffered.") );
  
  if (gps.merging != NMEAGPS::EXPLICIT_MERGING)
    DEBUG_PORT.println( F("Warning: EXPLICIT_MERGING should be enabled for best results!") );

  gpsPort.attachInterrupt( GPSisr );
  gpsPort.begin( 9600 );

  //  Configure the GPS.  These are commands for MTK GPS devices.  Other
  //    brands will have different commands.
  gps.send_P( &gpsPort, F("PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); // RMC only for MTK GPS devices
  gps.send_P( &gpsPort, F("PMTK220,100") ); // 10Hz update rate for MTK GPS devices

  // Enable the LED for blinking feedback
  pinMode( LED, OUTPUT );

  initSD();

  waitForFix();

} // setup

//----------------------------------------------------------------

void loop()
{
  GPSloop();

  if (gps.overrun()) {
    gps.overrun( false );
    DEBUG_PORT.println( F("DATA OVERRUN: fix data lost!") );
  }
}

//----------------------------------------------------------------

void initSD()
{
  #ifdef SIMULATE_SD

    DEBUG_PORT.println( F("  Simulating SD.") );
    
  #else

    DEBUG_PORT.println( F("Initializing SD card...") );

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
      DEBUG_PORT.println( F("  SD card failed, or not present") );
      // don't do anything more:

      // Flicker the LED
      while (true) {
        digitalWrite(LED,HIGH);
        delay(75);
        digitalWrite(LED,LOW);
        delay(75);
      }
    }

    DEBUG_PORT.println( F("  SD card initialized.") );

    // Pick a numbered filename, 00 to 99.
    char filename[15] = "data_##.txt";

    for (uint8_t i=0; i<100; i++) {
      filename[5] = '0' + i/10;
      filename[6] = '0' + i%10;
      if (!SD.exists(filename)) {
        // Use this one!
        break;
      }
    }

    logfile = SD.open(filename, FILE_WRITE);
    if (!logfile) {
      DEBUG_PORT.print( F("Couldn't create ") ); 
      DEBUG_PORT.println(filename);

      // If the file can't be created for some reason this leaves the LED on
      //   so I know there is a problem
      digitalWrite(LED,HIGH);

      while (true) {}
    }

    DEBUG_PORT.print( F("Writing to ") ); 
    DEBUG_PORT.println(filename);

   
    logfile.println( F("latitude,longitude,time,loggingTime") ); 

    //trace_header( logfile ); // and uncomment #include Streamers.h
    
  #endif
} // initSD

Here the Serial Monitor response :

NMEASDlog.ino started!
fix size = 31
1 GPS updates can be buffered.
  Simulating SD.
Waiting for GPS fix.....
0,11:49:00.00
47.0855667,6.3120157,723.50,0,11:49:01.00
47.0855650,6.3120150,723.40,DATA OVERRUN: fix data lost!
0,11:49:03.00
47.0855700,6.3120183,723.10,DATA OVERRUN: fix data lost!
0,11:49:05.00
47.0855640,6.3120160,723.10,0,11:49:06.00
47.0855650,6.3120165,723.20,0,11:49:07.00
47.0855595,6.3120128,723.40,0,11:49:08.00
47.0855507,6.3120077,723.90,DATA OVERRUN: fix data lost!
0,11:49:10.00
47.0855530,6.3120098,724.40,DATA OVERRUN: fix data lost!
0,11:49:12.00
47.0855543,6.3120112,724.80,0,11:49:13.00
47.0855512,6.3120108,724.80,DATA OVERRUN: fix data lost!
0,11:49:16.00
47.0855577,6.3120158,725.10,0,11:49:17.00
47.0855590,6.3120163,725.30,0,11:49:18.00
47.0855638,6.3120188,725.40,0,11:49:19.00
47.0855747,6.3120232,725.40,0,11:49:20.00
47.0855723,6.3120218,725.40,0,11:49:21.00
47.0855692,6.3120193,725.50,0,11:49:22.00
47.0855732,6.3120198,725.50,0,11:49:23.00
47.0855797,6.3120220,725.40,DATA OVERRUN: fix data lost!
0,11:49:25.00
47.0855845,6.3120228,725.10,0,11:49:26.00
47.0855795,6.3120210,725.00,0,11:49:27.00
47.0855833,6.3120240,724.90,0,11:49:28.00
47.0855745,6.3120210,724.80,DATA OVERRUN: fix data lost!
0,11:49:31.00
47.0855685,6.3120203,724.60,DATA OVERRUN: fix data lost!
0,11:49:33.00
47.0855725,6.3120243,724.30,0,11:49:34.00
47.0855710,6.3120237,724.30,0,11:49:35.00
47.0855740,6.3120248,724.20,0,11:49:36.00
47.0855755,6.3120260,724.20,DATA OVERRUN: fix data lost!
0,11:49:39.00
47.0855948,6.3120360,723.90,0,11:49:40.00
47.0855965,6.3120373,723.80,0,11:49:41.00
47.0856122,6.3120438,723.40,0,11:49:42.00
47.0856205,6.3120465,722.90,0,11:49:43.00
47.0856213,6.3120473,722.60,0,11:49:44.00
47.0856315,6.3120512,722.40,0,11:49:45.00
47.0856323,6.3120518,722.10,0,11:49:46.00
47.0856342,6.3120525,721.90,0,11:49:47.00
47.0856330,6.3120528,721.70,0,11:49:48.00
47.0856297,6.3120532,721.60,DATA OVERRUN: fix data lost!
0,11:49:51.00
47.0856303,6.3120568,721.30,DATA OVERRUN: fix data lost!
0,11:49:53.00
47.0856343,6.3120593,720.80,DATA OVERRUN: fix data lost!
0,11:49:56.00
47.0856440,6.3120633,720.10,0,11:49:57.00
47.0856498,6.3120655,719.90,0,11:49:58.00
47.0856460,6.3120643,719.80,0,11:49:59.00
47.0856438,6.3120647,719.50,0,11:50:00.00
47.0856437,6.3120657,719.30,0,11:50:01.00
47.0856463,6.3120672,718.80,0,11:50:02.00
47.0856520,6.3120698,718.50,0,11:50:03.00
47.0856523,6.3120700,718.00,0,11:50:04.00
47.0856532,6.3120700,717.70,0,11:50:05.00
47.0856472,6.3120678,717.40,DATA OVERRUN: fix data lost!
0,11:50:07.00
47.0856473,6.3120723,716.80,0,11:50:08.00
47.0856382,6.3120713,716.50,0,11:50:09.00
47.0856340,6.3120713,716.20,0,11:50:10.00
47.0856367,6.3120732,715.80,DATA OVERRUN: fix data lost!
0,11:50:12.00
47.0856323,6.3120730,715.20,DATA OVERRUN: fix data lost!
0,11:50:14.00
47.0856217,6.3120705,714.70,DATA OVERRUN: fix data lost!
0,11:50:16.00
47.0856085,6.3120672,714.70,0,11:50:17.00
47.0856075,6.3120678,714.80,DATA OVERRUN: fix data lost!
0,11:50:19.00
47.0856012,6.3120668,714.60,0,11:50:20.00
47.0855975,6.3120657,714.30,0,11:50:21.00
47.0855912,6.3120633,713.70,0,11:50:22.00
47.0855913,6.3120637,713.30,0,11:50:23.00
47.0855917,6.3120640,713.00,0,11:50:24.00
47.0855900,6.3120653,712.60,DATA OVERRUN: fix data lost!
0,11:50:26.00

I don't know why the format is not respected..

Thanks

I don't know why the format is not respected..

Because I didn't write your program for you. For example, I just put a comment for printing the date:

     // print the date

      // print the time

But there's no code to write the pieces of the date. You'll have to write it.

Ok sorry, I will try to do that

Thanks