Simple GPS Library

1. Overview

The library works with most standard GPS module. It will interpret data from GPS module and provide usable information to your program. The library supports NMEA messages with two required ones are $GPGGA and $GPRMC.

This library relies on Software Serial library and that must be included in your program.

2. Circuit & Operation

Most GPS modules automatically output NMEA messages at a certain rate, for example, once every second. They usually work independently without having to be setup or controlled. GPS library only tracks messages from the module when it needs to update data, otherwise, output messages will be ignored.

Therefore, your program is free to do other things while having GPS module connected. Any IO pin on Ansteron Board can be used to accept signal. There is no additional setup needed except one that GPS modules will take time to start up and its outputs are unusable for that period.

Typical connection between Ansteron Board and GPS module:

GPS modules usually send messages on TX pin at 4800bps (may vary depends on each module). Your program must change the baurate of SoftSerial before data can be retrieved. Below is an example:

This program will retrieve location data from GPS module and display on Serial Terminal. The numbers are raw data, latitude and longitude unit is in 1,000,000th of a degree. The descriptions for each value are below.

3. Functions

GPS_update(pin);

Update current data with data from GPS module. After this function is called, new data will be placed on memory and can be read at any time. Input pin is the IO where data signal of GPS module connected to, similar to other IO functions ( PIN_Bx, PIN_Cx, PIN_Dx). This function will poll for data and will not return until all necessary information is retrieved. The time this function takes will vary, depends on GPS module (up to 1 second for 1Hz modules).

GPS_pos_fix();

Return position fix indicator of GPS data. If it is letter "0" then data is not valid. Other values indicate different modes but for any of those, location data is valid.

GPS_time();

GPS_date();

Return UTC time and date. They are long values and the formats are hhmmss for time, ddmmyy for date. For example, 172302 time value represent 17:23:02, which is 05:23:02 PM. You may need to add or subtract offset from UTC time to get your local time.

GPS_latitude();

GPS_longitude();

Return location data. Longitude and Altitude are in 1,000,000th of a degree unit. For example, value 40,568,235 represents 40.568235 degree. Returned values have long data type.

GPS_latitude_dms();

GPS_longitude_dms();

Return location data in Degree-Minute-Second format. They are long values in the format ddmm.mmmm for latitude, dddmm.mmmm for longitude. For example, longitude value 56,352,653 represents 56:35.2653 (degree:minute).

GPS_NS_indicator();

GPS_EW_indicator();

Return North/South and East/West indicator. They are turn letter (char) "N" or "S" and "E" or "W".

GPS_altitude();

GPS_altitude_meter();

Return the altitude in foot and meter units respectively.

GPS_speed();

GPS_speed_knot();

Return speed over ground in mile per hour (mph) or knot respectively.

GPS_satellites_count();

Return the number of satellites currently in use.

sprint_GPS_time(buffer);

sprint_GPS_date(buffer);

Print GPS UTC time and date into buffer as a string. The format for time is HH:MM:SS and date is MM/DD/YY. Buffer size is 9 bytes minimum.

sprint_GPS_location(buffer);

Print GPS location data into buffer as a string in real number format. For example, "23.235642,70.56365" or "40.253652,-82.351236". This function handles the sign of latitude and longitude according to NS and EW indicators. Buffer should be big enough to hold the result string (up to 22 bytes). Function returns the length of output string.

sprint_GPS_latitude(buffer);

sprint_GPS_longitude(buffer);

Print individually Latitude or Longitude to buffer. They are both in degree and +/- signs are automatically handled. These functions returns the length of output string.

4. Note

Some GPS module supports higher data baurates. However, staying at rate equal or lower than 19200 is recommended for the library to work properly due to the time needed to interpret data.