Extracting $GPGGA line from NMEA GPS output

Good Afternoon,

Probably a simple solution for this one, but I’d like the community’s opinion as to the best way to go about this :slight_smile:
Basically, I have a GPS module (see below for the hardware) connected to our good ol’ Arduino Uno. The below code achieves full NMEA output which is great for interfacing with things such as Earth Bridge, but my project is to create a simple car tracker (forget about GSM at the moment). What I’d like is for the below code to simply output the NMEA sentence starting with “$GPGGA” for position data only as this will eventually be sent over GSM on request. I’ve seen a couple of threads about this, but none of them seem to have a sample solution.

GPS Module Hardware: http://rockblock.rock7mobile.com/?p=394

Any guidance is much appreciated. Thanks guys, Danny.

/* 
   9600  baud is GPS module RAW data output
   57600 baud is processed NMEA data output
*/

#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(3,4); //RX, TX pins for GPS module

int sleepPin = 2; //GPS module power-save pin

void setup()
{ 
  pinMode(sleepPin, OUTPUT);
  digitalWrite(sleepPin, HIGH);
  
  Serial.begin(57600);
  gpsSerial.begin(9600);
  gpsSerial.listen();
}

void loop()
{
  if (gpsSerial.available())
  {
    Serial.write(gpsSerial.read());     //<<< I need to extract the applicable NMEA line here, rather than just print the whole bunch.
  }
}

Declare a char array large enough to hold a single line. As serial data comes in, stuff the data in the array and null-terminate it. Once a new line is reached, use strncmp() to check if it has the proper header. If so, use strtok() to go through each of the comma deliminated tokens and extract the data as you see fit. atof() can convert the string into a float. Reset the array after it has been parsed by putting a null-terminating character as the first item and set the index variable back to 0.

Arrch: Declare a char array large enough to hold a single line. As serial data comes in, stuff the data in the array and null-terminate it. Once a new line is reached, use strncmp() to check if it has the proper header. If so, use strtok() to go through each of the comma deliminated tokens and extract the data as you see fit. atof() can convert the string into a float. Reset the array after it has been parsed by putting a null-terminating character as the first item and set the index variable back to 0.

Thanks for the suggestions there, Arrch. I'll look into the methods you've advised and return shortly. In the meantime, any further guidance, as always, is very much appreciated :)

Are you aware of tinyGPS, or are you not allowed to use it for some reason?

AWOL: Are you aware of tinyGPS, or are you not allowed to use it for some reason?

This is a personal project so I'm free to use whatever I please. I have heard of TinyGPS (but know very little of it at the moment). The only reason I have used the method I have done so far in my code is because it was suggested on the GPS Hardware Module page. Is TinyGPS compatible with all GPS hardware? Feel free to take a look at my hardware using the link on my first post :)

I ended up installing the TinyGPS library (amazing) and modifying one of the example sketches which gave me exactly what I needed. Thanks for your help! :)