Ultimate GPS parsing formatting

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Ultimate GPS parsing formatting

Post by night3dynamo »

I've dug around the forums, but haven't been able to find an exact answer.

My Ultimate GPS works fine, but I'm trying to clean up the output in the parsing example sketch to achieve a tab delimited file. Is it possible to suppress the NMEA sentences (such as $PGTOP,$GPGGA, $GPRMC, $GPGGA)? If not, can I insert a tab between each NMEA sentence group rather than a new line to keep everything on the same line?

Really appreciate the help.

Edit: My code is the GPS parsing example in the Adafruit GPS library. I've only been able to play with the bottom of the code for all of the Serial.print's. I haven't been able to find where the NMEA sentences get printed.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Ultimate GPS parsing formatting

Post by adafruit_support_bill »

Look in Adafruit_gps.h for the output options:

Code: Select all

// turn on only the second sentence (GPRMC)
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
// turn on GPRMC and GGA
#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
// turn on ALL THE DATA
#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
// turn off output
#define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
This is set in the Parsing example code here:

Code: Select all

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
And to replace a newline with a tab in your output, just replace the "\n" in the Serial.print() with a "\t".

night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Re: Ultimate GPS parsing formatting

Post by night3dynamo »

Thanks for the reply. I think I understand now that suppressing the NMEA output may not be possible. When I use "PMTK_SET_NMEA_OUTPUT_OFF" nothing gets parsed to location or time (because no GPRMC and GGA strings are being sent to the Arduino), and $PGTOP is still printed.

That said, I can't find the newline character "\n" in either the parsing example or Adafruit_gps.h in order to at least shove all the NMEA sentences to one tab limited line. Can you point me where you were referring to?

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Ultimate GPS parsing formatting

Post by adafruit_support_bill »

In the loop:

Code: Select all

 // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    
    Serial.print("\nTime: "); //<---------------------------------------------newline
    Serial.print(GPS.hour, DEC); Serial.print(':');

night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Re: Ultimate GPS parsing formatting

Post by night3dynamo »

Thanks for the reply. That newline does not control the unparsed NMEA output , only the serial.print for the word "Time". The parsing code (or library) prints each unparsed NMEA sentence on a newline, while I would like to use a tab instead. Is there a serial.println or \n that controls that unparsed NMEA output?

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Ultimate GPS parsing formatting

Post by adafruit_support_bill »

Those newlines are coming from the GPS. The code just echoes them. You would need to look at each character coming in and swap it before you print it. If you are using interrupts, that would be here:

Code: Select all

// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) UDR0 = c;
    // writing direct to UDR0 is much much faster than Serial.print
    // but only one character can be written at a time.
}

night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Re: Ultimate GPS parsing formatting

Post by night3dynamo »

Much appreciated. Yes, I'm using the default parsing example which uses interrupt. Thanks for the help. If I'm able to figure out how to modify the GPS output I will post that here for others.

night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Re: Ultimate GPS parsing formatting

Post by night3dynamo »

I'm back! I commented out the following lines. I'm not really clear on the function, but knowing that it was printed one character at a time from the GPS led me to that code.

Code: Select all

SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  //if (GPSECHO)  <--------
  //  if (c) UDR0 = c;  <--------
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}
I also modified the code to get a tab delimited output with a table heading. I posted it below if it will be useful to anyone else. Set serial to 57600. I have to play around with the print spacing a little since it messes up when the seconds are less than 10. Shouldn't be a huge issue since my goal is to record and export to Excel/MATLAB. Welcome to suggestions/improvements!

Image

Code: Select all

// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
// #include <NewSoftSerial.h>
 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
#if ARDUINO >= 100
  SoftwareSerial mySerial(3, 2);
#else
  NewSoftSerial mySerial(3, 2);
#endif
Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(57600);
  Serial.println("Adafruit GPS library basic test!");
Serial.print("HH:MM:SS");Serial.print("\t");
    Serial.print("DD/MM/YYY");Serial.print("\t");  
    Serial.print("FIX");Serial.print("\t");   
    Serial.print("Quality");Serial.print("\t");   
    Serial.print("Latitude");Serial.print("\t");   
    Serial.print("Longitude");Serial.print("\t");   
    Serial.print("Speed");Serial.print("\t");  
    Serial.print("Angle");Serial.print("\t");   
    Serial.print("Altitude");Serial.print("\t");   
    Serial.print("Sats");Serial.print("\t"); 
    Serial.println(""); 
  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  mySerial.println(PMTK_Q_RELEASE);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  //if (GPSECHO)
  //  if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) UDR0 = c;
      // writing direct to UDR0 is much much faster than Serial.print 
      // but only one character can be written at a time. 
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
    
    
    
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('\t');


    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.print(GPS.year, DEC);Serial.print("\t");
    
    Serial.print((int)GPS.fix); Serial.print("\t");
    Serial.print((int)GPS.fixquality); Serial.print("\t");
    
        
    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);Serial.print("\t");
      Serial.print(GPS.longitude, 4); Serial.print(GPS.lon);Serial.print("\t");
      Serial.print(GPS.speed);Serial.print("\t");
      Serial.print(GPS.angle);Serial.print("\t");
      Serial.print(GPS.altitude);Serial.print("\t");
      Serial.print((int)GPS.satellites);Serial.println("\t");
    }
  }
}

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: Ultimate GPS parsing formatting

Post by fmbfla »

Nice werk!
Put this in your code for the "GPS.minutes and Seconds" and it will stay Formatted.

Code: Select all

    if((GPS.minute) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");Serial.print((GPS.minute), DEC);
    }
    else{
      Serial.print((GPS.minute), DEC);
    }
        Serial.print(':');
    if((GPS.seconds) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");Serial.print((GPS.seconds), DEC);
    }
    else{
      Serial.print((GPS.seconds), DEC);
    }
Here is the whole thing "changed up a bit", (software serials are reversed for my application)Hope you don't mind :-)

Code: Select all

// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
// #include <NewSoftSerial.h>
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
#if ARDUINO >= 100
  SoftwareSerial mySerial(2, 3);
#else
  NewSoftSerial mySerial(3, 2);
#endif
Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(57600);
  Serial.println("Adafruit GPS library basic test!");
Serial.print("HH:MM:SS");Serial.print("\t");
    Serial.print("DD/MM/YYY");Serial.print("\t");  
    Serial.print("FIX");Serial.print("\t");   
    Serial.print("Quality");Serial.print("\t");   
    Serial.print("Latitude");Serial.print("\t");   
    Serial.print("Longitude");Serial.print("\t");   
    Serial.print("Speed");Serial.print("\t");  
    Serial.print("Angle");Serial.print("\t");   
    Serial.print("Altitude");Serial.print("\t");   
    Serial.print("Sats");Serial.print("\t"); 
    Serial.println(""); 
  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  mySerial.println(PMTK_Q_RELEASE);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  //if (GPSECHO)
  //  if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) UDR0 = c;
      // writing direct to UDR0 is much much faster than Serial.print 
      // but only one character can be written at a time. 
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
  

    if(GPS.hour =12 < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print(" ");
      Serial.print((GPS.hour > 12) ? GPS.hour - 12 : ((GPS.hour == 0) ? 12 : GPS.hour), DEC); // Conversion to AM/PM  
    }
    else{
      Serial.print((GPS.hour > 12) ? GPS.hour - 12 : ((GPS.hour == 0) ? 12 : GPS.hour), DEC); // Conversion to AM/PM
    }
    Serial.print(':');
    if((GPS.minute) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");Serial.print((GPS.minute), DEC);
    }
    else{
      Serial.print((GPS.minute), DEC);
    }
        Serial.print(':');
    if((GPS.seconds) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");Serial.print((GPS.seconds), DEC);
    }
    else{
      Serial.print((GPS.seconds), DEC);
    }
    if(GPS.hour < 12){   // Adding the AM/PM sufffix
      Serial.print(" A");Serial.print("\t");
    }
    else{
      Serial.print(" P");Serial.print("\t");// Serial.print("\t");
    }

    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.print(GPS.year, DEC);Serial.print("\t");
    Serial.print((int)GPS.fix); Serial.print("\t");
    Serial.print((int)GPS.fixquality); Serial.print("\t");

    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(" N");Serial.print("\t");
      Serial.print(GPS.longitude, 4); Serial.print(" W");Serial.print("\t");
      Serial.print(GPS.speed);Serial.print("\t");
      //Change from Degrees to N,S,E,W
            if ((GPS.angle > 348.75)||(GPS.angle < 11.25))Serial.print("N ");
      if ((GPS.angle >= 11.25)&&(GPS.angle < 33.75))Serial.print("NNE ");
      if ((GPS.angle >= 33.75)&&(GPS.angle < 56.25))Serial.print("NE ");
      if ((GPS.angle >= 56.25)&&(GPS.angle < 78.75))Serial.print("ENE ");
      if ((GPS.angle >= 78.75)&&(GPS.angle < 101.25))Serial.print("E ");
      if ((GPS.angle >= 101.25)&&(GPS.angle < 123.75))Serial.print("ESE ");
      if ((GPS.angle >= 123.75)&&(GPS.angle < 146.25))Serial.print("SE ");
      if ((GPS.angle >= 146.25)&&(GPS.angle < 168.75))Serial.print("SSE ");
      if ((GPS.angle >= 168.75)&&(GPS.angle < 191.25))Serial.print("S ");
      if ((GPS.angle >= 191.25)&&(GPS.angle < 213.75))Serial.print("SSW ");
      if ((GPS.angle >= 213.75)&&(GPS.angle < 236.25))Serial.print("SW ");
      if ((GPS.angle >= 236.25)&&(GPS.angle < 258.75))Serial.print("WSW ");
      if ((GPS.angle >= 258.75)&&(GPS.angle < 281.25))Serial.print("W ");
      if ((GPS.angle >= 281.25)&&(GPS.angle < 303.75))Serial.print("WNW ");
      if ((GPS.angle >= 303.75)&&(GPS.angle < 326.25))Serial.print("NW ");
      if ((GPS.angle >= 326.25)&&(GPS.angle < 348.75))Serial.print("NWN ");Serial.print("\t");

      Serial.print(GPS.altitude);Serial.print("\t");Serial.print("\t");
      Serial.print((int)GPS.satellites);Serial.println("\t");
    }
  }
}

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: Ultimate GPS parsing formatting

Post by fmbfla »

Code: Select all

    if(GPS.hour < 12){   // Adding the AM/PM sufffix
      Serial.print(" A");Serial.print("\t");
    }
    else{
      Serial.print(" P");Serial.print("\t");// Serial.print("\t");
    }
should be
if(GPS.hour > 12){ // Adding the AM/PM sufffix
Serial.print(" A");Serial.print("\t");
}
else{
Serial.print(" P");Serial.print("\t");// Serial.print("\t");
}
:oops:

night3dynamo
 
Posts: 15
Joined: Thu Dec 20, 2012 9:03 am

Re: Ultimate GPS parsing formatting

Post by night3dynamo »

fmbfla - thanks for the tips! Much appreciated.

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: Ultimate GPS parsing formatting

Post by fmbfla »

Code: Select all

//Neg -4 for East coast U.S.A.
    int gpsTIME = (GPS.hour - 4);
    if(gpsTIME > 12){  
      //Serial.print("0");
      Serial.print((gpsTIME > 12) ? gpsTIME - 12 :((gpsTIME == 0) ? 12 : gpsTIME ), DEC  ); // Once the clock reaches 12:00 Hrs 
      // I take away 12 Hrs from 24 hour clock and print it out
    }
    else{
      Serial.print(gpsTIME , DEC ); // Conversion to AM/PM
    }

    Serial.print(':');
    if((GPS.minute) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0"); // keeps the numbers in one place when less than 10
      Serial.print((GPS.minute), DEC);
    }
    else{
      Serial.print((GPS.minute), DEC);
    }
    Serial.print(':');
    if((GPS.seconds) < 10){  // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");// keeps the numbers in one place when less than 10
      Serial.print((GPS.seconds), DEC);
    }
    else{
      Serial.print((GPS.seconds), DEC);
    }
    if(gpsTIME < 12){   // Adding the AM/PM sufffix
      Serial.println(" AM");
    }
    else{
      Serial.println(" PM");
    }

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”