GPS sketch with nice output

This sketch prints out
Date: Latitude: Longitude:
Speed Over Ground mph: and kmh:
Course Over Ground (degrees): Fix: Satellites in use:
Total Satellites in use: and Satellites in view:
I adapted the code from the GPStest_RMC sketch
NewSoftSerial.h is at NewSoftSerial | Arduiniana
enjoy :slight_smile:

// This sketch needs $GPRMC, $GPGSA and $GPGSV activated.

#include <NewSoftSerial.h>
NewSoftSerial mySerial =  NewSoftSerial(2, 3);
#define powerpin 4
#define BUFFSIZ 90
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;
uint8_t hour, minute, second, year, month, date, i, anz=0;
uint16_t latitude, longitude, groundspeed, trackangle, track, mph, gs, tmp;
char latdir, longdir;
char status;
int k=0;
  void setup() 
  { 
  if (powerpin) pinMode(powerpin, OUTPUT);
  pinMode(13, OUTPUT);
  Serial.begin(115200);
  mySerial.begin(4800);
  digitalWrite(powerpin, LOW);         
  delay(500);
  } 

void loop() 
{ 
   
  readline();
  //Serial.println(" "); Serial.println(buffer);  // activate this line to see your gps raw data !!!
  if (strncmp(buffer, "$GPRMC",6) == 0)           // check $GPRMC
  {
   parseptr = buffer+7; // hhmmss time
   tmp = parsedecimal(parseptr); 
   hour = tmp / 10000;
   minute = (tmp / 100) % 100;
   second = tmp % 100;

    parseptr = strchr(parseptr, ',') + 1;
    status = parseptr[0];
    parseptr += 2;

    latitude = parsedecimal(parseptr);        // latitude
      if (latitude != 0) 
      {
      latitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      latitude += parsedecimal(parseptr);
      }
    parseptr = strchr(parseptr, ',') + 1;
   
      if (parseptr[0] != ',')                // latitude N/S 
      {
      latdir = parseptr[0];
      }

    parseptr = strchr(parseptr, ',')+1;      // longitude
    longitude = parsedecimal(parseptr);
      if (longitude != 0)
      {
      longitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      longitude += parsedecimal(parseptr);
      }
    parseptr = strchr(parseptr, ',')+1;
   
      if (parseptr[0] != ',')              // read longitude E/W data
      {
      longdir = parseptr[0];
      }
    
    parseptr = strchr(parseptr, ',')+1;    // groundspeed conversion
    tmp = parsedecimal(parseptr);
    parseptr = strchr(parseptr, '.')+1;
    groundspeed = parsedecimal(parseptr);
      if(tmp != 0)
      {
      tmp *= 100;
      groundspeed += tmp;
      mph=groundspeed * 1.151;
      groundspeed *= 1.852;  
      
      }
      else
      {
       mph=groundspeed * 1.151;
       groundspeed *= 1.852;
       }
          
    parseptr = strchr(parseptr, ',')+1;    // track angle
    trackangle = parsedecimal(parseptr);
    parseptr = strchr(parseptr, '.')+1;
    track = parsedecimal(parseptr);

    parseptr = strchr(parseptr, ',')+1;     // date + time
    tmp = parsedecimal(parseptr); 
    date = tmp / 10000;
    month = (tmp / 100) % 100;
    year = tmp % 100;

    Serial.print("Date: ");
    Serial.print(month, DEC); 
    Serial.print('/');
    Serial.print(date, DEC); 
    Serial.print('/');
    Serial.print(year, DEC);
    Serial.print("    Time: ");
    Serial.print(hour, DEC); 
    Serial.print(':');
    Serial.print(minute, DEC); 
    Serial.print(':');
    Serial.println(second, DEC);

    Serial.print("Latitude:  "); 
    Serial.print((char) latdir); 
    Serial.print(' ');
    Serial.print(latitude/1000000, DEC); 
    Serial.print(' ');
    Serial.print((latitude/10000)%100, DEC); 
    Serial.print('\''); 
    Serial.print(' ');
    Serial.print((latitude/100)%100, DEC); 
    Serial.print('.');
    Serial.print((latitude%100), DEC); 
    Serial.println('"');
    Serial.print("Longitude: ");
    Serial.print((char) longdir); 
    Serial.print(' ');
    Serial.print(longitude/1000000, DEC); 
    Serial.print(' ');
    Serial.print((longitude/10000)%100, DEC); 
    Serial.print('\''); 
    Serial.print(' ');
    Serial.print((longitude/100)%100, DEC); 
    Serial.print('.');
    Serial.print((longitude%100), DEC); 
    Serial.println('"');

    Serial.print("Speed Over Ground  mph: ");
    gs=mph;
    tempo(gs);
    Serial.print("    kmh: ");
    gs=groundspeed;
    tempo(gs);
    Serial.println(" ");  
    Serial.print("Course Over Ground (degrees): ");
    Serial.print(trackangle);Serial.print(".");
    Serial.println(track);
  }
 
  if (strncmp(buffer, "$GPGSA",6) == 0)       // check $GPGSA
  {
   parseptr = buffer+8;
   parseptr = strchr(parseptr, ',')+1;
      if (parseptr[0] != ',')                // FixType
      {
      latdir = parseptr[0];
      }
     if(latdir=='1') Serial.println("Fix: Not Available"); 
     if(latdir=='2') Serial.println("FixType: 2D ");
     if(latdir=='3') Serial.println("FixType: 3D ");
     
     Serial.print("Satellites in use: ");
      while (i<=8)
      {
       parseptr = strchr(parseptr, ',')+1;     // date
       tmp = parsedecimal(parseptr);
         if (tmp != 0)                // latitude N/S 
        {
        Serial.print("  --  "); Serial.print(tmp);
        anz=anz+1;  
        }
        i++;
       } 
   Serial.println(" "); Serial.print("Total Satellites in use: ");
   Serial.println(anz, DEC);
   i=0; anz=0;
   }
  
   if (strncmp(buffer, "$GPGSV",6) == 0)         // check $GPGSV
  {
   parseptr = buffer+7;
   tmp = parsedecimal(parseptr);                // Number of Messages
   parseptr = strchr(parseptr, ',')+1;
   anz = parsedecimal(parseptr);                // Message Number
   parseptr = strchr(parseptr, ',')+1;
   hour = parsedecimal(parseptr);               // Satellites in View
     if(anz==1)
    {
      Serial.print("Satellites in view: "); Serial.println(hour, DEC);
    }
      
      switch (tmp) 
      {
      case 1:
      year=hour;
      break;
      case 2:
      if(anz==1) year=4;
      if(anz==2) year=hour-4;
      break;
      case 3:
      if(anz<3) year=4;
      if(anz==3) year=hour-8;
      }

      year--;
      i=0;
       while (i < year)
      {
       parseptr = strchr(parseptr, ',')+1;        
       minute = parsedecimal(parseptr);
          if ((minute >= 1) && (minute <= 32))               
         {
         Serial.print("  --  "); Serial.print(minute, DEC);
         parseptr = strchr(parseptr, ',')+1;        
         parseptr = strchr(parseptr, ',')+1;        
         parseptr = strchr(parseptr, ',')+1;        
         i++;
         }
    }
        parseptr = strchr(parseptr, ',')+1;        
        minute = parsedecimal(parseptr);
        if ((minute >= 1) && (minute <= 32))               
         Serial.print("  --  "); Serial.print(minute, DEC);
         if(tmp==anz) Serial.println(" ");
         anz=0;
  }
} 

uint32_t parsedecimal(char *str)
{
 uint32_t d = 0;

    while (str[0] != 0)
    {
    if ((str[0] > '9') || (str[0] < '0'))
      return d;
    d *= 10;
    d += str[0] - '0';
    str++;
    }
  return d;
}

void readline(void)
{
  char c;
  buffidx = 0;        
    while (1)
    {
    c=mySerial.read();
    if (c == -1) continue;
    if (c == '\n') continue;
      if ((buffidx == BUFFSIZ-1) || (c == '\r'))
      {
      buffer[buffidx] = 0;
      return;
      }
    buffer[buffidx++]= c;
    }
}
void tempo(uint16_t gs)
{
  if(gs <=99)      // speed output conversion
    {
    Serial.print("0.");
    Serial.print(gs);
    }
    else
    {
    Serial.print(gs/100, DEC); Serial.print(".");
    tmp = gs % 100;
    if(tmp <=9) Serial.print("0");
    Serial.print(tmp);  
    }
}
// enjoy - arduino forum user: head