TinyGPS++

A *NEW* Full-featured GPS/NMEA Parser for Arduino

TinyGPS++ is a new Arduino library for parsing NMEA data streams provided by GPS modules.

Like its predecessor, TinyGPS, this library provides compact and easy-to-use methods for extracting position, date, time, altitude, speed, and course from consumer GPS devices. 

However, TinyGPS++’s programmer interface is considerably simpler to use than TinyGPS, and the new library can extract arbitrary data from any of the myriad NMEA sentences out there, even proprietary ones.

Download and Installation

To install this library, download here, unzip the archive into the Arduino “libraries” folder, and restart Arduino. You should rename the folder “TinyGPSPlus”.
Download

History

TinyGPS++ is the immediate inheritor of TinyGPS, a popular compact parser that is used in Arduino installations around the world.  TinyGPS++ is not quite as ‘tiny’ as its older sibling, but its powerful and extremely easy-to-use new object model and useful new feature set make it an attractive alternative.

Usage

Let’s say you have an Arduino hooked to an off-the-shelf GPS device and you want to display your altitude.  You would simply create a TinyGPS++ instance like this:

#include "TinyGPS++.h"
TinyGPSPlus gps;

Repeatedly feed it characters from your GPS device:

while (ss.available() > 0)
  gps.encode(ss.read());

Then query it for the desired information:

if (gps.altitude.isUpdated())
  Serial.println(gps.altitude.meters());

Differences from TinyGPS

Although TinyGPS++ shares much the same compact parsing engine with TinyGPS, its programmer interface is somewhat more intuitive.  As a simple example, here’s how easy it is to print out the current latitude, longitude, and altitude in TinyGPS++:

Serial.print("LAT=");  Serial.println(gps.location.lat(), 6);
Serial.print("LONG="); Serial.println(gps.location.lng(), 6);
Serial.print("ALT=");  Serial.println(gps.altitude.meters());

Both libraries extract basic position, altitude, course, time, and date, etc. from two common NMEA sentences, $GPGGA and $GPRMC. But there are a number of other interesting sentences out there, both NMEA-defined and vendor-proprietary, just waiting to be harvested.

Consider the obscure $GPRMB, for example, which provides “recommended minimum navigation information” if you have a destination waypoint defined.

$GPRMB,A,4.08,L,EGLL,EGLM,5130.02,N,00046.34,W,004.6,213.9,122.9,A*3D

With TinyGPS++ it is now possible to extract just the “L” in the third field (it means “steer Left!”). It’s easy with the new TinyGPSCustom watcher object:

TinyGPSCustom steerDirection(gps, "GPRMB", 3);
...
Serial.print(steerDirection.value()); // prints "L" or "R"

Naturally, this extra functionality comes at some cost.  TinyGPS++ consumes somewhat more memory than TinyGPS, and it’s interface is incompatible.  So how to decide whether to update?  Here’s a guide:

Consider TinyGPS++ over TinyGPS if:

  • Compatibility with existing code (using TinyGPS) isn’t necessary.
  • Your sketch is not close to reaching RAM or flash resource limits.
  • You are running on Due or processor which can take advantage of the higher precision of 64-bit “double” floating-point.
  • You prefer the more intuitive object model.
  • You need to query for NMEA data beyond the basic location, date, time, altitude, course, speed, satellites or hdop.

Feeding the Hungry Object

To get TinyGPS++ to work, you have to repeatedly funnel the characters to it from the GPS module using the encode() method. For example, if your GPS module is attached to pins 4(RX) and 3(TX), you might write code like this:

SoftwareSerial ss(4, 3);
void loop()
{
  while (ss.available() > 0)
    gps.encode(ss.read);
  ...

After the object has been “fed” you can query it to see if any data fields have been updated:

  if (gps.location.isUpdated())
  {
    Serial.print("LAT="); Serial.print(gps.location.lat(), 6);
    Serial.print("LNG="); Serial.println(gps.location.lng(), 6);
  }
} // end loop()

The TinyGPS++ Object Model

The main TinyGPS++ object contains several core sub-objects:

  • location – the latest position fix
  • date – the latest date fix (UT)
  • time – the latest time fix (UT)
  • speed – current ground speed
  • course – current ground course
  • altitude – latest altitude fix
  • satellites – the number of visible, participating satellites
  • hdop – horizontal diminution of precision

Each provides methods to examine its current value, sometimes in multiple formats and units. Here’s a complete list:

Serial.println(gps.location.lat(), 6); // Latitude in degrees (double)
Serial.println(gps.location.lng(), 6); // Longitude in degrees (double)
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg); // Raw latitude in whole degrees
Serial.println(gps.location.rawLat().billionths);// ... and billionths (u16/u32)
Serial.print(gps.location.rawLng().negative ? "-" : "+");
Serial.println(gps.location.rawLng().deg); // Raw longitude in whole degrees
Serial.println(gps.location.rawLng().billionths);// ... and billionths (u16/u32)
Serial.println(gps.date.value()); // Raw date in DDMMYY format (u32)
Serial.println(gps.date.year()); // Year (2000+) (u16)
Serial.println(gps.date.month()); // Month (1-12) (u8)
Serial.println(gps.date.day()); // Day (1-31) (u8)
Serial.println(gps.time.value()); // Raw time in HHMMSSCC format (u32)
Serial.println(gps.time.hour()); // Hour (0-23) (u8)
Serial.println(gps.time.minute()); // Minute (0-59) (u8)
Serial.println(gps.time.second()); // Second (0-59) (u8)
Serial.println(gps.time.centisecond()); // 100ths of a second (0-99) (u8)
Serial.println(gps.speed.value()); // Raw speed in 100ths of a knot (i32)
Serial.println(gps.speed.knots()); // Speed in knots (double)
Serial.println(gps.speed.mph()); // Speed in miles per hour (double)
Serial.println(gps.speed.mps()); // Speed in meters per second (double)
Serial.println(gps.speed.kmph()); // Speed in kilometers per hour (double)
Serial.println(gps.course.value()); // Raw course in 100ths of a degree (i32)
Serial.println(gps.course.deg()); // Course in degrees (double)
Serial.println(gps.altitude.value()); // Raw altitude in centimeters (i32)
Serial.println(gps.altitude.meters()); // Altitude in meters (double)
Serial.println(gps.altitude.miles()); // Altitude in miles (double)
Serial.println(gps.altitude.kilometers()); // Altitude in kilometers (double)
Serial.println(gps.altitude.feet()); // Altitude in feet (double)
Serial.println(gps.satellites.value()); // Number of satellites in use (u32)
Serial.println(gps.hdop.value()); // Horizontal Dim. of Precision (100ths-i32)

Validity, Update status, and Age

You can examine an object’s value at any time, but unless TinyGPS++ has recently been fed from the GPS, it should not be considered valid and up-to-date. The isValid() method will tell you whether the object contains any valid data and is safe to query.

Similarly, isUpdated() indicates whether the object’s value has been updated (not necessarily changed) since the last time you queried it.

Lastly, if you want to know how stale an object’s data is, call its age() method, which returns the number of milliseconds since its last update. If this returns a value greater than 1500 or so, it may be a sign of a problem like a lost fix.

Debugging

When a TinyGPS++ sketch fails, it’s usually because the object received an incomplete NMEA stream, or perhaps none at all.

Fortunately, it’s pretty easy to determine what’s going wrong using some built-in diagnostic methods:

  • charsProcessed() – the total number of characters received by the object
  • sentencesWithFix() – the number of $GPRMC or $GPGGA sentences that had a fix
  • failedChecksum() – the number of sentences of all types that failed the checksum test
  • passedChecksum() – the number of sentences of all types that passed the checksum test

If your sketch has been running a while but charsProcessed() is returning 0, you likely have a problem with your wiring or serial connection. (If data never arrives from the GPS unit, it stands to reason it’s not getting to TinyGPS++.) I often insert a little debug clause into my GPS sketches detects this condition then prints out the incoming stream:

// Debug: if we haven't seen lots of data in 5 seconds, something's wrong.
if (millis() > 5000 && gps.charsProcessed() < 10) // uh oh
{
  Serial.println("ERROR: not getting any GPS data!");
  // dump the stream to Serial
  Serial.println("GPS stream dump:");
  while (true) // infinite loop
    if (ss.available() > 0) // any data coming in?
      Serial.write(ss.read());
}

Another common failure is when the sentences sent to TinyGPS++ are incomplete. This usually happens when you retrieve the characters from the GPS so slowly or infrequently that some are lost. The symptom is easy to spot: checksum failure.

Explanation: Every NMEA sentence ends with a numeric field that represents a mathematical summing of all the characters in the sentence. It’s there to ensure data integrity. If this number doesn’t match the actual sum (perhaps because some characters went awry), TinyGPS++ simply discards the entire sentence and increments an internal “checksum failed” counter. You can read this counter with:

Serial.print("Sentences that failed checksum=");
Serial.println(gps.failedChecksum());

// Testing overflow in SoftwareSerial is sometimes useful too.
Serial.print("Soft Serial device overflowed? ");
Serial.println(ss.overflow() ? "YES!" : "No");

If the checksum counter is continually incrementing, you have a problem. (Hint: don’t use delay() in your sketch.)

Custom NMEA Sentence Extraction

One of the great new features of TinyGPS++ is the ability to extract arbitrary data from any NMEA or NMEA-like sentence. Read up on some of the interesting sentences there are out there, then check to make sure that your GPS receiver can generate them.

The idea behind custom extraction is that you tell TinyGPS++ the sentence name and the field number you are interested in, like this:

TinyGPSCustom magneticVariation(gps, "GPRMC", 10)

This instructs TinyGPS++ to keep an eye out for $GPRMC sentences, and extract the 10th comma-separated field each time one flows by. At this point, magneticVariation is a new object just like the built-in ones. You can query it just like the others:

if (magneticVariation.isUpdated())
{
  Serial.print("Magnetic variation is ");
  Serial.println(magneticVariation.value());
}

Establishing a fix

TinyGPS++ objects depend on their host sketch to feed them valid and current NMEA GPS data. To ensure their world-view is continually up-to-date, three things must happen:

  1. You must continually feed the object serial NMEA data with encode().
  2. The NMEA sentences must pass the checksum test.
  3. For built-in (non-custom) objects, the NMEA sentences must self-report themselves as valid. That is, if the $GPRMC sentence reports a validity of “V” (void) instead of “A” (active), or if the $GPGGA sentence reports fix type “0″ (no fix), then the position and altitude information is discarded (though time and date are retained).

It may take several minutes for a device to establish a fix, especially it has traveled some distance or a long time has elapsed since its last use.

Distance and Course

If your application has some notion of a “waypoint” or destination, it is sometimes useful to be able to calculate the distance to that waypoint and the direction, or “course”, you must travel to get there. TinyGPS++ provides two methods to get this information, and a third (cardinal()) to display the course in friendly, human-readable compass directions.

const double EIFFEL_TOWER_LAT = 48.85826;
const double EIFFEL_TOWER_LNG = 2.294516;
double distanceKm =
  TinyGPSPlus.distanceBetween(
    gps.location.lat(),
    gps.location.lng(),
    EIFFEL_TOWER_LAT,
    EIFFEL_TOWER_LNG) / 1000.0;
double courseTo =
  TinyGPSPlus.courseTo(
    gps.location.lat(),
    gps.location.lng(),
    EIFFEL_TOWER_LAT,
    EIFFEL_TOWER_LNG);
Serial.print("Distance (km) to Eiffel Tower: ");
Serial.println(distanceKm);
Serial.print("Course to Eiffel Tower: ");
Serial.println(courseTo);
Serial.print("Human directions: ");
Serial.println(TinyGPSPlus.cardinal(courseTo));

Library Version

You can retrieve the version of the TinyGPS++ library by calling the static member libraryVersion().

Serial.println(TinyGPSPlus::libraryVersion());

Sample Sketches

TinyGPS++ ships with several sample sketch which range from the simple to the more elaborate. Start with BasicExample, which demonstrates library basics without even requiring a GPS device, then move onto FullExample and KitchenSink. Later, see if you can understand how to do custom extractions with some of the other examples.

Acknowledgements

Thanks go out to the many Arduino forum users for outstanding help in testing and popularizing TinyGPS, this library’s predecessor. Thanks especially to Maarten Lamers, who wrote the wiring library that originally gave me the idea of how to organize TinyGPS++.

All input is appreciated.

Mikal Hart

Page last updated on September 28, 2014 at 11:35 am
429 Responses → “TinyGPS++”

  1. Adrian

    10 years ago

    I get only 0 for gps.satellites.value()
    it worked well for while and now it just shows 0. (gps.location.isValid()) is VALID so there must be a problem elsewhere. do i get i right u32 means unsigned integer with 32 bit?


  2. Mikal

    10 years ago

    @Adrian,

    If you’re getting valid latitude and longitude data but the satellites value is 0, that may mean that your receiver doesn’t generate this data (satellite count).

    If you’re not getting lat and long and you’re leaving the module outdoors with a clear view of the sky for a number of minutes, it may be that your module is broken. (I have seen this happen with 2 of my EM-406A modules.)

    Yes, u32 means unsigned 32-bit integer.


  3. michinyon

    10 years ago

    You should mention in the file comments which subfolder of \libraries\ this has to go into to make it work


  4. pixelatedpic

    10 years ago

    in TinyGPS it outputs lat, lon in floats too but is there any way to get float values from TinyGPS++? precision is needed..


  5. Mikal

    10 years ago

    @pixeladedpic,

    Yep. TinyGPS reports lat and long in C “double” type.


  6. pixelatedpic

    10 years ago

    so how to get precision? will 2 decimal point will be enough for an gps guided small car. any way to get float values if it is not


  7. Mikal

    10 years ago

    @pixelatedpic,

    The precision is already there. The (likely) problem is that you are printing the values using the default floating-point print, which truncates to 2 digits:

    double lat;
    Serial.print(lat); // This prints to only 2 digits
    Serial.print(lat, 6); // Do this instead
    

  8. Mikal

    10 years ago

    @pixelatedpic,

    The precision is already there. The (likely) problem is that you are printing the values using the default floating-point print, which truncates to 2 digits:

    double lat;
    Serial.print(lat); // This prints to only 2 digits
    Serial.print(lat, 6); // Do this instead
    

  9. pixelatedpic

    10 years ago

    thank you for the support :)
    This library is much better because distanceto and courseto save much time instead of doing the calculations our own. wish you luck.
    Once my prototype is done will update you. :)


  10. james

    10 years ago

    hi, i have found this amazing page! i am hoping to use this library on my robot but i am having issues, i have multiple serial port open, one connection to rasp pi, one through usb on arduino and the other to listen to the GPS, i am using a arduino mega. but it does not want to read the data coming from the serial port that my and encode it, in the loop it does everything up to gps.encode(GPS.read()); line of my code??? i am using other libraries such as, wire.h, hmc5883l.h, tinygps++.h, and softwareserial.h, am i missing something??? im not amazing at arduino but im not a newbie! but i suspect its a simple error!!


  11. Mikal

    10 years ago

    @james,

    A good initial debug step is to Serial.write() the characters that come in from the GPS (GPS.read()). Are there any? If not, your wiring may be wrong.


  12. Paolo

    10 years ago

    Hi Mikal,
    while testing the KitchenSink sketch, without the Altitude, DistanceTo & CourseTo portion, the printout generate the LOCATION line twice, with the only difference is 2-4ms of Age. This is a random duplication every 2-4 prints. GPS is feed via COM1 using a simulator every 3″(i.e. sending same data). Moving the LOCATION code 3 position down, the TIME line is randomly duplicated instead. Any hint?


  13. Ole

    10 years ago

    Hi
    I have an Arduino UNO and a UBLOX.5N GPS. When i run the TinyGPS++ FullExample.ino i got the date and time only? Sats, HDOP Lat Lon es just listed as **** **** **********. Sentebce RX is = 0, and Checksum Fail =0
    I use Mac OSX. 10.6.8 and Aurdino 1.0.5.

    Any idea?
    Ole

    FullExample.ino
    An extensive example of many interesting TinyGPS++ features
    Testing TinyGPS++ library v. 0.92
    by Mikal Hart

    Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum
    (deg) (deg) Age Age (m) — from GPS —- —- to London —- RX RX Fail
    —————————————————————————————————————————————
    **** **** ********** *********** **** ********** ******** **** ****** ****** ***** *** ******** ****** *** 0 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:21 641 ****** ****** ***** *** ******** ****** *** 64 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:22 719 ****** ****** ***** *** ******** ****** *** 128 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:23 796 ****** ****** ***** *** ******** ****** *** 192 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:24 874 ****** ****** ***** *** ******** ****** *** 255 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:26 23 ****** ****** ***** *** ******** ****** *** 383 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:27 101 ****** ****** ***** *** ******** ****** *** 447 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:28 179 ****** ****** ***** *** ******** ****** *** 511 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:29 256 ****** ****** ***** *** ******** ****** *** 575 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:30 333 ****** ****** ***** *** ******** ****** *** 638 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:31 411 ****** ****** ***** *** ******** ****** *** 701 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:32 489 ****** ****** ***** *** ******** ****** *** 765 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:33 567 ****** ****** ***** *** ******** ****** *** 829 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:34 643 ****** ****** ***** *** ******** ****** *** 892 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:35 719 ****** ****** ***** *** ******** ****** *** 956 0 0
    **** **** ********** *********** **** 12/28/2013 10:12:36 799 ****** ****** ***** *** ******** ****** *** 1020 0 0


  14. Steve

    10 years ago

    Is there a way to print the raw NMEA sentences?


  15. quade

    10 years ago

    I absolutely adore this! Thank you so much!

    I was having an HUGE issue in using this library with a display (http://www.adafruit.com/products/938), but I eventually figure out the magic of using the smartDelay() you had written into one of your examples. Once I started using that, it gave TinyGPSPlus enough time to decode everything properly.

    static void smartdelay(unsigned long ms)
    {
      unsigned long start = millis();
      do
      {
        while (ss.available())
          gps.encode(ss.read());
      }
      while (millis() - start < ms);
    }
    

    Brilliant work Mikal. Again, thank you.


  16. Mikal

    10 years ago

    @Paolo,

    The KitchenSink example updates the location display every time a sentence goes by that contains location info. Since both the $GPGGA and $GPRMC sentences contain location data, your observations don’t surprise me. The only way to tell for sure, though, is to look at the NMEA stream coming in.


  17. Mikal

    10 years ago

    @Ole,

    My guess is you are not getting a fix. Are you outside? Again, many of these problems can be solved by looking at the NMEA stream.


  18. Mikal

    10 years ago

    @Steve. Yep. It’s actually pretty easy. Simply Serial.write() each character that arrives just before you send it to TinyGPSPlus.encode().


  19. Mikal

    10 years ago

    @quade,

    Well, gee, that’s a kind comment. Thanks!


  20. harry

    10 years ago

    I tiring to improve the acc. of arduino GPS this is a project i have been working on for many months. I am new to arduino but it has the capability of complex math i have 2 gps modules but uses WAAS but can’t get a good location the other is on a balloon and is repeated through a 1.2 GHZ repeater . i have tried to input the balloon signals in to full example where the distance to tower is but haven’t had luck with that yet. any help would greatly appreciated and save a lot of time thanks again harry


  21. harry

    10 years ago

    after reading what I wrote the first time a possible fix. is it possible for tinygps++ to decipher two diff. gps signals at different times in your full example


  22. Andrew

    10 years ago

    Great routine !
    I am working on a pointer system for the Astra2 satellite (autotracking) and have managed to change the London LON LAT settings to the LON LAT for Astra2 however as we know the satellite is 28.2 degrees in the air at 38k kms. can you help me find the elevation from anypoint? I was hoping to use the tinygps++ satellite elevation but can not get it to function at any baud rate.
    regards
    A


  23. Mikal

    10 years ago

    @harry,

    It is easy to create two TinyGPS++ objects and have them each parse independent GPS NMEA streams. This works fine, although the tricky part will be acquiring the two streams simultaneously. Make sure at least one, and preferably both, are connected to hardware serial.


  24. harry

    10 years ago

    Andrew,
    we use http://heavens-above.com/ tracking LEO’s are done using a simple arduino code follow the cite instruction


  25. harry

    10 years ago

    after many hrs of trying I have come to the conclusion I don’t know enough about arduino Uno to get it to work with just one arduino can’t sync the data yet and can’t tell if the 2nd data is even getting in thanks for your help I do have a new starting place


  26. Andrew

    10 years ago

    @Harry
    Have had a look at the site and cannot see any code for my project
    At the moment when running Mikals code I receive the following
    Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum
    (deg) (deg) Age Age (m) — from GPS —- —- to Astra2 —- RX RX Fail
    —————————————————————————————————————————————
    **** **** ********** *********** **** ********** ******** **** ****** ****** ***** *** ******** ****** *** 63 0 1
    5 278 53.641242 -1.726477 517 01/06/2014 20:47:00 682 72.60 0.00 0.61 N 6571 144.46 SE 469 2 5

    I simply want to add “Elevation” to the output I have the following script to do the math but no idea how to include it for Arduino as it is in Java and html

    function calc(form, l, n, s) { // Function parameter names correspond to table variables

    // VARIABLES USED IN CALCULATIONS

    var azi;
    var ele;
    var g = (s – n);

    // CONVERSIONS TO RADIANS???

    var grad = (g / 57.29578);
    var lrad = (l / 57.29578);
    // var nrad = (n / 57.29578);
    // var srad = (s / 57.29578);

    // AZIMUTH CALCULATIONS

    azi = (3.14159 –
    (-Math.atan((Math.tan(grad)/Math.sin(lrad)))));

    form.azimuth.value = azi * 57.29578;

    // ELEVATION CALCULATIONS
    a = Math.cos(grad);
    b = Math.cos(lrad);
    ele = Math.atan((a * b -.1512)/(Math.sqrt(1 – (a*a) * (b*b))));

    form.elevation.value = ele * 57.29578;
    }


  27. Andrew

    10 years ago

    CONT FROM LAST POST NOT INCLUDED

    / Code

    EARTH STATION NORTH LATITUDE:
    degrees

    EARTH STATION WEST LONGITUDE:
    degrees

    SATELLITE WEST LONGITUDE:
    degrees

    AZIMUTH:
    degrees

    ELEVATION:
    degrees


  28. Ryan Blace

    10 years ago

    Hi,

    First, thank you so much for this library. It is perfect for my needs and much more.

    Can you explain a little more about the differences between .isValid and .isUpdated? I’ve looked through the code and in most cases, they are both being either set to TRUE or FALSE on the same line. Can you give an example case where they would differ? I’m thinking .isValid might represent what the NMEA is saying (VOID/FIX/0/ETC) and .isUpdated means a sentence which updates this object has been eaten since it was last queried.

    Finally, does reading .age() count as a query which resets .isValid?

    What would you recommend using if you are literally just building a digital speedometer?

    Thanks again,
    Ryan


  29. Cesar

    10 years ago

    Hi Mikal,

    Thanks for your contribution. This library is excellent. I am totally new in this Arduino, and C stuff, but with your library I am easily walking my first steps.

    I am just facing problems to work with altitude.When I print in the serial monitor just like in your examples:

    Serial.print(F(“ALT=”)); Serial.print(gps.altitude.meters());
    Serial.print(F(“, LAT=”)); Serial.print(gps.location.lat());
    Serial.print(F(“, LON=”)); Serial.println(gps.location.lng());

    This is the result of this line:

    ALT=651.40, LAT=-22.97, LON=-47.07

    It works fine, but when I try to convert the results into strings to later write into a SD card, the altitute is always “0″. This does not happen with lat and long. Any idea way ?

    Here is the line I am using:

    logPos = String(dtostrf(gps.location.lat(),10,7,sout))+ String(“,”)+ String(dtostrf(gps.location.lng(),10,7,sout))+ String(“,”)+ String(dtostrf(gps.altitude.meters(),10,7,sout));

    This is the result of this line:

    -22.9743420,-47.0670740, 0.0000000

    Thanks
    Cesar


  30. Stephen

    10 years ago

    I am still trying to convert the date and time to UTC +10 to suit Australian timezones. Any advice would be greatly appreciated.
    Has a time offset been added to this new library?

    Awesome work Mikal… Thanks so much for this excellent library.


  31. harry

    10 years ago

    Andrew,

    i have done the same i think using a basic stamp. after finding the sats 2 line elements u enter it into the code then the stamp lines up your ant displays info on monitor and keeps in line but with arduino more math is available and tracking is better but i have been able to find a code that works hope this helps i’m still trying to get tinygps++ to help me fine a high alt balloon so u know how much i know about arduino


  32. harry

    10 years ago

    Mikal,

    I study gps code and starting again. you said to use hardware serial i know u don’t have time to go into it where is a good starting place

    thanks


  33. Mikal

    10 years ago

    @Ryan Blace,

    It’s a good question.

    When TinyGPS++ starts up you can immediately query latitude and speed, but these contain invalid data (obviously). The isValid() flag on each object tells you that you should be suspect of the data when it returns false. As soon as the first sentence is parsed which correctly sets, say, the location, the isValid flag becomes true for that object, for eternity. That is, the object from then on always contains valid, if perhaps stale, data, that changes only when some new equally valid data arrives.

    On the other hand, isUpdated() is set each time new valid data arrives, but it’s *unset* when you actually begin to examine that data. It’s useful if you just want to check whether the latitude, say, has changed since the last time you processed it.

    Neither of these have anything to do with NMEA fix (void, etc.). The only way to tell that you have a fix is if the gps.sentencesWithFix() counter is non-zero and increasing.

    Lastly, querying .age() doesn’t reset anything.

    In your speedometer, are you just interested in the .speed.mph() query? If so, I think I would just put in my loop something like

    if (gps.speed.isUpdated())
      displaySpeed(gps.speed.mph());
    

  34. Mikal

    10 years ago

    @Stephen, I think I would use the Arduino Time library to perform this kind of manipulation.


  35. harry

    10 years ago

    do you have a break down of tinygpg++


  36. Magnus

    10 years ago

    Hi and thanks for an amazing library!
    I have a problem using custom object you might be able to help me with.

    I have declared this object:
    TinyGPSCustom head(gps, “IIHDG”, 1);

    Printing it like this works great:
    lcd.print(head.value());

    But when i want to assign the value to a variable:
    myBoat.cog=head.value(); // myBoat.cog is a uint32_t

    I get an error message:
    invalid conversion from ‘const char*’ to ‘uint32_t’

    What am i doing wrong?


  37. Magnus

    10 years ago

    solved it by uding atof() and atoi(). Sorry for the question.

    /Magnus


  38. mozan unal

    10 years ago

    Library does not work at baud rates higher than 9600. I have mt3329 any i want to parse its data but its default baud rate 38400 and send 5 different nmea sentences. Does my gps have to send only gga and rmc sentences ? I have tried lots of thing but when my gps lock, arduino stop sending data.Before locking i can take data but only “Invalid”. I use arduino mega 2560 and i use hardware and software serial (with correct pins:for software 10 11)


  39. jef

    10 years ago

    Thank you for a very well thought out and implemented library.
    I thought I would have lots of difficult coding to do to get my project going, but discovered you had done all the hard work, and in a very elegant way.

    Much appreciated.


  40. Electrophile

    10 years ago

    Hi, I tried using the TinyGPS++ library with a GPS module that I bought locally (GlobalTop’s FGPMMOPA6E or PA6E as its commonly referred to). No matter what I did I could not get it to work with the TinyGPS++ library. However, When I tried it with Adafruit’s GPS library it worked right away and I could see data being received from the module on the serial monitor. What am I doing wrong? Here is a link to the image of my setup,

    http://i41.tinypic.com/2n809dj.jpg


  41. Mikal

    10 years ago

    @Electrophile,

    If the Adafruit GPS library is working, then there is no wiring issue. It’s probably just a usage error with TinyGPS++. Are you running the examples?


  42. Peter

    10 years ago

    I am using TinyGPS++ and it works well for my application. However, I’d like to modify the code to output OziExplorer track records in CSV format. My big problem is that Ozi’s transfer file expects the latitude and longitude with no decimal places. Your “50.5390″ value for latitude should be written to the Ozi CSV file as a field containing “505390.” I know the number of significant digits can be controlled in TinyGPS by changing the value in the location.lat and location.lng functions. However, the result of lowering the significant digits value does not, of course, remove or move the decimal point.
    Is there a way to produce the desired result (a 6 digit degree + decimal fraction using Tiny GPS++ ??


  43. abay

    10 years ago

    @ Mikal,
    How can I use TinyGPS++ library on device “GPS/GPRS/GSM Module V3.0 (SKU:TEL0051)”, having trouble with creating a SoftwareSerial…

    Help needed ASAP, Thanks


  44. Ratheesh

    10 years ago

    I am using the new Arduinio version 1.05. Its showing an error like this
    “BasicExample:18: error: ‘TinyGPSPlus’ does not name a type”

    What may be the reason?


  45. Mikal

    10 years ago

    @abay, what’s the trouble?


  46. Mikal

    10 years ago

    @Ratheesh,

    Either your installation is defective or you did not #include . Make sure you have a TinyGPSPlus directory at the same level as, say, SoftwareSerial.


  47. Mike Leslie

    10 years ago

    I’m working with a system that changes the GPS sentences before I get to them, it changes the “GP” to an “II”.
    I created custom sentences for them (I have over 25 defined custom fields I pick out) and it all works very well but would like to use distance to etc, and was wondering if it would be as simple as changing the CPP file like this:

    #define _GPRMCterm “GPRMC”
    in the CPP file to
    #define _GPRMCterm “IIRMC”

    It seems too simple of a change to actually work, but I thought I’d ask,

    Mike


  48. Mikal

    10 years ago

    @Mike Leslie–

    I think that elegant modification would work great–as long as you never have any real GPRMC sentences. Nice!


  49. Alan

    10 years ago

    Mikal,

    Thanks after being a fan of the first version on the arduino, when I found that you’d done a c++ version I immediately tweaked…

    It’s running just fine on an STM32F3 with a MediaTek GPS attached… parsing data and feeding input to some simple satellite tracking code on the same processor.

    It really was a drop in for the most part, I had to fix up a couple of things that are arduino specific – sq is non-standard, radian and degrees, etc. But that was pretty easy to fix with some inline code. Because the F3 is an M4 core I used the single instruction math functions for sin/cos etc…

    Anyway excellent work and it works fine on another processor :
    Alan


  50. Mikal

    10 years ago

    Thanks Alan. I’m glad to hear it (almost) works right out of the box on such a different core. You’ve inspired me to remove the reliance on those homespun Arduino functions like sq() and radians(). As you say, they are easy to roll yourself. Don’t have an easy way to remove my reliance on millis() though. Ideas?

29 Trackbacks For This Post
  1. TinyGPS++ to the Rescue | Stainless Steelhead

    [...] to the brains behind Arduiniana, Mikal Hart, Poolbot has moved to the brand-new GPS library set, TinyGPS++.  This saved enormous time in developing custom code to process and check the validity of NMEA [...]

  2. Antenna tracker, first steps | kolin's

    [...] or none, I made simple arduino program for parsing NMEA crap and encoding it in LTM packets. I used TinyGPS++ library for parsing NMEA and few lines from TauLabs [...]

  3. GPS Ublox Neo-6M cu Arduino Uno | ArduHobby

    [...] Descarcati biblioteca tinyGPS sau tinyGPS++. [...]

  4. GPS-Logger | Pascal's Königreich

    [...] Card Breakout Board gibt’s bei Adafruit, um mit dem GPS Modul zu sprechen wurde die Library TinyGPS++ [...]

  5. GPS Distance Calculator (for golf) -Use Arduino for Projects

    [...] Tiny GPS++ [...]

  6. Arduino GPS with OLED Display | Home of Benty

    [...] OLED from Adafruit. It’s still a work in progress just squishing together code from the TinyGPS++ library and using the Adafruit GFX [...]

  7. SpainLabs - Mantener tus proyectos en hora

    [...] Con Arduino puedes usar la librería tyniGPS++. [...]

  8. Prototype 1 – GPS Module | A Mean Center

    [...] something useful with it. This isn’t due to any competence on my part, but because of  the TinyGPS++ library by Mikal Hart which is just amazing. There are many examples included with the library, so it is [...]

  9. Unexpected behavior of sprintf with i32/u32 | CL-UAT

    [...] trying to build a string of characters from several elements given by the TinyGPS++ library with the use of [...]

  10. Connecting u-blox NEO-6M GPS to Arduino | Big Dan the Blogging Man

    [...] http://arduiniana.org/libraries/tinygpsplus/ [...]

  11. LatLong to XY | Rocket Project

    [...] the same. latlon2xy is the doc with the Arduino code. Since I last looked at GPS, Mikal Hart has an updated GPS library that computes distanceBetween() and courseTo(). It might be worth pursuing. Share [...]

  12. با برد آردوینو و شیلد GPRS دستگاه ردیاب کوچک و کارآمد بسازید | رایانش نیوز

    [...] این کتابخانه را برای استفاده از برد GPS دانلود کنید. سپس کدهای [...]

  13. Shield GPS Ublox NEO-6M – Programación con Arduino MEGA 2560 – Tecno-fly C.A

    [...] http://arduiniana.org/libraries/tinygpsplus/ [...]

  14. Leyendo datos del GPS – OCEANO ABIERTO

    [...] Arduino que nos permite convertir esas cadenas de caracteres en valores fácilmente interpretables: TinyGPSplus. Tendremos que descargar el archivo .zip de la última versión e instalarlo manualmente en nuestro [...]

  15. Lightweight Module for Collecting Stratospheric Microbes | HENRY-1 HAB MISSION

    [...] RBBB was programmed with Arduino’s IDE and includes both the TinyGPS++ and Arduino Servo libraries. The TinyGPS library is very effective at parsing NMEA GPS data [...]

  16. How to make a GPS Speedometer? – DFRobot

    [...] following library ‘s in your Arduino Library Folder. U8glib – For the oled display. TinyGps++ – For the GPS. The code is “printing” the speed, course, number of satellites, [...]

  17. IoT WiFi Boat Monitor | Mechinations

    [...] Next, grab the starting source code. You will also need to install the TinyGPS++ library. [...]

  18. Adding Location to Microcontroller Projects: GPS Tutorial | Teach Me Micro

    [...] levels hence a voltage divider is needed to step down the voltage from the Arduino.You can use the TinyGPS++ library for easier Arduino GPS interfacing. Here's an example sketch from the library (modified to fit [...]

  19. Using Seeeduino LoRaWAN with GPS and Loriot.io – Squix – TechBlog

    [...] temperature and humidity we have to install two libraries. Download the TinyGpsPlus library from http://arduiniana.org/libraries/tinygpsplus/ Then install also the DHT library from Adafruit from the library manager in the Sketch > [...]

  20. GPS CLOCK with M5STACK | macsbug

    [...]  TinyGPS++ [...]

  21. Guide to NEO-6M GPS Module Arduino | Random Nerd Tutorials

    [...] to get information on location in a format that is useful and easy to understand. You can click here for more information about the TinyGPS++ [...]

  22. GPS With Arduino Tutorial | How To Interface GPS With Arduino using tiny gps++

    [...] Tiny GPS Library Download Table of Contents1 How to Interface GPS with Arduino Uno2 GPS  Arduino Code Display on Serial Monitor3 How to Display Longitude and Latitude on LCD3.1 16×2 LCD and Arduino Connection4 Arduino GPS LCD Code5 GPS Arduino Projects [...]

  23. GPS Tutorial–Sending GPS Coordinates over GSM | alselectro

    [...] http://arduiniana.org/libraries/tinygpsplus/ [...]

  24. GY-NEO6MV2 GPS Module – Mr. Robotrick

    [...] tiny GPS Module can connect to 4 Sattelite and it is pretty accurate. The library I use to interact with this module makes getting coordinates very easy., just add it to your [...]

  25. GPS Neo-6M com Arduino - Aprenda a usar - Blog Eletrogate

    [...] Biblioteca TinyGPS++ Avaliações: 5.0. de 1 voto. Por favor, aguarde…{"item":{"entity":"posts","name":"post","id":3185,"item_id":74,"nonce":"60e8e7599d"},"render":{"args":{"echo":false,"entity":"posts","name":"post","item_id":null,"id":3185,"method":"stars-rating","series":null},"method":{"disable_rating":false,"allow_super_admin":true,"allow_user_roles":["administrator","editor","author","contributor","subscriber"],"allow_visitor":true,"allow_author":false,"template":"default","alignment":"center","responsive":true,"distribution":"normalized","rating":"average","style_type":"font","style_name":"star","style_size":30,"font_color_empty":"#cccccc","font_color_current":"#ffcb05","font_color_active":"#ffd016","style_class":"","labels":["Pu00e9ssimo","Ruim","Bom","u00d3timo","Excelente"]}},"stars":{"max":5,"resolution":100,"responsive":true,"current":100,"char":"s","name":"star","size":30,"type":"font"},"labels":["Pu00e9ssimo","Ruim","Bom","u00d3timo","Excelente"]} [...]

  26. Wio LTEで遊んでみる(その5:3軸デジタル加速度センサーとGPS) | IT技術情報局

    [...] が、これだけだと読みにくい。 なので、上記のサイトをそのまま参考にTinyGPS++」を使用して読みやすくする。 [...]

  27. Cara Menggunakan GPS Ublox Neo 6M + Arduino – Coretan Aja

    [...] http://arduiniana.org/libraries/tinygpsplus/ http://geekistuff.blogspot.com/2014/06/advance-u-blox-neo-6m-gps-module.html Bagikan ini:TwitterFacebookGoogleSukai ini:Suka Memuat… [...]

  28. Using the GT-U7 GPS module based on u-blox 7th generation GPS chip – Pseudo Random

    [...] http://arduiniana.org/libraries/tinygpsplus/ [...]

  29. In-Depth: Interface ublox NEO-6M GPS Module with Arduino

    [...] to Mikal Hart for his great contribution. His website Arduiniana.org has a full overview of all of the capabilities of the TinyGPS++ [...]

Leave a Reply