G'day all,
I'm sure I don't need to tell you I'm a "Newb" because I'm here asking a question!
I've been trying to parse GPS data from a 3G phone module but only when called. The output from the module is formatted as GPSACP and not the generic GPRMC sentence as would be the case with dedicated free running GPS. I have no trouble getting the data from the module as required but without re-inventing the wheel and writing the parsing code myself I can't figure out how to use for example Tiny GPS to simplify the task. Is there a way to get this Library to recognise the GPSACP: sentence from the 3G module? The code below is based on the work of others so I'm confident that with a valid GPRMC sentence output it would work fine.
Any assitance would be greatly appreciated.
Cheers
Greg.
// In order for this sketch to work, you will need to download
//TinyGPS libraries from arduiniana.org and put them
// into the hardware->libraries folder in your ardiuno directory.
// Here are the lines of code that point to those libraries.
#include <TinyGPS.h>
TinyGPS gps;
//void getgps(TinyGPS &gps);
void setup()
{
// This is the serial rate for your terminal program. It must be this
// fast because we need to print everything before a new sentence
// comes in. If you slow it down, the messages might not be valid and
// you will likely get checksum errors.
Serial.begin(115200);
Serial.println("");
Serial.println("GPS Test Example Sketch");
Serial.println("");
Serial.println("ATE0"); //turn echo off
delay(5000); //wait for 3G module
Serial.println("AT$GPSP=1");
delay(5000); //wait for 3G module
}
// This is the main loop of the code. All it does is check for data on
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
void loop()
{
Serial.println ("AT$GPSACP"); // Call for GPS data
while(Serial.available()) // While there is data on the RX pin...
{
int c = Serial.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
}
}
delay(10000); //delay before next loop
}
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// To get all of the data into varialbes that you can use in your code,
// all you need to do is define variables and query the object for the
// data. To see the complete list of functions see keywords.txt file in
// the TinyGPS and NewSoftSerial libs.
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
// You can now print variables latitude and longitude
Serial.print("Lat/Long: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);
// Same goes for date and time
/*int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// Print data and time
Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
//Since month, day, hour, minute, second, and hundr
*/
// Here you can print the altitude and course values directly since
// there is only one value for the function
//Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
// Same goes for course
Serial.print("Course (degrees): "); Serial.println(gps.f_course());
// And same goes for speed
Serial.print("Speed(knots): "); Serial.println(gps.f_speed_knots());
Serial.println();
// Here you can print statistics on the sentences.
//unsigned long chars;
//unsigned short sentences, failed_checksum;
//gps.stats(&chars, &sentences, &failed_checksum);
//Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
//Serial.println(); Serial.println();
}