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

  1. Mr.Sensor

    6 years ago

    @Mikal, thanks a lot for your reply. My fault was that the module i used updated the time every second, as a result centiseconds were always 00. Is there any chance, that your library could also report milliseconds even though my gps updates only with a frequency of 10Hz? For example using centiseconds or better said the time between two centiseconds and splitting them up to be more accurate…

    Regards,

    Mr. Sensor


  2. Mikal

    6 years ago

    @Mr.Sensor, I think it’s pretty reasonable to say that TinyGPS++’s job is to simply report the data provided by the GPS module in human-readable form. I’m very reluctant to modify that basic premise.


  3. Filippo

    6 years ago

    Hi Mikal,

    first of all thanks for sharing your library. I have a problem, I have a problem, I want to put the latitude value in a variable but i don’t work.
    Here my program:

    Serial.println(“Latitude= “); // It works
    Serial.println(gps.location.lat(), 6); //It works

    double temp_lat = (gps.location.lat(), 6);

    Serial.println(temp_lat); // It doesen’t work.

    Please, could you tell me what there is of wrong?
    Thanks
    Filippo


  4. Mikal

    6 years ago

    @Filippo

    double temp_lat = gps.location.lat();
    Serial.println(temp_lat, 6);


  5. Mike Morrow

    6 years ago

    Using this: TinyGPSCustom GSATest(gps, “GNGSA”, 1); // $GNGSA sentence, first element

    then this: if (GSATest.isUpdated()) {

    It is always on. After every single character from the GPS, it fires again. It is never off. I want to catch GNGSA statements and pick up the number of sats used in the solution. There are two of these in each block (one for GPS, one for GLONASS). I need to get control on each of them but it is not working that way. It is always firing!

    Is there something else I need to do?


  6. Mike Morrow

    6 years ago

    Having a problem trying to get numbers from GNGSA statements. I need to get all 12 of the in-use slots from 2 of these statements that come one after the other. Trouble is, with the Custom statements coded:

    TinyGPSCustom GSATest(gps, “GNGSA”, 1); // $GNGSA sentence, first element

    the

    if (GSATest.isUpdated()) {

    statement fires EVERY character coming from the GPS. The others seem to be performing properly.

    TinyGPSCustom satsInViewP(gps, “GPGSV”, 3);

    and

    TinyGPSCustom satsInViewL(gps, “GLGSV”, 3);

    I only want it to fire once per GNGSA statement, obviously. Is there something else I should be doing to read the GNGSA statements? The GPS I am using does not emit GPGSA at all, but two GNGSA statements. I need to get access to both and total up the in-use sats since this is not available anywhere I can find. In view is available from the GPGSV and GLGSV statements. I add these together for the total in vies sats. Just need GNGSA to operate properly.

    Thanks for a nice library.

    Mike


  7. Mikal

    6 years ago

    @Mike Morrow,

    When you retrieve the value of your GSATest custom object, are you using value() every time? The “updated” flag is cleared every time you retrieve the value using this technique.

    (code)
    const char *value() { updated = false; return buffer; }

    Mikal


  8. Mike Morrow

    6 years ago

    TinyGPSCustom GSATest(gps, “GNGSA”, 15);

    if (GSATest.isUpdated()) {
    Serial.print(millis());
    Serial.println(” – pdop updated.”);
    }

    From one of your examples. This pops every 2 ms. That is not possible. Yes, GNGSA. When it is set to GPGSA it does not pop at all. And, at least, that part is correct since I don’t get GPGSA. I get GNGSA and I want to read the details of them. Can’t I get an answer from someone? I have written in 2 places and get no answers.


  9. Mikal

    6 years ago

    @Mike Morrow,

    Per my answer from 4 days ago, the “updated” flag is only cleared when you actually retrieve the value with the “value()” method. The code you quote, which incidentally is not from one of my examples, simply reports on the state of the updated flag.


  10. Mike Morrow

    6 years ago

    I have figured out how to cause and (sorta) solve the problem (for me, at least, but not solving it in the general case).

    Higher on this page, the documentation says “isUpdated() indicates whether the object’s value has been updated (not necessarily changed) since the last time you queried it”. Pretty straightforward.

    That implies that the is-updated flag will be reset when it is checked and stay reset until the firing action occurs once again. Seems like correct operation to me. But that is not how it is working.

    Coded:
    TinyGPSCustom pdop(gps, “GNGSA”, 15); // $GPGSA sentence, 15th element
    TinyGPSCustom hdop(gps, “GNGSA”, 16); // $GPGSA sentence, 16th element
    TinyGPSCustom vdop(gps, “GNGSA”, 17); // $GPGSA sentence, 17th element

    So, when I do this:

    void loop() {
    if (pdop.isUpdated())
    {
    Serial.print(millis());
    Serial.println(” – pdop updated.”);
    // Serial.print(F(“, PDOP=”)); Serial.print(pdop.value()); // line 1
    // Serial.print(F(“, HDOP=”)); Serial.print(hdop.value()); // line 2
    // int i = int(pdop.value()); // line 3
    }
    while (NMEA.available() > 0)
    gps.encode(NMEA.read());
    } // The entire loop() routine.

    so then pdop.isUpdated() fires every input character (every 2 ms.) and I print like crazy to the Serial monitor.

    When I uncomment only “line 1”, it fires properly. Unclear why the change.

    When I uncomment only “line 2”, it starts firing every input character again.

    Also, uncommenting only line 3 makes it fire twice per second as it should.

    Uncommenting 1 or 3 cause the data element associated with the firing to be referenced and that, magically, resets the isUpdated() flag. It takes both actions. That is not mentioned, above.

    But with all 3 commented, the thing pops on every input character — essentially every time it can.

    Is this the intended operation of the library? I would think not. It seems like isUpdated() is somehow linked with the specific .value retrieval it fired for and never gets unset just by checking it as mentioned, above. Am I completely missing the point here?

    The sample code I referred to, previously, is here:

    https://github.com/mikalhart/TinyGPSPlus/blob/master/examples/UsingCustomFields/UsingCustomFields.ino

    I used it as my guide. And it finally led me to finding out that I had to reference the data element associated with the firing as well as calling isUpdated() to have it function properly. Since I will reference the firing data element, it will work properly and I can proceed to finishing my project but I would hope that you check further into this and make it work as documented. At least, as I read the documentation. I hope I did not miss something…

    Your library has saved me a bunch of time but has cost me many days of intermittently trying to troubleshoot this troublesome operation. I guess it is still a win. Thanks.

    I have written this code before (in VB6) with far more detailed data parsing and did not want to have to write it, again, in a different language (C).


  11. Mikal

    6 years ago

    I don’t know what to tell you, Mike. What you describe is exactly how I would expect it to behave, and how it’s documented to behave. If you “uncomment only line 2” and leave the other 2 commented out, you are no longer checking pdop.value(), therefore, isUpdated() will return “true” every time. Here’s the summary:

    1. If you don’t ever call pdop.value() (i.e. if you have lines 1 and 3 commented out) then pdop.isUpdated() will always be true, as documented.
    2. Line 2 references hdop a different object, so it has no bearing on pdop.isUpdated().

    It’s not “magic”: it’s exactly what’s in the documentation:

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


  12. Ricardo

    6 years ago

    Hi Mika, thankyou for library very nice!!
    I have a problem in the recovered values of gps.time.isValid ()
    my code:
      if (gps.time.isValid ())
       {
         Serial.print (gps.time.value ()); // Raw time in HHMMSSCC format (u32)
         hour = gps.time.hour ();
         minute = gps.time.minute ();
         second = gps.time.second ();
       }

    Everything works fine, as long as there are no zeros.
    for example for
    23:59:59
    time.value = 23595900
    time.hour = 23
    time.minute = 59
    time.second = 59

    but if time is 00:01:00
    time.value = 010000 (2 digits missing)
    time.hour = 0
    time.minute = 01
    time.second = 0

    The worst is the case of:
    time now 23:00:00
    time.value = 2300
    and
    time.hour = NULL
    time.minute = 23 (this is the time not the minutes)
    time.second = 0

    Explain well?
    Thanks for a solution, your library is very practical.


  13. Alexander Rubli

    6 years ago

    HI
    I would like to know if it is possible to disable the checksum verification. I would like to send some test sentences to see if my project handles correctly some error conditions and if my DST subroutine is working.

    I am not a seasoned programmer… just sort of an advanced beginner.

    thank you


  14. Mikal

    6 years ago

    @Alexander… see my github comment.


  15. Mikal

    6 years ago

    @Ricardo,

    What GPS device are you using? I admit I don’t see how this can happen. It might help if you could supply some of the raw NMEA or your code.


  16. Michael Strnad

    6 years ago

    Hello Mikal!
    First of all, that library is really great, I like it and used it already in some projects. Now I try to get the exact time from GPS to correct my clock: I have a Citroen 2CV that was electrified by the local technical school in 2007. 2011 I was able to buy it and now I try to have a look to the electrical interior with several sensors and an Arduino Mega. To have an overview I use a SmartGPU2 from Vizic Tec. But now with the GPS there must be a conflict at the serial. Vizic told me:
    From the examples I learned that Pin 10, 11 is used for data for the Mega. To define par example Pin 14, 15 and Serial1 for the communication with the GPS did not work and I have no experience how to do it. I would be glad for a hint how to do it. Thanks a lot!


  17. Rushi

    6 years ago

    I did not get Location in indoor. Can this module support indoor location? I am use TinyGPS library. Please tell me what to do for indoor location?


  18. Yannis Xidianakis

    6 years ago

    Hi and thanks for this amazing library.
    I want to use a function to show me in an OLED display the fix 2D or 3D or none and also to get the sat elevation.
    How can i do taht?
    Thank you.


  19. Heikki

    6 years ago

    Hi and thank you for sharing this. Would it be possible to have two receivers on Arduino Due with TinyGPSPlus? I tried first reading one on serial2 and then another on serial3 on same loop. This returns invalid position. While reading just one or the other data is valid. I would like to see how position drifts between two receivers that are close to each other. I could try making a compass by placing two receivers at distance of about 7 meters from each others. Heading signal could be filtered as I have gyro data to enhance heading. As I have CAN bus and several arduinos on the bus I could send the position of the other receiver over the bus and see how that works.

    Is position available in radians on TinyGPSPlus? Not of course a big thing.


  20. Mikal

    6 years ago

    Hi @Heikki,

    Yes, you can use two receivers at once. Just make sure you declare two TinyGPS++ objects… one for each stream:

    TinyGPSPlus gps1, gps2;
    while (true)
    {
    if (Serial2.available())
    gps1.encode(Serial2.read());
    if (Serial3.available())
    gps2.encode(Serial3.read());

    … do stuff here with gps1 and gps2 …
    }


  21. Chris

    6 years ago

    Thank you so much, I’ve been working with a GPS unit from Adafruit for the last three days and I could not understand what to do until I dl’d/installed your lib and read your documentation. The explanation was key, and thank you for publishing the methods. All of the other libraries I found we very dense and poorly documented. Your examples are clearly superior as well.

    Thanks again.


  22. Christiaan

    5 years ago

    I get this error, while using the “courseTo” function. I just copied the code from the code box.

    GPS_plaatsdetectie:38: error: expected primary-expression before ‘.’ token

    TinyGPSPlus.courseTo(

    ^

    exit status 1
    expected primary-expression before ‘.’ token


  23. Mikal

    5 years ago

    @Chris, thanks for the nice message.


  24. Mikal

    5 years ago

    @Christiaan, in C++ the syntax for static functions is

    TinyGPSPlus::courseTo(…)

    (Note double semicolon.)


  25. Bengt

    3 years ago

    Hi, thanks for excelent code. I have a problem trying to asign the value when I have used a ustom NMEA Sentence Extraction like this:

    TinyGPSPlus NEXUS;
    TinyGPSCustom hdmNow(NEXUS, “IIHDM”, 1); // $IIHDM sentence, 1st element

    SerialMonitor.println(hdmNow.value()); // Works
    double oldDir = *hdmNow.value(); // Does not work, value of oldDir is not set


  26. Pit Hermann

    1 year ago

    @Mikal

    Hello,
    I’m missing the values for W (West) and E (East) on longitude and even
    the values for N (North) and S (South) on latitude
    Did you implement them with location.rawLat().negative and gps.location.rawLng().negative ?

    Pit


  27. Martin Brightmore

    1 year ago

    Hi Mikal

    Great piece of software, thank you.

    Could you explain why LONDON_LON is divided by 1000 in the following statement?

    unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
    gps.location.lat(),
    gps.location.lng(),
    LONDON_LAT,
    LONDON_LON) / 1000;
    printInt(distanceKmToLondon, gps.location.isValid(), 9);

    Thank you
    Martin


  28. tolis.labas

    10 months ago

    hi can i ask for help??i want to put the distanse from home and Course over ground.
    here is the code

    #include //https://github.com/adis1313/iBUSTelemetry-Arduino
    #include
    #include
    #include
    #include

    //pin pour carte SD
    const int cs_sd=2;

    TinyGPSPlus gps;

    #define UPDATE_INTERVAL 500

    // pin voltage
    #define dP A0

    iBUSTelemetry telemetry(9); // arduino pin pour donnes iBUS

    uint32_t prevMillis =0; // neessaire pour updateValues()

    //LED

    const int verte = 3;
    const int rouge = 4;

    float maxspeed = 0, speed1 = 0;
    int maxhigh = 0, high1 = 0;
    int maxsatelite = 0, satelite1 = 0;

    float meters ;
    float voltage=0.0;

    void setup()
    {
    Serial.begin(9600);

    pinMode(rouge, OUTPUT);
    pinMode(verte, OUTPUT);

    //Condition vrifiant si la carte SD est prsente dans l’appareil

    if(!SD.begin(cs_sd))
    {

    digitalWrite(rouge, HIGH);//absence SD
    return;
    }

    digitalWrite(rouge, LOW);// carte SD absente

    File data = SD.open(“donnees.txt”,FILE_WRITE); // Ouvre le fichier “donnees.txt”
    data.println(“”); data.println(“Demarrage acquisition ibus”); // Ecrit dans ce fichier
    data.println(“”); data.println(“date heure latitude longitude altitude vitesse”);
    data.close();

    Wire.begin();
    telemetry.begin();

    // definition capteurs

    telemetry.addSensor(IBUS_MEAS_TYPE_ALT); //altitude
    telemetry.addSensor(IBUS_MEAS_TYPE_EXTV); //batterie
    telemetry.addSensor(IBUS_MEAS_TYPE_SPE); //vitesse km/h
    telemetry.addSensor(IBUS_MEAS_TYPE_GPS_LAT); // latitude
    telemetry.addSensor(IBUS_MEAS_TYPE_GPS_LON); // longitde

    }

    void loop()
    {

    updateValues();
    telemetry.run();
    }

    void updateValues()
    {

    // lecture donnes Gps et allumage LED si OK

    if (Serial.available()) {
    digitalWrite(verte, HIGH);//donnes Gps OK
    gps.encode(Serial.read());
    }

    float meters = (gps.altitude.meters());
    voltage=float(analogRead(dP))*(20/1023.00);
    float airSpeed = (gps.speed.kmph());

    // definition vitesse max

    speed1 = (gps.speed.kmph());
    if ( speed1 > maxspeed) {
    maxspeed = speed1;
    }

    // recuperation date et heure du GPS pour datalogging

    String Temps=String(gps.time.hour()+1)+(“:”)+(gps.time.minute())+(“:”)+(gps.time.second());
    String Date=String(gps.date.day())+(“/”)+(gps.date.month())+(“/”)+(gps.date.year());

    // Temporisation

    uint32_t currMillis = millis();

    if (currMillis – prevMillis >= UPDATE_INTERVAL) { // Code in the middle of these brackets will be performed every 500ms.
    prevMillis = currMillis;

    // affichage donnes capteur sur radiocommande

    telemetry.setSensorValue(1, (meters )*100.0 ); // altitude

    telemetry.setSensorValue(2, voltage*100 );

    telemetry.setSensorValue(3, speed1 );

    telemetry.setSensorValue(4, (gps.location.lat()*10000000));

    telemetry.setSensorValue(5, (gps.location.lng()*10000000)) ;

    // Ecriture des donnes dans le fichier texte

    File data=SD.open(“donnees.txt”,FILE_WRITE);

    data.println(Date + ” ” + Temps + ” ” + String(gps.location.lat(), 6)+” “+String(gps.location.lng(), 6)+(” “)+String(gps.altitude.meters(),0)+(” “)+String(speed1)+(” “)+String(maxspeed));
    data.close();
    }
    }


  29. Akash Mittal

    9 months ago

    Sir i am using tinygpscustom it does not give any response when we print any value from nmeasentence we are using Quectel L89HA S90 please help me


  30. adria

    8 months ago

    using the library i get no data parsed

    22:58:13.246 -> load:0x40080400,len:3600
    22:58:13.277 -> entry 0x400805f0
    22:58:13.376 -> DeviceExample.ino
    22:58:13.376 -> A simple demonstration of TinyGPSPlus with an attached GPS module
    22:58:13.376 -> Testing TinyGPSPlus library v. 1.0.2
    22:58:13.376 -> by Mikal Hart
    22:58:13.376 ->
    22:59:37.206 -> Location: INVALID Date/Time: INVALID INVALID
    23:00:43.288 -> Location: INVALID Date/Time: INVALID INVALID

    running from serial i get:

    $GLGSV,2,1,08,65,38,244,,71,26,040,34,72,71,358,33,73,05,064,*6B
    $GLGSV,2,2,08,80,04,015,,86,28,153,31,87,81,189,32,88,37,325,30*60
    $GNGLL,4118.56209,N,00159.69793,E,220620.00,A,A*78
    $GNRMC,220621.00,A,4118.56214,N,00159.69795,E,0.948,89.86,130324,,,A*49
    $GNVTG,89.86,T,,M,0.948,N,1.756,K,A*1C
    $GNGGA,220621.00,4118.56214,N,00159.69795,E,1,07,3.33,121.9,M,49.4,M,,*40
    $GNGSA,A,3,03,02,04,21,,,,,,,,,4.55,3.33,3.10*1F
    $GNGSA,A,3,72,86,71,,,,,,,,,,4.55,3.33,3.10*14
    $GPGSV,3,1,11,01,,,34,02,32,136,30,03,55,052,36,04,78,125,39*4F
    $GPGSV,3,2,11,06,28,312,31,09,44,211,32,17,45,244,19,19,42,282,33*77
    $GPGSV,3,3,11,21,18,136,24,28,08,035,15,31,20,059,39*47

    gps is a BN 810 Beitian


  31. Olivier CROISET

    6 months ago

    Hi Mikal,
    I use this library, that works fine.
    For the first time I use the HDOP value: in my sketch, the HDOP value is very high, from 100 to 300. (all other values, lon, lat , date and time, alt are correct).

    My sketch uses :

    #include “TinyGPS++.h”

    tft << "HDOP: " << gps.hdop.value();

    Any idea?
    Thanks for your help.


  32. Mike Morrow

    3 months ago

    Since you seem to use the Position Fix Indicator value field from GGA statement internally. Could you please expose this via command to us? Yes, I know I can put in a Custom for it and I will since it does not seem to be available. That’s very important to have available.

    Love your library. Been using it since it was invented. Never wanted to use fix quality before. I have been using 3 other .valid values to be sure all is well.

    Thanks,
    Mike


  33. Mikal

    2 months ago

    Thanks for this, Mike. Older me agrees that younger me should have put this feature in. :)


  34. davut

    1 month ago

    Hello. Thank you for the library. Could you explain the cardinal() issue a little more, I don’t understand it. Can you explain in more detail how I can measure my distance to a location? I couldn’t understand it from githup.


  35. Mikal

    1 month ago

    Hi!

    “Cardinal” translates a direction (in degrees) to a compass presentation. People are sometimes more comfortable with directions (“SSE” or “NW”) than bearings in degrees.

    If you know the latitude and longitude of two points on the earth (four total values), DistanceBetween will measure the distance in meters between them. Just follow the example and it should be pretty clear?

4 Trackbacks For This Post
  1. Using the GT-U7 GPS module based on u-blox 7th generation GPS chip – Pseudo Random

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

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

  3. Guide to NEO-6M GPS Module with Arduino - IOT3TDIY

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

  4. Tutorial GPS con Arduino módulo NEO-6M - Geek Factory

    […] Página oficial de la librería TinyGPS y TinyGPS++ […]

Leave a Reply