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
434 Responses → “TinyGPS++”

  1. artem

    9 years ago

    Hi.
    Try to use your library.
    I receive from GPS:
    5245.94146 —- 05548.84800
    but your library converts it to:
    52.765663 —- 55.814132

    I need original GPS strings. How to get it? Make example please.


  2. Mikal

    9 years ago

    @artem,

    The original strings contain the latitude and longitude in degrees/minutes form, or more precisely, DDMM.MMMMM. The library converts the values to decimal degrees.

    Always remember that you control the GPS strings before you send them to TinyGPS++. If you want the raw GPS string, just save it yourself before you send it on to TinyGPS.


  3. Mikal

    9 years ago

    @KP. Perfect. Although I would use the integral constant 1000000UL instead of the function pow(10, 6), which is a floating point number.


  4. Ron Koval

    9 years ago

    Mikal,

    I have been trying to use TinyGPSCustom steerDirection(gps, “GPRMB, 3); to get the R and L from my Garmin GPS. Indeed R and L are read, but the GPS seems extremely slow to update, indicate a necessary change from R to L or L to R.

    I see I can extract “course” (which I assume is the equivalent to “Track” on the Garmin display, but is there a way to extract “Bearing” which is the goto heading? I would hope that these would update very quickly as I notice on the Garmin display.

    Thanks in advance to your reply.


  5. Ron Koval

    9 years ago

    Mikal,

    I asked too quickly. Bearing is the 11th field of the $GPRMB sentence. So using Bearing and Course, I can determine R and L and hopefully much quicker than my Garmin analyzes and updates it.


  6. KP

    9 years ago

    Mikal,

    Is there any specific reason I should avoid using the pow other than it is a floating point? What does 1000000UL do and why declare as such?

    Also if it is better or more effective, could I replace all my pow usage to XXXUL?


  7. Sergey

    9 years ago

    Hello Help me pls i made sketch to extract depth value from nmea sentence:

    #include
    #include
    #include “TM1637.h”
    #define CLK 2
    #define DIO 3
    TM1637 disp(CLK,DIO);

    static const int RXPin = 10, TXPin = 11;
    static const uint32_t GPSBaud = 4800;

    // The TinyGPS++ object
    TinyGPSPlus gps;

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

    TinyGPSCustom SDDPT(gps, “SDDPT”, 1); // $SDDPT sentence, 1 element

    void setup()
    {
    Serial.begin(4800);
    ss.begin(GPSBaud);

    disp.set(5);
    disp.init(D4056A);

    }

    void loop()
    {

    Serial.println(SDDPT.value());
    while (ss.available() > 0)
    gps.encode(ss.read());

    delay(20);
    }

    everything work fine but how can i extract numerical value of depth inside program to operate with it (i’m making downrigger)


  8. AlexTadeo

    9 years ago

    Hi mikal.
    I would like to know if ur library works with the gps A2235-H.


  9. Mikal

    9 years ago

    @Sergey, you should be able to add:

    long depth = atol(SDDPT.value());
    

  10. Mikal

    9 years ago

    @AlexTadeo,
    If that device uses the NMEA protocol, specifically GPGLL and GPRMC, I think it will work.


  11. Mitch

    9 years ago

    Thanks for this great library. It has saved countless hours on my Arduino based seven digit Nixie clock project. Timing is an issue here, I’m “feeding” for about 50ms for each loop. Then isValid() is checked until valid date and time data is available and if not, more feeding on the next loop. Baud rate for the GPS is 9600. The display is updated every 100ms now, but when I implement crossfading, display updating frequency will have to increase. Occasionally the display is interrupted by GPS data gathering. Is there a better way to do this? Thanks in advance.


  12. Brian

    8 years ago

    Silly question perhaps, but I decided to try TinyGPSPlus with a basic Arduino with 328P versus the Mega128 and custom ATmega128A boards I’ve been successfully using, but does TinyGPSPlus allow the use of the 328P hardware serial?

    The GPS data is mirrored to the serial monitor correctly, but the TinyGPS object does not seem to do anything!

    Oddly enough, even with a Mega128, if you feed it using Serial1 (second hardware serial), it works fine, but move it to Serial0 (first serial) you get nothing!

    Any ideas?


  13. Brian

    8 years ago

    Never mind the last question! ;) Stupid pinout diagram for the breakout shield has the RX/TX lines reversed! Doh!

    In any case, before figuring out the RX/TX swap, I optimized the code seeing how having 5(!) bytes of RAM left over is probably not a good thing in an ATmega328! It now has 321 bytes free, and works fine.


  14. MF

    7 years ago

    // Hello, Good day. Thank you so much for sharing this GPS module library.

    // my project aims to warn the driver with a voice message when the speed
    // reached 80 km/hr, and also sends information like latitude and longitude via
    // text message.

    // Initially, I did not put the voice alert function, just the text message
    // function. There was no problem with the GPS module getting a fix information
    // when it was connected to the Arduino UNO and GSM module, I did not use a
    // library for the GSM module. It was working fine by then. The values from the
    // GPS module are updated.

    // But when I wired the mp3 player module and included the DFPlayer_Mini_Mp3.h
    // library and its commands to my sketch, the voice alert was fine, the GSM
    // module sends a message to my phone but is not updated, just zero values from
    // the GPS module. ex. LAT: 000000,
    // LONG: 000000


  15. Paul Rowntree

    7 years ago

    Hi! Great package, it simplified my program quite a bit! Thank you very much!
    I am new to Arduino-land, and c-programming. Why do your examples use

    TinyGPSPlus.courseTo(… // from examples on this web page
    and
    TinyGPSPlus::courseTo(… // from some of the Example sketches

    instead of simply

    gps.courseTo( … // from my program, seems to work fine
    Cheers!


  16. surajit paul

    7 years ago

    hi, I’m using tinygpsplus library.I’m making a project “gps controlled rc car ” using ublox neo 6m gps sensor and hmc5883l compass. my problem is that when I connect the arduino with computer everything works fine and gets gps coordinate and compass heading bt when I disconnected usb and connect with 9v battery to arduino, the car does move. rx signal receiving and tx not indicating.when I connect with usb to arduino, the car moving. I’m also using hmc5883l library. and not using this function “while(!serial). in the loop I’m using “while(ss.available ()>o)”. what’s happening please help me


  17. Ben Mc

    7 years ago

    Hi Mikal,

    Thanks for your code. I have a question in regards to gps data sampling rate. The code outputs the sentences at 1 s increments by default, is it possible to access the data faster? I would like to get altitude data off my gps module at 10-100 hz.

    Thx for any help


  18. Mikal

    7 years ago

    @Ben Mc:

    The rate at which samples are delivered depends entirely on the hardware you choose. The EM-406a and EM-506 that I often use only deliver in 1Hz samples; there is no way to bump up the rate. Other devices can be configured to deliver samples at 10Hz, but this isn’t something that can be done in TinyGPS++.


  19. Mikal

    7 years ago

    @Paul Rowntree,

    When I’m using C++ “static” member functions I like to use the ClassName::MemberName() syntax instead of Object.MemberName() to illustrate that the member function is independent of any particular object.


  20. Mikal

    7 years ago

    @MF: You should probably switch to a Teensy or Mega or something that provides more than 1 Hardware Serial port.


  21. DM Rick

    7 years ago

    Thank you so much sir. I wasn’t sure from the remarks was if you were getting the bearing and distance to London from the GPS unit by sending it a waypoint or if you were doing the calculation in TinyGPS++. My GPS unit (NEO-6M) doesn’t seem to take waypoints or produce RMB so I a super glad to find your TinyGPS++ does that work. What a find. You really have saved me as little sailboat and I were to leave a month ago but wanted to work out at least an auto steering system. Now I will have a much better system where I changed London to WayPoint and feed Lat/Lon to where I want to go. The Cross Track Error I can work out.
    This is amazing. Thank you.


  22. Rick

    7 years ago

    The more I use it the more I like it. Only thing is I still don’t fully understand it and just modified the example to get the info I needed out of the NEO-6M. It seems to run thru the void loop just once per second. I kicked up the data transfer rate of NEO and Uno (Softwareserial) to 57,600 and dropped out all but GGA and RMC from NEO but still loops about once per second. My fix is just adding another Uno for keypad and rudder control. Solves pin count problem too. I should be able to transfer the data I2C. I have plenty of boards but since I also name them (Adam, Eve, Max) I’m running out of names :)
    Thanks for writing this gem


  23. Jeferson

    7 years ago

    What type of licence tinygpsplus is under? Can I use on my drones and wings?


  24. Michele

    7 years ago

    Hi!
    I’m facing a very very strange problem…
    All the TinyGPSPlus examples works ok…
    A sketch of mine that does not use TinyGPSPlus works ok…

    If in my sketch i simply add

    #include
    TinyGPSPlus gps;

    The sketch does not work anymore (cannot find a way to debug this problem).

    My sketch is using the library JTEncode and the function that “hang” is jt65_encode of that library.

    I’ve no idea of what the statement “TinyGPSPlus gps;” does…but if i comment it, everything works ok.

    Any idea?

    PS: I’ve written to the developer of JTEncode, i’m waiting for an answer from him too.

    PLEASE, an help would be really appreciated.

    Michele


  25. Mikal

    7 years ago

    @Michele, if your program breaks when you added only the definition of the gps variable, then my guess is that you have run out of some resource (memory or flash space).


  26. Mikal

    7 years ago

    No problem @Jeferson. It’s licensed under LGPL. Let us know how it works out.


  27. Mikal

    7 years ago

    @Rick, I think one problem might be that SoftwareSerial can get unreliable at speeds greater than 19.2 or 38.4K.

    I think the NEO-6M refreshes at 5Hz. TinyGPS++ itself has no internal limit beyond just the processing power of the underlying CPU. Subject to that it will process characters as fast as the GPS module generates them.


  28. JP_Austin

    7 years ago

    Mikal, great library. I have been using it in an ESP8266 project and experiencing some issues with the distanceBetween function. I have essentially the same LAT and LON values defined as my HOME location and when I exercise the function to determine how far from home it reports an error of about 10KM. Am I doping something odd or is it something with the ESP8266 and how it compiles the code?

    Only thing I could find remotely close to the error is from this Particle post. Similar issue was being reported.

    https://community.particle.io/t/tinygps-distancebetween-calculates-wrong-distance/20557

    I use the function like this:

    unsigned long Distance_To_Home = (unsigned long)TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),Home_LAT, Home_LNG);
    display.print(“KM to Home: “); // Have TinyGPS Calculate distance to home and display it
    display.println(Distance_To_Home);


  29. Mikal

    7 years ago

    Hi @JP_Austin.

    I don’t think you’re experiencing the same thing reported on the particle.io site.

    You realize, right, that distanceBetween() returns distance in meters, not in kilometers? Assuming so, can you give me some more detail? What number were you expecting and what number did you get? It would be useful if you could give me (approximate) values for bot lat/long pairs.


  30. JP_Austin

    7 years ago

    Face palm –> Meters and not KM! OK now I do feel stupid. I had loaded an example provided and it was reporting the value as KM. I didn’t scrub the documentation well enough to realize your library was reporting the distance in meters. Lesson learned – don’t pick up examples and report issues unless you really know the said example is clean.


  31. Rick

    7 years ago

    Mikal, Thanks. You are exactly correct. I dropped GPS transfer speed back down in steps from 57600 to 19200 and it became stable again. Of course being as I am I then dropped it to 9600 just to be sure. Still plenty fast enough at 1 Hz samples to drive a sailboat :)

    I’m still a little confused about which is newer, TinyGPS++ or TinyGPS13. I was having trouble with the count of satellites on I2C driven 20×4 LCD so rewrote it all using v.13 library and working ok so far.


  32. JIM_COLORADO

    7 years ago

    Mikal,

    TinyGPS++ is great in most of my Arduino sketches. Thanks for writing it.

    However, I am trying to run your sketch “SatelliteTracker.ino” which I got from GitHub. I’m using an Adafruit GPS Logger shield with an Arduino UNO. I changed the RXPin and TXPin numbers to 8 and 7, respectively, and I changed the GPSBaud statement to “static const uint32_t GPSBaud = 9600;” The sketch compiles OK and runs down through the Serial.println statements in the void setup. I don’t get any output after that. Do you have any suggestions? Thanks.

    Jim


  33. Herve

    7 years ago

    Hi,
    I’m very please using TinyGPS++.
    Just one thing, I want to update the arduino time ONLY if date and time are valid (for datalogger, so I block my sketch waiting for these conditions to be valid) …. but that doesn’t work as expected.

    I’m using: if (gps.date.isValid() && gps.time.isValid()) ….

    even if the GPS replies a “false date” (2000/01/01) TinyGPS++ consider them as valid.

    Is there any solution to change that behaviour ?

    Many thanks in advance
    best regards … and thanks again for the good work !


  34. Mikal

    7 years ago

    @Herve,

    Yes, it’s a little confusing, but the “isValid()” method on date and time is simply the library reporting that at least one NMEA stream that could contain a date or time has been parsed. Would you suggest a different algorithm? I’ll think about this.

    M


  35. Mikal

    7 years ago

    @Jim–It’s easy to get the wiring backwards. Usually (but not always!) you connect TX to RX and RX to TX.


  36. Tony

    7 years ago

    Hands down the best library out there for Arduino. It’s simple plug and play, I couldn’t ask for more!
    At first I thought it didn’t work though, because a new GPS has a very long cold start and I feel like this is not stressed enough. Nothing to do with the lib, just my experience in general with these things!


  37. Ron Koval

    7 years ago

    What is the operational difference that I see in the above TinyGPS++ instructions:

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

    and

    library FullExample:

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

    ?


  38. Damien

    7 years ago

    Hi!
    First of all, thank you for your libraries. This is really great!
    I am using two ublox neo6m v2, that I manage to talk with with TinyGPS and TinyGPS++, except that I cannot retrieve the date (I get a ‘0’ value). While investigating, I found that the case COMBINE(GPS_SENTENCE_GPRMC, 9): // Date (GPRMC) from the library was actually never used (a Serial.println(“test”) gives nothing here, but prints for other cases).
    Has anyone experienced the same, or has a clue of what happens (or does not happen)?
    Many thanks,
    Damien


  39. Thomas Kjeldsen

    7 years ago

    Hi
    im trying to do a read out to a display(nokia 5110) but i only get 0 or strange numbers

    here is my code

    ;
    a = (gps.speed.kmph());
    sprintf(kmt, "%d", a);
    display.setTextSize(1);
    set_text(1,18,"Speed:",BLACK);
    set_text(40,18,kmt,BLACK);

    char retning[8];
    a = (gps.course.deg());
    sprintf(retning, "%d", a);
    display.setTextSize(1);
    set_text(1,27,"Course:",BLACK);
    set_text(40,27,kmt,BLACK);

    char longt[32];
    a = (gps.location.lng());
    sprintf(longt, "%d", a);
    display.setTextSize(1);
    set_text(1,36,longt,BLACK);

    char lati[32];
    a = (gps.location.lat());
    a = (a);
    sprintf(lati, "%d", a);
    display.setTextSize(1);
    set_text(1,45,lati,BLACK);
    Serial.println(a);

    char dato[32];
    d = gps.date.value();
    sprintf(dato, "%d", d);
    display.setTextSize(1);
    set_text(14,0,dato,BLACK);

    char tid[32];
    d = gps.time.value();
    sprintf(tid, "%d", d);
    display.setTextSize(1);
    set_text(20,9,tid,BLACK);

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

    if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
    }

    // This custom version of delay() ensures that the gps object
    // is being "fed".
    static void smartDelay(unsigned long ms)
    {
    unsigned long start = millis();
    do
    {
    while (ss.available())
    gps.encode(ss.read());
    } while (millis() – start < ms);
    }
    void set_text(int x,int y,String text,int color){

    display.setTextColor(color); // Textfarbe setzen, also Schwarz oder Weiss
    display.setCursor(x,y); // Startpunkt-Position des Textes
    display.println(text); // Textzeile ausgeben
    display.display(); // Display aktualisieren
    }


  40. Leo Megliola

    7 years ago

    Autonomous kayak using TinyGPS++, see https://youtu.be/9v6JTt4jLEg


  41. Thomas Michalak

    7 years ago

    Hi,

    First of all, it’s a brilliant library, really easy to use, versatile and got me up and running in no time.

    I have one question. I was driving around with my breadboard on the passenger seat (testing my project), everything was fine but, just once, the Lat and Lon jumped to North Africa (I’m in the UK). I looks like the decimal point shifted on the lat from 50.8376420 to 5.0837642 and Lon went from negative to positive.

    Does that sound familiar?

    I’m thinking of writing something to ignore those jumps but I though it might be worth asking first. I haven’t used isValid() so maybe that will do it.

    Cheers


  42. dudu

    7 years ago

    hey Mikal! thank u for the library but I’ve been wondering if in this code there is a way you can add how to give command to arduino due to the coordinates given by GPS???
    for example when GPS reach this coordites….. do this…??

    thank you


  43. Todd

    6 years ago

    Works beautifully! Thanks.

7 Trackbacks For This Post
  1. با برد آردوینو و شیلد GPRS دستگاه ردیاب کوچک و کارآمد بسازید | رایانش نیوز

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

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

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

  3. 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 […]

  4. 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 […]

  5. 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, […]

  6. IoT WiFi Boat Monitor | Mechinations

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

  7. 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 […]

Leave a Reply