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. Stanley

    9 years ago

    Dear Mikal,

    I’ve figure out a way to decode BeiDou GPS receiver … I took yr code and only change the 2 defines from GP to GN..

    #define _GPRMCterm “GNRMC”
    #define _GPGGAterm “GNGGA”

    There is an extra NMEA sentences called BDGSA similar to BDGSA to check for DOP & active Sats , add both the Sats up would give the total Sats in view…

    Could you add this BeiDou support to your next version release ?

    Thanks in advance..


  2. Dave

    9 years ago

    Hello,

    Is it possible to turn al LED on when there is a fix and an other when there is no fix?
    Tried couple of things, but don’t work…

    Thanks!


  3. Fredrik

    9 years ago

    Thanks for the really beautiful and simple impl. of this library!

    I’m using the Adafruit Ultimate GPS module and is trying to parse out altitude and hdop values. But both end up beeing zero all the time. My module does seem to be supporting those NMEA strings… Any tips on what could be wrong? Also lacking a few decimal to get accurate position.

    Thanks!
    Fredrik


  4. Mikal

    9 years ago

    @Fredrik,

    1. It’s possible that you are losing some data due to overflow?
    2. Serial.print(lat, 6). Add the second parameter to print with greater resolution.


  5. Mikal

    9 years ago

    @Dave,

    Sure it’s possible. I look at the age() of, say, the location object. If it’s greater than a couple of seconds you probably don’t have a fix. What have you tried?


  6. Arion

    9 years ago

    Mikal,

    Hi. Thank you for the library. Does the function “distanceBetween” calculate distance to another lat/lon location using the curvature of the earth calculations? Thanks!


  7. Chris

    9 years ago

    Used tinyGPS and now plus, with a uBlox NEO 6M successfully (got the data i wanted flawlessly). Now i’m trying to use uBlox LEA 6H from 3drobotics (Ardupilot 2.6). They have configured it for UBX data, but i managed to change the output to NMEA only.
    All i get is this (increasing Chars and Passed)
    DIAGS Chars=6560 Sentences-with-Fix=0 Failed-checksum=0 Passed-checksum=103
    I’ve waited for over an hour and still getting this.
    Using u-center (uBlox software) the LEA 6H locks after a minute (2′ tops).


  8. Yaron

    9 years ago

    Hi Mikal,
    First of all, the Tinygps is superb! It works great! Well done!
    I’m using a up501 gps module connected to Serial2 on my Arduino Mega 2560.
    Is there a way to get the gps to get a fix, and then restart it to get a new fix without turning anything off?
    I want my arduino to get gps fix data, do some other stuff for a few minutes, and then get a new gps fix and the old fix data to be erased.
    Is that possible?
    Thanks for your help!
    Yaron


  9. Thor Valø

    9 years ago

    /*
    GPS_Tiny
    Consistent read of GPS serial
    Created 17.10.2014
    By Thor Valo
    */

    #include “TinyGPS++.h” // http://arduiniana.org/libraries/tinygpsplus/

    #include ; // required for virtual RX, TX

    TinyGPSPlus gps;
    SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)

    const int serialTime = 100; // enough time to read all NMEA sentences once

    void setup()
    {
    Serial.begin(115200);
    gpsSerial.begin(9600);
    } // end setup

    void loop()
    {
    int start = millis(); // reference for starting timestamp
    int now = millis();

    do {
    while (gpsSerial.available() > 0) {
    gps.encode(gpsSerial.read());
    }
    now = millis();
    } while ((now – start < serialTime)); // breaks out of read gps serial

    if (gps.location.isUpdated())
    {
    Serial.print("Lat: "); Serial.println(gps.location.lat(), 6);
    Serial.print("Lng: "); Serial.println(gps.location.lng(), 6);
    }

    if (gps.altitude.isUpdated()) {
    Serial.print("Alt: "); Serial.println(gps.altitude.meters());
    }
    } // end main loop()


  10. alessandro

    9 years ago

    Dear Mikal you have done a great work! I am pretty sure I will use it in my next gps project. This is my first time I play with gps and I need more accuracy than 2.5 meters provided from all gps shields. Someone told me it can be improved calibrating the gps, I checked on internet but no luck. Do you have any library to suggest or any useful information about it?

    Thank you for sharing!
    Alessandro


  11. Stefan

    9 years ago

    Hi Mikal! I’m trying to use version 13 TinyGPS.h, and I had trouble reading the data (data not printing), however I do the same with the V.12 version and if I print the data correctly (using test_with_gps_device). I have tried using the library TinyGPSPlus.h but neither works. the gps is working but does not show me any data (CHARS = 0 = 0 CSUM SENTENCES ERR = 0
    No characters ** received from GPS: check wiring **
      CHARS = 0 = 0 CSUM SENTENCES ERR = 0
    ). I have an Arduino UNO and GPS VPN1513. You have any idea what it could be?


  12. Juan Domingo

    9 years ago

    Hey there!

    First of all, I would like to thank you, Mikal, for sharing TinyGPS++. It’s awesome. Definitely, a piece of well done work.

    I have just spotted why my code wasn’t working perfectly OK with TinyGPS++ lib and I have thought it might be useful to other users or even a nice contribution to a new version of the lib.

    My GNSS device was outputting good data (I checked it by bypassing it through serial) but when at building and printing my propietary frame, I couldn’t get proper values for location.lat(), lng(), kmph(), gps time functions… GPS time suddenly freezed, and lat and lng kept outputting 0 after receiveng data fixes with such information.

    I was about going mad, thoroughly reviewing Mikal’s code, trying to understand what was happening “behind the scenes”. And then… I stopped over the word “_GPRMCterm” and the penny dropped.

    I’m currently working with GNS701, a GPS+GLONASS device. The thing is that when it receives GPS data, it outputs some $GP— frames; when it receives GLONASS data, it outputs some GL— frames; and when it combines both, it outputs some GN— frames. Therefore, you can have both GPGSV and GLGSV frames printed, or GNRMC instead of GPRMC.

    That last one case gave me a hard time. When the RMC frame outputted was the GPS RMC frame, things went reasonably well, as the lib was able to parse it with the encode function. But as soon as a better GPS/GLONASS signal was received, GNRMC frame was obtained. Thus, no further encoding was done.

    I fixed it defining GNRMC header in TinyGPSPlus.cpp

    #define _GPRMCterm “GPRMC”
    #define _GNRMCterm “GNRMC” //ADDED!!

    and matching GNRMC frames to GPRMC parsing (this is a bit twisted, bad practice, I know, but it works for GNRMC frame by now) in line 212

    if (!strcmp(term, _GPRMCterm) || !strcmp(term, _GNRMCterm)) //MODIFIED!!
    curSentenceType = GPS_SENTENCE_GPRMC;

    Adding GPS/GLONASS support should be quite easy. Just needs defining the headers and some extra clauses in switch-case structures (and things like that). So maybe, it’s an interesting feature to include in a new lib version release. I volunteer to help. Please, contact me if so.

    Regards,
    Juan


  13. Pete

    9 years ago

    thsnks for the great software
    Just one question/ remark
    It would be great if minute and seconds are formatted 00-59
    instead of
    Serial.println(gps.time.minute()); // Minute (0-59) (u8)
    Serial.println(gps.time.second()); // Second (0-59) (u8)

    Is there a simple code to achieve this?


  14. Mikal

    9 years ago

    @Arion,

    I didn’t write the distanceBetween function, but I’m pretty sure that it does account for curvature. That is, I doubt whether the distance from New York to Moscow is calculated along the straight line through the center of the earth. It surely is the great circle.


  15. Mikal

    9 years ago

    @Chris, can you dump the raw data that your device is sending? Try Serial.write(c) for each c that comes from the device.


  16. Mikal

    9 years ago

    @Yaron, sorry for the slow reply.

    Yes! Do this C++ trick when you want to reset your TinyGPS[++] object:

    TinyGPSPlus gps;
    ...
    gps = TinyGPSPlus(); // reinitialize
    

  17. Mikal

    9 years ago

    @alessandro, I’ve never heard of any way to calibrate your ordinary over-the-counter GPS modules. Sorry!


  18. Mikal

    9 years ago

    @Stefan, the method for acquiring data from the GPS module didn’t change, so if you’re getting “No characters received”, I feel pretty sure that you are not using the right port or the correct software serial pins. Can you check to make sure they are the same as in the v12 sketch that’s working?


  19. Mikal

    9 years ago

    @Juan Domingo,

    Thank you very much for that clear explanation. I think I will have to incorporate this GLONASS stuff in the near future, and you have helped me figure out how to do it. Thanks


  20. Mikal

    9 years ago

    @Pete,

    Yeah, the Arduino printing facility is (necessarily) quite limited. What I end up doing is something like:

    if (gps.time.minute() < 10)
       Serial.print("0");
    Serial.println(gps.time.minute());
    

  21. Yaron

    9 years ago

    Hi Mikal,

    Thanks for the reply. I’ll give it a try!

    I also wanted to know if there’s a way to turn the gps off thru the software alone?
    My up501 gps module is connected directly to the 5V pin on the arduino mega and i want it to turn on once every 15 minutes, get valid data, and than turn off again. Is that possible by code?

    Thank you


  22. Jay

    9 years ago

    Hi Mikal,

    Thanks for the excellent TinyGPSplus library ! Just wondered if there is a feature to do a rolling average of the position latitude and longitude, over a specified number of readings to get a stable position. The number of readings could be variable to either speed up or slow down the response. Thanks!


  23. user

    9 years ago

    Is it also possible to use the tinyGPS++ with hardware serial port?
    and how?


  24. Mikal

    9 years ago

    @Jay, that rolling average feature would be useful, but I don’t think it’s quite compelling enough to put into the library. I can see that it would compensate for any minor inaccuracies, but another way to do this is to examine the number of satellites, and generate position data only when there are at least, say, 6 satellites being used.


  25. Mikal

    9 years ago

    @user,

    Yes, it’s pretty easy. Basically you just replace all the “ss” in the examples with “Serial” or “Serial1″.


  26. Jay

    9 years ago

    Thanks for the reply. I tried to implement a rolling/ smoothing code, but it seems that I can’t pick up the data that the TinyGPS++ extracts.

    For example (based on Arduino smoothing example):

    TinyGPSCustom rawlat (gps, “GPGGA”, 2); // extract raw Lat
    .
    .
    .
    void loop() {

    total= total – readings[readIndex]; // subtract the last reading:

    readings[readIndex] = rawlat; //read in extracted rawlat reading = numReadings) // if we’re at the end of the array…

    readIndex = 0; // …wrap around to the beginning:

    average = total / numReadings; // calculate the average:

    Serial.println(average); // print the average

    So trying to use rawlat doesn’t work ! Compilation error. Any suggestions/ help much appreciated!! Many thanks!


  27. Practical_Pirate

    9 years ago

    Thought you would like to be aware of an open source marine data
    infrastructure (NMEA etc.) consortium that is coalescing on Github/google groups.

    The base website is http://www.SignalK.com . A good
    article from Bill Bishop on Panbo: http://www.panbo.com/archives/2014/11/signal_k_a_true_game_changer_.html

    Some of the conversation on google groups is focused on navigation and
    crowdsourced data and your expertise at fiddling and inventiveness suggest to me you might be able (and willing) to contribute to the conversation.


  28. Nikos

    9 years ago

    Hi Mikal..Thank you for your great work.
    I’m runing your library in a NEOV2 Gps like this one

    http://www.ebay.com/itm/Ublox-NEO-6M-V2-GPS-Module-Aircraft-Flight-Controller-For-Arduino-MWC-IMU-APM2-/321598638877?pt=LH_DefaultDomain_2&hash=item4ae0c5cb1d

    but i’m taking Checksum fail errors..
    4 OR 5 in every loop when runing the FullExample.

    Any idea why ?

    Thank you once again.


  29. Mikal

    9 years ago

    @Nikos, what’s the baud rate on that device?


  30. Rob

    9 years ago

    Mikal – Just wanted to thank you for all your effort on this. The TinyGPS library was great, but I think you’ve managed to make it better with TinyGPS++! I’m using it on an E-Traxx based robot and it works great. Thank you again.


  31. Mikal

    9 years ago

    @Rob, hey thanks for the nice words.


  32. Arion

    9 years ago

    Mikal,

    Thanks for the previous reply. I have another question. I am trying to get the GPGSV satellite data using TinyGPSCustom objects. There are usually multiple sentences starting with $GPGSV depending on the number of satellites. I cannot read each sentence individually with my custom objects.
    TinyGPSCustom messageNumber1(gps, “GPGSV”, 2);
    TinyGPSCustom messageNumber2(gps, “GPGSV”, 2);
    TinyGPSCustom messageNumber3(gps, “GPGSV”, 2);

    All I get is the last sentence value every time. For example, if there are 3 GPGSV sentences, I get 3 each time instead of 1, 2, 3. I am using the second parameter for now as I am just trying to get the sentences separated so I can read them individually. My goal is to create a visual representation of where the satellites are in the sky using the elevation and azimuth data from these sentences (like the view in this link http://www.ka2ddo.org/ka2ddo/YAACdocs/viewgps.html). Any help would be greatly appreciated. Thanks again!

    Arion


  33. christian

    9 years ago

    Hey Mikal,

    Thanks for sharing the Library. I have a question about the course_to feature of the TinyGPS, sometimes it gives me the right degrees, and sometimes it doesn’t. Any inputs as to why this happens?

    Regards


  34. Craig Swanson

    9 years ago

    In one comment it was said that a Due or processor which can take advantage of the higher precision of 64-bit “double” floating-point is needed for TinyGPS+. Were you refering to hard or soft float? Im only asking because im not seeing any mention of an fpu in these arduino chips. Im interested in using this on a mips based soc but knowing if this is hard or soft float is important. Thank you ever so much

    Craig


  35. MPCadosch

    9 years ago

    @Mikal and @Chris, did you ever figure out how to use it with the uBlox LEA?

    Thanks!


  36. sv650s

    9 years ago

    Hi,
    i try to take latitude, longitude, altitude and satellites number but for the 2 last this doesn’t work ….
    the values are at 0 for altitude and satellites….
    i have an arduino mega 2560 with a GPS U-Blox-7N
    i have already imported the TinyGPSPlus in my arduino
    this is my code :

    #include
    #include

    static const int RXPin = 12, TXPin = 11;
    static const uint32_t GPSBaud = 9600;

    // The TinyGPS++ object
    TinyGPSPlus gps;

    // The serial connection to the GPS device
    SoftwareSerial ss(RXPin, TXPin);

    void setup()
    {
    Serial.begin(115200);
    ss.begin(GPSBaud);
    }

    void loop()
    {
    while (ss.available() > 0)
    if (gps.encode(ss.read()))
    displayInfo();

    if (millis() > 5000 && gps.charsProcessed() < 10)
    {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
    }
    }

    void displayInfo()
    {

    if (gps.location.isValid())
    {
    Serial.print(F("Location: "));
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
    Serial.print(F(","));
    Serial.print(F("Altitude: "));
    Serial.println(gps.altitude.meters());
    Serial.print(F(","));
    Serial.print(F("Satellites: "));
    Serial.print(gps.satellites.value());
    }
    else
    {
    Serial.print(F("INVALID"));
    }

    Serial.println();
    }


  37. Ahmad

    9 years ago

    Hi Mikal,

    I had a GPS module GP 635T connected to Arduino Uno on pin 3,2.

    I used the following program:
    [...]

    I works perfectly when I walk.
    But it doesn't work when I tried to test it in the car.

    Any Recommend?


  38. Mikal

    9 years ago

    @Craig Swanson,

    I don’t think that that comment was referring to how the floating point calculations were performed, i.e. in hardware vs. microcode vs. software emulation, just that on many modern microcontrollers the precision is much higher–64 vs. 32 bits. The original TinyGPS didn’t make use of double, so couldn’t take advantage of the higher precision offered by these controllers.


  39. Mikal

    9 years ago

    @sv650s, could you reproduce a short 10-15 line sample of the stream coming in on the serial port?


  40. Mikal

    9 years ago

    @Ahmad,

    What kind of problems are you having?


  41. David

    9 years ago

    I am trying out the new library TinyGPS++ for a telemetry project, and I have begun with “BasicExample.” I wanted to see what would trigger errors, so tried changing one character at a time in various gpsStream fields, but I never got the “INVALID” msg; the only effect was that the string wouldn’t print. I realize a single character change would generate a checksum error, but that isn’t an error case in this demo… so what would be a printable string but an INVALID time for example?

    Also, is there a configuration option to parse the msg but ignore the CRC?


  42. Beat

    9 years ago

    Hi Mikal,
    I am not sure, but the validity of custom sentence is always true?
    $IIMWV,338.0,R,044.0,M,V*21 flags void.

    TinyGPSCustom wind_dir(gps, “IIMWV”, 1);
    TinyGPSCustom wind_speed(gps, “IIMWV”, 3);

    (wind_speed.isValid()) is always ok.
    Now i handle it as custom field itself.
    TinyGPSCustom wind_valid(gps, “IIMWV”, 5);


  43. Beat

    9 years ago

    Upps, found it in the for me not relevant “Establishing a fix” Section (Because i use no GPS)

    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).

    But Maybe this could be configurable too..?


  44. Gilles

    9 years ago

    Ni Mikal,
    I need a clarification :
    Arduino Uno doubles and/or floats have an accuracy of 6 or 7 digits and many people say that this is generating a large error.

    Do your library is doing something to alleviate the problem ?

    Thanks a lot for sharing your knowledge on this !


  45. TommiP

    9 years ago

    Hi all

    Does this work with 1.0.6 ?
    I’ve tried quite many times to install library to the Arduino libray folder and treid to copy .cpp and .h -files quity many place but it keep saying that “BasicExample:26: error: ‘TinyGPSPlus’ has not been declared”

    BR
    TommiP


  46. Pete B

    9 years ago

    Question. What’s the best way to determine that GPS has a fix with this code? I like the interface better with this, but the Adafruit GPS includes a fix variable that can be checked which allows me to loop for a while until a fix is obtained. Is there a good mechanism to understand when a fix is obtained?

    Thanks, this is really great stuff.


  47. flydr2

    9 years ago

    Thanks for all the hard work… I’ve managed to develop an autopilot for my experimental aircraft (Thorp T-18) using your library.

    I’m using an arduino due and it controls my trim tabs.. It works great but without your lib I would not have had it perfected to full navigation.. It would have followed only a compass.

    Now it take gps data from hard wired neo 6m and my Android tablet/cell phone via bluetooth as well Lowrance GPS…

    Thanks again!


  48. Costin

    9 years ago

    Hi,Mikal..
    I’m using an ATMEGA board with the gps on Serial1. I’m updating once a week a DS3231 clock, but there’s a strange problem. When the update occurs, the date and time transferred in the DS3231 are the ones from the last reset of the entire board, instead the actual ones.I’m using the isValid query before writing the DS3231.How can I flush the buffer after a reading so to get reals date and time or which function to use from GPS++ ?
    Cheers,
    Costin


  49. Jay Be

    9 years ago

    hi mikal,
    thanks for your great library!
    i’m using it with an u-blox neo-6m module and it works, BUT
    i dont get the GPGGA information like sats, hdop and altitude…

    if i’m using a terminal program with the gps module directly, i get all information from $GPGSV, $GPGLL, $GPRMC, $GPVTG, %GPGGA and $GPGSA.

    my baudrate is 9600. any suggestions?
    thanks!


  50. Mikal

    9 years ago

    @David–

    There isn’t any code that prints “INVALID” in the BasicExample. TinyGPSPlus::encode() returns true when it successfully parses a sentence with the correct checksum.

    No, there isn’t any provision for ignoring the checksum. Can you think of a time when it might be useful? Is there ever a scenario where you could get a bad checksum but still trust that the data is correct?

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