A Compact Arduino GPS/NMEA Parser

TinyGPS is designed to provide most of the NMEA GPS functionality I imagine an Arduino user would want – position, date, time, altitude, speed and course – without the large size that seems to accompany similar bodies of code.  To keep resource consumption low, the library avoids any mandatory floating point dependency and ignores all but a few key GPS fields.


To use, simply create an instance of an object like this:

#include "TinyGPS.h"
TinyGPS gps;

Feed the object serial NMEA data one character at a time using the encode() method. (TinyGPS does not handle retrieving serial data from a GPS unit.) When encode() returns “true”, a valid sentence has just changed the TinyGPS object’s internal state. For example:

#define RXPIN 3
#define TXPIN 2
SoftwareSerial nss(RXPIN, TXPIN);
void loop()
  while (nss.available())
    int c = nss.read();
    if (gps.encode(c))
      // process new gps info here

You can then query the object to get various tidbits of data. To test whether the data returned is stale, examine the (optional) parameter “fix_age” which returns the number of milliseconds since the data was encoded.

long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;

// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);

// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);

// returns speed in 100ths of a knot
speed = gps.speed();

// course in 100ths of a degree
course = gps.course();


The stats method provides a clue whether you are getting good data or not. It provides statistics that help with troubleshooting.

// statistics
gps.stats(&chars, &sentences, &failed_checksum);
  • chars – the number of characters fed to the object
  • sentences – the number of valid $GPGGA and $GPRMC sentences processed
  • failed_checksum – the number of sentences that failed the checksum test

Integral values

Values returned by the core TinyGPS methods are integral. Angular latitude and longitude measurements, for example, are provided in units of millionths of a degree, so instead of 90°30’00″, get_position() returns a longitude value of 90,500,000, or 90.5 degrees. But…

Using Floating Point

…for applications which are not resource constrained, it may be more convenient to use floating-point numbers. For these, TinyGPS offers several inline functions that return more easily-managed data. Don’t use these unless you can afford to link the floating-point libraries. Doing so may add 2000 or more bytes to the size of your application.

float flat, flon;

// returns +/- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
float falt = gps.f_altitude(); // +/- altitude in meters
float fc = gps.f_course(); // course in degrees
float fk = gps.f_speed_knots(); // speed in knots
float fmph = gps.f_speed_mph(); // speed in miles/hr
float fmps = gps.f_speed_mps(); // speed in m/sec
float fkmph = gps.f_speed_kmph(); // speed in km/hr

Date/time cracking

For more convenient access to date/time use this:

int year;
byte month, day, hour, minutes, second, hundredths;
unsigned long fix_age;

gps.crack_datetime(&year, &month, &day,
  &hour, &minute, &second, &hundredths, &fix_age);

Establishing a fix

TinyGPS objects depend on an external source, i.e. its host program, to feed valid and up-to-date NMEA GPS data. This is the only way to make sure that TinyGPS’s notion of the “fix” is current. Three things must happen to get valid position and time/date:

  1. You must feed the object serial NMEA data.
  2. The NMEA sentences must pass the checksum test.
  3. The NMEA sentences must report valid data. 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 those sentences are discarded.

To test whether the TinyGPS object contains valid fix data, pass the address of an unsigned long variable for the “fix_age” parameter in the methods that support it. If the returned value is TinyGPS::GPS_INVALID_AGE, then you know the object has never received a valid fix. If not, then fix_age is the number of milliseconds since the last valid fix. If you are “feeding” the object regularly, fix_age should probably never get much over 1000. If fix_age starts getting large, that may be a sign that you once had a fix, but have lost it.

float flat, flon;
unsigned long fix_age; // returns +- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
if (fix_age == TinyGPS::GPS_INVALID_AGE)
  Serial.println("No fix detected");
else if (fix_age > 5000)
  Serial.println("Warning: possible stale data!");
  Serial.println("Data is current.");

Interfacing with Serial GPS

To get valid and timely GPS fixes, you must provide a reliable NMEA sentence feed. If your NMEA data is coming from a serial GPS unit, connect it to Arduino’s hardware serial port, or, if using a “soft” serial port, make sure that you are using a reliable SoftSerial library. As of this writing (Arduino 0013), the SoftwareSerial library provided with the IDE is inadequate. It’s best to use my NewSoftSerial library, which builds upon the fine work ladyada did with the AFSoftSerial library.

Library Version

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

int ver = TinyGPS::library_version();

Resource Consumption

Linking the TinyGPS library to your application adds approximately 2500 bytes to its size, unless you are invoking any of the f_* methods. These require the floating point libraries, which might add another 600+ bytes.


The latest version of TinyGPS is available here: TinyGPS13.zip

Change Log

  1. initial version
  2. << streaming, supports $GPGGA for altitude, floating point inline functions
  3. also extract lat/long/time from $GPGGA for compatibility with devices with no $GPRMC
  4. bug fixes
  5. API re-org, attach separate fix_age’s to date/time and position.
  6. Prefer encode() over operator<<. Encode() returns boolean indicating whether TinyGPS object has changed state.
  7. Changed examples to use NewSoftSerial in lieu of AFSoftSerial; rearranged the distribution package.
  8. Greater precision in latitude and longitude.  Angles measured in 10-5 degrees instead of 10-4 as previously.  Some constants redefined.
  9. Minor bug fix release: the fix_age parameter of get_datetime() was not being set correctly.
  10. Added Maarten Lamers’ distance_to() as a static function.
  11. Arduino 1.0 compatibility
  12. Added satellites(), hdop(), course_to(), and cardinal()
  13. Improved precision in latitude and longitude rendering. get_position() now returns angles in millionths of a degree.


Many thanks to Arduino forum users mem and Brad Burleson for outstanding help in alpha testing this code. Thanks also to Maarten Lamers, who wrote the wiring library that originally gave me the idea of how to organize TinyGPS.  Thanks also to Dan P. for suggesting that I increase the lat/long precision in version 8.  Thanks to many people who suggested new useful features for TinyGPS, especially Matt Monson, who wrote some nice sample code to do so.

All input is appreciated.

Mikal Hart

Page last updated on August 31, 2013 at 7:00 pm
701 Responses → “TinyGPS”

  1. Mikal

    9 years ago


    Does that device allow you to (temporarily) ratchet down the baud rate to 9600 or 4800? I’m just guessing your problem might have to do with the high speed over a software serial link?

  2. Peter

    9 years ago

    The ITEAD studio GPS I bought has a Ublox NEO 6M module on it.
    There is a Ublox utility for working with the GPS on their web site, but I suspect you cannot communicate with it via the arduino uno usb port, and my attempts to alter the data rate to other than 38,400bps were ineffective.
    There is a real lack of documentation for this unit other than the data sheet and a detailed manual for that module (which indicated that 9600 bps is the default data rate). It would be nice if there were the equal of the “AT” command set to modify the behavior of the module.
    The sentences produced all seem to be truncated (missing the checksum). I understand that fairly recently (last couple of years?)that NMEA sentence was modified to add another character of information before the checksum. Other sentences produced on startup seem to have checksums attached, only the $GPRMC that appears after a few minutes lacks the checkum.

    Perhaps I can find a way to communicate with the GPS module directly and alter the data rate, but for the moment, I can find no way to chage to 4800 or 9600 bps.
    Thanks, Peter
    Would there be any Arduino buffers that should be increased in size?

  3. Pete

    9 years ago


    If I were to detach the GPS shield and then load a sketch into the Arduino that interfaced the GPS to the Arduino on pins 0 and 1, I think I would be using a faster hardware interface?? I could then remount the GPS shield, reboot and use a monitoring program, but without the need for the SoftSerial library. Do you think this would help with the speed problem?


  4. Mikal

    9 years ago


    Probably so. I don’t know for sure whether the strange behavior with those modules is caused by characters dropped the software serial interface or whether the modules themselves have a peculiarity that TinyGPS doesn’t accommodate, but this seems like a good way to find out.

  5. Pete

    9 years ago

    silly me – I will still need two ports to talk to two devices. I guess I could use the softserial port to communicate between the Arduino and the PC, and the hardware port to communicate from the GPS to the Arduino. I am assuming the hardware port is more capable of higher speeds than softserial.

  6. Pete

    9 years ago


    To follow up on the above:

    The ITEAD GPS Shield 1.1 is equipped with a UBlox Neo 6m gps module on an Arduino shield.
    As you recall, I asked for help since it appeared to be generating incomplete sentences (and therefor no fix). The hardwired default RATE WAS 38,400 BPS.
    I found that by using some $PUBX commands to the ublox GPS in a sketch (found on the net), I could change the rate to 4800. I should mention I found at least one opinion that 19,200bps is as fast as SoftwareSerial can go on an Arduino Uno.
    At any rate, the GPS now works perfectly, even getting good reception thru a closed glass window. (11 sats) So the main thrust of this email is to let you know the Itead GPS works, but not faster than 4800 bps via SoftwareSerial.
    However, one problem remains. After changing the port’s bps rate, if I remove power the new setting vanishes and I then have to “re-install the rate change.
    Question: Do you know a $PUBX command to store the configuration data in the eblox GPS module in non-volatile memory? I can’t find any references to a complete function list of $PUBX commands.


  7. Randy

    9 years ago

    First to Pete, thank you for those of us pulling our hair out wishing to use iTead shield and TinyGPS++. The $PUB commands work and I would never have found without your post. For the record, starting with SoftwareSerial at 38400, I added the following lines to my setup.

    ss.print(“$PUBX,41,1,0007,0003,4800,0*13\r\n”); // Change iTead baudrate
    ss.begin(4800); // reset SoftwareSerial baudrate

    I am a newbie and delay(50) may not be required but seemed to help.
    The following reference I found indicates there is no nonvolatile memory and that battery backup would be required.

    Mikal, great library, I want to add my thanks to all the myriad others I have seen directed to you while searching for a solution to this problem.

  8. Mikal

    9 years ago

    @Randy, @Pete,

    Yes, thank you for investigating this. It sounds like the iTead modules may be compliant after all, it’s just that the high speed overwhelms the microcontroller. Thanks for the workaround code.

  9. Peter

    9 years ago

    Further update on the Itead GPS shield:
    I found that I could use the AltSoftSerial.h library with better results. I can run the GPS at 38,400 and get excellent results. However, the AltSoftSerial routines are “hardwired” to pins 8 and 9 of the Uno. I made a simple 2 wire jumper that took the signal from the Itead pin selection block Rx row and Tx row ( any pin in either row), and routed them to pins 8 and 9. Of course, remove the jumpers from the pin select jumper block.
    For some reason, my Itead GPS never seems to listen, so I can’t easily switch speeds, and it can’t remember modified parameters on power cycling, but since it is hardwired to default to 38400 BPS, this is fine.
    I don’t know if it is defective, or if it my ignorance that’s the problem, but I have worked around it.

    Here’s the “test” code from AltSoftSerial.h modified for bps rates:


    // AltSoftSerial always uses these pins:
    // Board Transmit Receive PWM Unusable
    // —– ——– ——- ————
    // Teensy 2.0 9 10 (none)
    // Teensy++ 2.0 25 4 26, 27
    // Arduino Uno 9 8 10
    // Arduino Mega 46 48 44, 45
    // Wiring-S 5 6 4
    // Sanguino 13 14 12

    AltSoftSerial altSerial;

    void setup() {
    Serial.println(“AltSoftSerial Test Begin”);
    altSerial.println(“Hello World”);

    void loop() {
    char c;

    if (Serial.available()) {
    c = Serial.read();
    if (altSerial.available()) {
    c = altSerial.read();

    Hope this helps.

  10. Mikal

    9 years ago


    Thanks for that. Yeah, AltSoftSerial is a good product if it applies.

  11. Matt

    9 years ago

    Just to add a small comment to this thread on communicating with high Baud rate gps’ (I am using a 5Hz, 57,600 baud rate 66 channel LS20031 GPS). There is certainly an issue with serialSoft. Other forums have suggested increasing the buffer in the serialSoft library to get around this.

    Personally I take the easy route and up load my sketch and then connect the GPS to pin 0 and 1 afterwards.

  12. Brendan

    9 years ago

    Hi Mikal,

    Thanks very much for creating and maintaining this library.

    I’m using the Adafruit Ultimate GPS library with battery backup, which essentially functions as a RTC and outputs the correct time even though no fix is established. I’ve been doing some testing, and it seems like TinyGPS is filtering out these sentences as there is no valid fix.

    I’m attempting to modify the library to parse the date/time before evaluating the sentence checksum (in the TinyGPS::term_complete() function). Do you think this will create any further issues with the rest of the library?


  13. Mikal

    9 years ago


    You are quite right that TinyGPS discards sentences that arrive without a Fix. This, as you point out, potentially discards a perfectly good timestamp, because the time can be correct even when the location fix is not. You might examine how we solve this problem with TinyGPS++.

  14. T Arnerich

    9 years ago


    Thank you for your superbly functioning GPS utility. I was initially using my own routines for NMEA parsing but there were some puzzling issues with truncated sentences. Your TinyGPS example with the reported statistics was a welcome 2nd opinion which helped me find reliable settings for the baud rate and NMEA sentence repeat rate.

    I could use an even tinier Tiny GPS so I would like to see if I can trim out any functionality I won’t be using. I am trying to log not only GPS data to an SD card, but also the data from the many sensors in the AdaFruit 10 degree of freedom inertial measurement unit.

    The SD card library is not small, and the 10-DOF IMU libraries aren’t small either. I can log GPS data to the SD; the remaining RAM at that point is 383 bytes. When I include the IMU’s data my free RAM shrinks down to 355 bytes and the sketch will simply not run. Any trimming I can do should get me closer to a workable sketch.

    The GPS fields I wish to log are Date, Time, Lat, Lon, Altitude, Course, and Speed in mph. The 10-DOF will be contributing 3 axes each for Accelerometer, Magnetometer, and Gyroscope.

    Can you offer any advice for trimming down TinyGPS? I’ve been looking through the SD and also the AdaFruit sensor libraries but haven’t found any low-hanging fruit there yet.

  15. Mikal

    9 years ago

    @T Arnerich,

    If I were in your position I think I’d consider the “low hanging fruit” to be the 64 bytes that the hardware and/or software serial libraries allocate by default.

    Actually, when I found myself recently in a similar position I migrated my application to the Teensy++ (http://pjrc.com). You might try that or another Arduino-like device with more RAM.

  16. Tim

    9 years ago

    I am running the iTead Studios GPS shield with an UNO for the purpose of controlling 4 external relays that operate every 15 seconds to provide timing interlock for several paging transmitters that share the same channel.
    The problem that I am experiencing is that the time shown by the GPS is about 9 seconds behind actual time.
    I am using TinyGPS++ but have also seen the same error with TinyGPS.
    Have you or anyone else noticed this time error?
    Occasionally after reloading the sketch the time will be correct for a few minutes then return to the 9 second late error.
    Thanks, Tim

  17. john

    9 years ago

    no matter what i do i cant get past the “Tinygps does not name a type error
    I can see the libart in the arduino libary folders but I cant get it to work.

    thanks john

  18. Mikal

    9 years ago

    @john, Make sure your type has the correct capitalization. It’s “TinyGPS”. Also, make sure to #include .

  19. Nagaraj

    9 years ago

    Guys i really need some help here. I’m interfacing a gps receiver with my arduino mega. I have a simple gps receiver with nmea output. I tried reading sequence.I used to get proper loc. But now am able to receive only GPVTG. Can anybody please help me on this.

  20. Brian

    9 years ago


    The TinyGPS++ custom fields capability looks very interesting for an application we have in mind, but I need to check a few details first!

    Basically, we’re looking to replace some of the unused/irrelevant (I hope) data in the NMEA strings with telemetry data, recalculate the checksum, and then forward that to the ground station.

    Basically, does TinyGPS++ use the GPGGA fields such as: Height of geoid above WGS84 ellipsoid, DGPS reference station id, and other oddballs?

    Lastly, if you simply want lat/long and altitude, can TinyGPS+ extract those from a GPGGA-only sting? (uBlox receivers can limit the strings transmitted, allowing you to optimize wireless bandwidth)


  21. Racheney

    9 years ago

    I seem to have a problem between tinygps and ledcontrol.h . ledcontrol stoppes working as soon as I start an instance of tinygps. Has anyone else encountered this problem with the 2 libraries running in the same sketch?

  22. Antonio Ladeia

    9 years ago

    Hello Mikal,

    I’m use your library, but not have any data from Iteastudio GPS shield.

    My code is here https://github.com/Ladeia/TCC/blob/master/gps/gps.ino

    and I use the ports RX 4 and TX 3.

    I need help…

  23. Kevin

    9 years ago

    Tim- my class is using the same board as you (itead gps v1.1) and an UNO rev3 on Arduino IDE 1.05, but cannot get any of the examples from tinyGPS++ to work. We get nothing but ****** stars.How did you get yours up and running?

    However, we do get valid gprmc data, and the sentence count is 0 when the simple test from tinyGPS (no plus) is run, and the baud rate of the gps softserial is set to 38400. From Arduino 1.00 up the baud limitation has supposedly been lifted on software serial.
    I’ve been searching the net and forums until my eyes bled for an answer to get the gps unit working, any help will be welcome from someone who has the same itead gps v1.1.

  24. Nic

    9 years ago

    it would be nice to put a download for this somewhere where someone can find it, is there a prize for someone who locates it?

  25. Mikal

    9 years ago


    How do you know you “do get valid gprmc data”? Could you log an example of what you are getting and send me a snippet?

  26. Kevin

    9 years ago


    I am getting the following $gprmc stream using your TinyGps simple test and uncommenting the serial read(c).(tinygps++ examples do not have an option to view the raw serial, and I do not have enough experience to add it in yet)

    $GPRMC,001707.00,A,4230.22586,N,08258.44727,W,0.262,,220414,,,D1 CHARS=642 SENTENCES=0 CSUM ERR=0
    $GPRMC,001708.00,A,4230.22595,N,08258.44728,W,0.226,,220414,,,DG. CHARS=707 SENTENCES=0 CSUM ERR=0
    $GPRMC,001709.00,A,4230.22622,N,08258.44724,W,0.215,,220414,,,D1 CHARS=771 SENTENCES=0 CSUM ERR=0
    $GPRMC,001710.00,A,4230.22641,N,08258.44724,W,0.105,,220414,,,D0W CHARS=836 SENTENCES=0 CSUM ERR=0
    $GPRMC,001711.00,A,4230.22660,N,08258.44723,W,0.137,,220414,,,D, CHARS=900 SENTENCES=0 CSUM ERR=0
    $GPRMC,001712.00,A,4230.22673,N,08258.44726,W,0.040,,220414,,,D0 CHARS=964 SENTENCES=0 CSUM ERR=0
    $GPRMC,001713.00,A,4230.22681,N,08258.44724,W,0.218,,220414,,,D, CHARS=1028 SENTENCES=0 CSUM ERR=0

    As you can see, I have a valid fix noted by the A, latitude and long data, many characters and no sentences.
    @Antonio Ladeia- if I get this working I’ll let you know, because it looks like we are in the same situation.

  27. Mikal

    9 years ago


    Well, I see why TinyGPS[++] is not parsing those strings. The required checksum field is missing. See http://blog.iteadstudio.com/play-arduino-with-global-positioning-system-gps/, in particular the text

    eg1. $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68

    *68 mandatory checksum

    One of two things is happening. Either the module is not transmitting any checksum, or, more likely, you’re experiencing buffer overflow. Do these experiments:
    1. Look at ss.overflow() to see if it’s true. I bet it is.
    2. Change _SS_MAX_RX_BUFF in SoftwareSerial.h from 64 to 144, exit Arduino, and come back in. See if that makes a difference.
    3. Maybe experiment with reducing the baud rate of the connection?

  28. Aaron Hall

    9 years ago

    Hi Mikal,

    I am in the process of building a box*(arduino Uno), using the Audafruit GPS Shield. I have had some success so far. However I am to the point of implementing a Time Constraint/ Time limit using the date and time from the GPS module.
    If you can offer any incite into how to run this data…I would appreciate it.


  29. sherbahdur

    9 years ago

    why I am getting *************** at the serial monitor of the arduino Uno.

  30. Mikal

    9 years ago

    @Aaron Hall,

    It’s not too hard. Use TinyGPS or TinyGPS++ (the latter is easier) to grab the current time, then compare it to the time you’re interested in. For example, if you don’t want the box to open before December 25, 2014 you could:

    if (gps.date.year > 2014 ||
        (gps.date.year == 2014 && gps.date.month == 12 && gps.date.day >= 25)
       ... open box

  31. Syah

    9 years ago


    I used the exact code. However, if I were to use “if(gps.encode(gpsSerial.read()))”, it won’t execute whatever codes below. If I were to change it to “if(gpsSerial.read())”, the longitude and latitude are both 999999999999999.

    Please assist.

  32. Joe

    9 years ago

    Hello Mikal!

    Awesome work with TinyGPS! It has sped my development along!

    I have a uBlox 5 GPS and an Arduino Pro Mega. The GPS data arrives on one of the UARTs and TinyGPS parses the data. I’ve been able to reduce the number of GPS sentences coming from the GPS to improve bandwidth and, presumably, reduce discarded sentences. I also set the GPS baud to 19200. Lastly, I transmit the GPS data using a RFM DNT900.

    The main loop calls a function to process incoming GPS sentences using TinyGPS. My understanding is when encode() returns true, valid GPS data is available. When GPS data is valid, I transmit the data. The set up for the transmission requires a bit of time but I have not had an issue transmitting valid GPS data once per second.

    I am seeing some odd behavior and wanted to ask about it. Occasionally, I see the same GPS data transmitted twice:


    My theory is the loop executes fast enough that it calls encode() before more GPS data arrives. That is, I get valid GPS data, transmit it, call encode() and it returns true because the previous data is valid.

    My goal is to have GPS data transmitted once per second. What data might I use from TinyGPS to help with that goal?


  33. Joe

    9 years ago

    @Joe Follow Up

    Hello Mikal!

    I did some experiments today. I changed the program to transmit GPS data only when the current and previous GPS time are different. This check is made immediately after calling encode for the last character received from the GPS.

    This successfully limits the transmission to once per second and only when the GPS time changes. I’m still curious about your thoughts on this.


  34. Robin

    9 years ago

    Hello Mikal,
    I’m using your librairy, but I want to use an Xbee in paralel with it.

    The problem is: I don’t now how to assigne an another specific serial output to the TinyGPS.

    Can you help me please?


  35. Mikal

    9 years ago


    Not quite. encode() only returns true when it has just received the last character of (and parsed) an NMEA sentence. If that sentence doesn’t affect the location–and some don’t–encode still returns true, even though the location hasn’t changed.

    Have you looked at TinyGPS++ on the same site? Each object contains an “isUpdated” method that you can poll. Using that you can ignore the return value of encode() and just transmit when you data has been updated.

  36. Mikal

    9 years ago


    Ah! Great solution!

  37. Mikal

    9 years ago


    Have you considered using a Mega or a device which contains multiple hardware serial ports?

  38. Robin

    9 years ago


    Yes, I’m using an arduino mega.
    Now, the problem is that I’m sending NMEA sentences that was given in your example by an arduino UNO, to an arduino MEGA.
    I have checked the MGA receive the sentences, but the problem is that it can’t extract the course from it.

    Thanks for helping me

  39. Ankit

    9 years ago

    Can you please explain how and where does the TinyGPS library do all the required calculations to get the fix?

  40. Mats

    9 years ago

    I’m trying to make a power budget for a TinyGPS.

    And does anyone have experience what the time is from cold start to have a fixed position. I know that it can vary depending on factors like clouds, partly seen sky and so on.

  41. nick

    9 years ago

    I have an unusual behaviour when it comes to your library.

    i have arduino duemilanove and em408
    My code is this:

    #include <Arduino.h>
    #include <TinyGPS.h>
    #define GPS_RX_PIN 2
    #define GPS_TX_PIN 3
    TinyGPS gps;
    SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);
    void setup()
    void loop()
      while (ss.available())
        char c = byte(ss.read());
        // Here i tried Serial.write(c); and i succesully saw the NMEA data in my serial monitor
        if (gps.encode(c))
          long lat, lon;
         unsigned long fix_age;
        gps.get_position(&amp;lat, &amp;lon, &amp;fix_age);
        if (fix_age == TinyGPS::GPS_INVALID_AGE )
          Serial.println("No fix ever detected!");
        else if (fix_age &gt; 2000)
          Serial.println("Data is getting STALE!");
          Serial.println("Latitude and longitude valid!");
          Serial.print("Lat: ");
          Serial.print(" Lon: ");
        else Serial.println("Not encoded data!");

    My output is this:

    No data!
    No data!
    No data!
    No data!

    No data!
    No data!
    No data!
    No data!
    No data!
    No data!
    No data!
    No data!
    No data!
    Latitude and longitude valid!
    Lat: 32758239
    Lon: 15637489
    No data!
    No data!
    No data!
    No data!
    No data!
    No data!
    No data!

    And then i continue getting No data! forever…

    So… 1. Why does gps.encode() only manage to return true only 1 time? I have gotten the raw data from the gps (the commented code on my code snippet) and it’s ok. Why it returns true only one time?

    2. Why the longitude/latidude data is like this? As far as i know, this isnt valid, correct?

  42. Allan

    9 years ago

    Hi again Mikal.

    Please disregard my previous email for help.
    I have your excellent library working beautifully. Many thanks for that.

    My problem was simple. I downloaded the library and renamed it to TinyGPS.
    Unfortunately the files within the folder were still named TinyGPS13 (the current version).
    The compiler reported the Library as installed, when in fact it was not! I had extracted the files…. but of course they still had the old name within the new folder. Stupid me!
    It now works 100%.

    Kind regards,
    Allan (in sunny Scotland) :-)

  43. Mikal

    9 years ago


    The TinyGPS library doesn’t really do any calculations. It simply parses the data provided by the GPS module and presents it in a more convenient form.

  44. Mikal

    9 years ago

    @Mats, I get times of up to about 6 minutes with an absolutely cold EM-406A in poor conditions.

  45. Mikal

    9 years ago


    Your problem is probably buffer overflow caused by the fact that your sketch is mostly working on printing “No data!”. Remove that “else Serial.println(“No data!”)” line and see if that helps.

    The lat/long values are reported in millionths of a degree, so if you are off the Libyan coast they are correct. If not, I can’t explain them. :)

  46. Dizzwold

    9 years ago

    Hi Mikal. Great library. Do you know of any code to transmit TinyGPSPlus data over 2 nrf24l01′s? 1 TX 1RX.

  47. Ben

    9 years ago

    Fantastic Library! Love It.

    Have you considered option to allow use of TinyGPS::distance_between with longs instead of floats?

  48. Ben

    9 years ago

    Mikal & Users

    So many thanks – this really is a most fantastic piece of work.

    Kevin Walton & Terry Baume have forked previous versions to include some great additions for ublox recievers.
    Enabling the use of request / response gps updates instead of being hit with NMEA sentences constantly.
    I understand that your library has been designed to be non device specific, and further that the TinyGPS plus library has support for custom sentences, so I see why you have not rolled these additions into your source.

    I have updated Kevin and Terrys work to include your V13 updates and its available here: https://github.com/HarperBen/TinyGPS

    Again Mikal – thanks – through developing and releasing this library you saved me several days swearing at a gps module – Champion.

  49. Jonas

    9 years ago

    i want to send a complete sentence gpgga for example to an seial port…is there a command for tiny GPS for a complete sentence ???

  50. GOHO

    9 years ago

    Mikal , i want to ask u that how to show the calculating of the latitude and longitude in the program? and then how to show the value like an example -7.281495 that the value of the latitude, but on my program only show in serial.print in -7.28 like that…, can u explain to me please, thanks before…

82 Trackbacks For This Post
  1. เริ่มต้นสร้าง GPS จอสีกับอาดูอี้โน่ | Ayarafun Factory

    [...] http://www.sundial.org/arduino/?page_id=3 [...]

  2. 10

    [...] won’t. I answer a few questions on the Arduino microcontroller forum and post an update to a library I [...]

  3. The Hired Gun » GPS project: show me something

    [...] this journey I also looked into using the TinyGPS library. While it does a nice job of handling the core GPS parsing, I still had the primary desire to log [...]

  4. GPS mit Arduino - Webmeister Blog

    [...] serielle Verbindung werden die  Daten ans Display geschickt. Verwendet werden die Bibliotheken TinyGPS und [...]

  5. The Frustromantic Box, Part 4: Software « New Bright Idea

    [...] Arduino developers for the great librarires, and to Mikal Hart in particular for his work on the TinyGPS and NewSoftSerial [...]

  6. Transmission success - Projects

    [...] and sending the bits of “Hello World” in 7N1 format.  I spent some time with the TinyGPS and NewSoftSerial libraries from Mikal Hart, and got the parsing working nicely and building an [...]

  7. GPS testing with LCD Character Display

    [...] can have the LCD output latitude, longitude, or whatever. You’ll need the TinyGPS library from Arduiniana downloaded and installed for it to work. They suggest using NewSoftSerial, but I couldn’t get [...]

  8. Arduino GPS — not exactly pocket-sized, but cool! « Arduino Projects FTW

    [...] EEPROM so they are persistent between power cycles. The sketch uses Mikal Hart's excellent TinyGPS library and includes code from the ArduPilot Projectfor [...]

  9. A fully functional Arduino GPS receiver | Embedded projects from around the web

    [...] uses a TinyGPS library for easier GPS shield access. So device can be used as normal GPS tracking device the only [...]

  10. Moving Forward with Arduino – Chapter 17 – GPS « t r o n i x s t u f f

    [...] point you will need to install two libraries into the Arduino software – NewSoftSerial and TinyGPS. Extract the folders into the libraries folder within your arduino-001x [...]

  11. Shield Driven Arduino GPS

    [...] sketch uses Mikal Hart’s excellent TinyGPS library and includes code from the ArduPilot Project for [...]

  12. GPS bővítés « Nikon D5000 DSLR

    [...] 2 [...]

  13. The Maritime Geocaching Association » Build Your Own Steampunk GPS

    [...] attached code should pretty much speak for itself. Using the TinyGPS library, your current position is taken and the direction to the final location is calculated. [...]

  14. Moving Forward with Arduino – Chapter 19 – GPS part II « t r o n i x s t u f f

    [...] pull-down resistor). You will need to install the SdFAT library, NewSoftSerial library, TinyGPS library and the SdFat library if not already [...]

  15. Arduinoによる放射線データ収集(3) « stastaka's Blog

    [...] http://arduiniana.org/libraries/tinygps/ USBシリアルを使っているとTX,RXが使えませんが、 [...]

  16. reptile-addict.nl | My Arduino Blog

    [...] Mikal Hart’s tinyGPS library; [...]

  17. Communicating to GPS Receiver using USB Host Shield « Circuits@Home

    [...] how to send raw GPS output to a NMEA 0183 message parser. For the following code example I used Mikal Hart’s TinyGps library. Since the library itself is not handling serial input, it was only necessary to make changes in [...]

  18. GpsBee and Seeeduino Stalker v2 « Wireless Building Automation

    [...] easy developing of the necessary Arduino application I used an existent dedicated library: TinyGPS (http://arduiniana.org/libraries/tinygps/), which help us to parse all the packets received on the serial port from the GpsBee module. Ok, so [...]

  19. SheekGeek » Blog Archive » Weather Balloon Payload Testing on a Model Rocket (Pt.1)

    [...] and gyroscope package and slapped together a simple SD card interface. The libraries I used were TinyGPS and fat16lib (for SD card use). Weather_Balloon_Code and schematic in case you’d like to [...]

  20. Moving Forward with Arduino – Chapter 19 – GPS part II « t r o n i x s t u f f

    [...] forget the 10k ohm pull-down resistor). You will need to install NewSoftSerial library, TinyGPS library and the SdFat library if not already [...]

  21. Anonymous

    [...] [...]

  22. Jacket Positioning System: JPS « Titles are Strange Things

    [...] it’s pretty simple. It only does those functions, but with the help of the truly fantastic TinyGPS library, I have a destination function in the [...]

  23. Testing MTK3329 10Hz GPS module and making an Arduino GPS logger | Develop with Arduino

    [...] TinyGPS for Arduino [...]

  24. Arduino + GPS Shield + LCD 16x2 | We Are The Electric Brothers

    [...] tinygps [...]

  25. TinyGPS Libraryを使ってGPSデータを取得

    [...] ちなみに、データ処理部分は、TinyGPS Libraryなる便利なものがあったので、それを使ってみた。 [...]

  26. GPS приемник на базе модуля Quectel L30 | Arduino Market

    [...] Библиотека для работы с GPS/NMEA для Arduino (TinyGPS) [...]

  27. Using SKYLAB SKM53 GPS with Arduino

    [...] Download TinyGPS her [...]

  28. Arduino GPS module test sketch - Develop with Arduino

    [...] Working with Arduino and TinyGPS [...]

  29. Distance measuring with Arduino - Develop with Arduino

    [...] Working with Arduino and TinyGPS [...]

  30. Tutorial 15 for Arduino: GPS Tracking | JeremyBlum.com

    [...] used the tinyGPS library to decode the NMEA GPS Data. Cooking-Hacks generously supplied both the GPS shield and SD Card [...]

  31. Early Sailing Sensor designs | Andrew Hodel

    [...] the TinyGPS library: http://arduiniana.org/libraries/tinygps/ Share this: Written by andrewhodel Posted in Engineering, [...]

  32. When thinking o… | pa2dy

    [...] “TinyGPS is designed to provide most of the NMEA GPS functionality I imagine an Arduino user would want ñ position, date, time, altitude, speed and course ñ without the large size that seems to accompany similar bodies of code.  To keep resource consumption low, the library avoids any floating point dependency and ignores all but a few key GPS fields.” – TinyGPS website [...]

  33. GPS Box | pa2dy

    [...] “TinyGPS is designed to provide most of the NMEA GPS functionality I imagine an Arduino user would want ñ position, date, time, altitude, speed and course ñ without the large size that seems to accompany similar bodies of code.  To keep resource consumption low, the library avoids any floating point dependency and ignores all but a few key GPS fields.” – TinyGPS website [...]

  34. GPS Box « Sketching with Hardware

    [...] “TinyGPS is designed to provide most of the NMEA GPS functionality I imagine an Arduino user would want ñ position, date, time, altitude, speed and course ñ without the large size that seems to accompany similar bodies of code.  To keep resource consumption low, the library avoids any floating point dependency and ignores all but a few key GPS fields.” – TinyGPS website [...]

  35. Telemetría y data logger with Arduino Part IIÁlvaro López | Álvaro López

    [...] a Base y testear el alcance de las antenas, el proceso lo he ejecutado en el Base. He utilizado la librería TinyGPS que aparentemente funciona bastante bien, y los programas usados han sido los [...]

  36. Updated – WISMO228 Library for Arduino | Rocket Scream

    [...] (while adding more functionality) as we also need use the SD library for logging and also the TinyGPS library for GPS NMEA output [...]

  37. GPS Speed Display | Open Source Software Development

    [...] project makes use of the TinyGPS library. It provides a useful parsing library with easy access to the data returned by the Serial [...]

  38. Arduino + HMC6343 + u-blox MAX-6 | cjdavies.org

    [...] not hard to parse it yourself, but why go to the effort when there are libraries like TinyGPS that can do it for [...]

  39. EECS Sr Design » Blog Archive » 7. Team Bravo Squad – Prototype I Final Report: Emergency GPS Locator

    [...] the next while tweaking things. During that time, we rewrote the code (attached below) to use the TinyGPS library and wired the switch up. For the switch, it was simply a matter of connecting the common pin on the [...]

  40. Interfaceando com modulo GPS EM-411 | Alan Carvalho de Assis

    [...] Estava procurando uma biblioteca para interfacear com o modulo EM-411 mas não queria algo muito complexo, apenas algo que retornasse a distancia entre duas lat/long e o angulo entre elas. Então encontrei o projeto TinyGPS. [...]

  41. Montando o GPS | Heliostat Brasil

    [...] to interpret the information the GPS sends out ourselves as there’s a really helpful libraryTinyGPS that will do the hard work for [...]

  42. Fastrax UP501 GPS Module - Babelduck Cybernetics

    [...] Works with Arduino TinyGPS Library http://arduiniana.org/libraries/tinygps/ [...]

  43. Sketching with Hardware 2012 6/6 – GPS Box | Blog

    [...] “TinyGPS is designed to provide most of the NMEA GPS functionality I imagine an Arduino user would want ñ position, date, time, altitude, speed and course ñ without the large size that seems to accompany similar bodies of code.  To keep resource consumption low, the library avoids any floating point dependency and ignores all but a few key GPS fields.” – TinyGPS website [...]

  44. Slow progress, but progress non-the-less! | Decibear

    [...] tutorial video from Jeremy Blum to help us work out the GPS module, in which he referred us to the TinyGPS arduino library which we found lovely to use. With the help of Jeremy, and the example sketches with the library, [...]

  45. Pre-Race Telemetry Snippets | TechWeasel

    [...] TinyGPS Arduino library makes it very simple to make your GPS do something useful, much thanks… Hope [...]

  46. GPS modules for sale! | Rock 7 - RockBLOCK

    [...] is standard 9600 baud serial NMEA sentences.  There’s an excellent GPS NMEA decoder library for Arduino here which works with this [...]

  47. Data geo-tagging primer | biodesign for the real world

    [...] TinyGPS is a library for Arduino that allows to use a GPS module relatively painlessly. [...]

  48. Arduino GPS Tracking System -Arduino for Projects

    [...] used the tinyGPS library to decode the NMEA GPS Data. Cooking-Hacks generously supplied both the GPS shield and SD Card [...]

  49. Arduino GPS Datalogger -Arduino for Projects

    [...] using two really awesome libraries written by Mikal Hart, so make sure you have downloaded them! (TinyGPS and NewSoftSerial ) TinyGPS basically makes it easier for us to extract data like longitude and [...]

  50. nmea gpgga | GPS検索

    [...] TinyGPS | Arduiniana sentences – the number of valid $GPGGA and $GPRMC sentences processed; failed_checksum …. I am trying to input some proper NMEA commands but the response goes just like that. CHARS=0 …. 46 Trackbacks For This Post. เริ่มต้น สร้าง … [...]

  51. gpgga format | GPS検索

    [...] TinyGPS | Arduiniana sentences – the number of valid $GPGGA and $GPRMC sentences ….. 46 Trackbacks For This Post … and sending the bits of “Hello World” in 7N1 format. I spent … [...]

  52. My Proposal Box, Part 3: Software

    [...] click here to download it. You will also need to download the PWMServo library (version 2) and the TinyGPS library written by Mikal Hart. While you are at his site, thank him for his amazing work. If you [...]

  53. Xronos Clock Home – Time via GPS

    [...] for what I needed, and used interrupts, and other complex stuff Fortunately Time library used TinyGPS library, which is indeed very lightweight and straightforward. It also “requires” [...]

  54. Arduino en GPS | Pieters fijne blog

    [...] TinyGPS library [...]

  55. Greater Accuracy with TinyGPS 13 | Arduiniana

    [...] TinyGPS [...]

  56. GPS Bee Kit (Part 2) | Zx Lee

    [...] the next part, I am going to use one of the library available for Arduino, which is TinyGPS. You can download TinyGPS library here. This library ease your job to get all the information from [...]

  57. The Frustromantic Box, Part 4: Software | New Bright Idea

    [...] the Arduino developers for the great libraries, and to Mikal Hart in particular for his work on the TinyGPS and NewSoftSerial [...]

  58. Playing around with GPS: ATtiny GPS LongLat Logger « insideGadgets

    [...] recently purchased one of those U-blox GPS modules from Ebay for $20 and after downloading the TinyGPS library for the Arduino, it works well once it has valid GPS data (I had to have mine close to the window) [...]

  59. Módulo GPS Skylab SKM53 | AUTOMALABS

    [...] a biblioteca TinyGPS (documentação e download da v13). Requer [...]

  60. My 15$ GPS module | Bajdi.com

    [...] to the module and hooked it up to an ATmega328 running at 3.3V / 8MHz. I installed the Arduino tinygps library and uploaded one of the example sketches to the ATmega. I put my laptop, micro controller and GPS [...]

  61. 86duino

    [...] This requires the TinyGPS and NewSoftSerial libraries from Mikal Hart: http://arduiniana.org/libraries/TinyGPS and http://arduiniana.org/libraries/newsoftserial/ [...]

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

    [...] biblioteca tinyGPS sau [...]

  63. Arduino Development Journal/May 2014 | Surfing Satellites

    [...] one extra sentence that is discarded by TinyGPS (a very cool library – check it out at http://arduiniana.org/libraries/tinygps/).  I corrected that and believe the GPS delivers the optimum number of sentences at 19200 baud to [...]

  64. Tutorial – Arduino and MediaTek 3329 GPS » Geko Geek

    [...] fly, so thankfully there is an Arduino library to do this for us - TinyGPS. So head over to the library website, download and install the library before [...]

  65. Tutorial – Arduino and MediaTek 3329 GPS

    [...] fly, so thankfully there is an Arduino library to do this for us - TinyGPS. So head over to the library website, download and install the library before [...]

  66. GPS und Arduino | wer bastelt mit?

    [...] Eine recht praktische und kompakte Library zum Parsen von GPS/NMEA Daten: TinyGPS [...]

  67. Interfacing a USB GPS with an Arduino | Bayesian Adventures

    [...] Library to connect to the shield and I modified the code a little to stream incoming data into Mikal Hart’s GPS Parser Library, TinyGPS. Here is the crux of the [...]

  68. Freematics Blog – Users Guide for Arduino Telematics Kits

    [...] TinyGPS Library [...]

  69. Freematics Blog – Freematics OBD-II Adapter Programming Guide

    [...] TinyGPS Library [...]

  70. Spark Core and TinyGPS Library | devlper

    [...] comes a sample application using Spark Core and TinyGPS library. TinyGPS is a very powerful and fast NMEA GPS parser for Arduino and compatible. In this [...]

  71. Arduino UNO with GPS module(GY-GPS/NEO6MV2) - TFP

    [...] the Arduino IDE, I shall directly skip on the coding part then. Our arduino sketch will require Tiny GPS library, which you can download it from here. Import the downloaded library to your Arduino IDE. [...]

  72. GPS logging on SD card using TinyGPS | CL-UAT

    [...] tutorials are either too complex (i.e. include extra stuff like displays) or they don’t use TinyGPS or TinyGPS++ library. In the first step I’ve managed to get GPS working and displaying the [...]

  73. A cheap, functioning GPS | Denial Media

    [...] first thing I had to do software wise was install the TinyGps library. This was hard to do as the creator’s website was iffy at the time. I ended up downloading it from github and renaming it to get rid of the dash [...]

  74. GPS Tracker на ардуино своими руками | FNIT.RU

    [...] TinyGPS (ссылка на скачивание в середине страницы) [...]

  75. Arduino Time Library learning notes | tlfong01

    [...] requires the TinyGPS and NewSoftSerial libraries from Mikal Hart: http://arduiniana.org/libraries/TinyGPS and http://arduiniana.org/libraries/newsoftserial/ Example [...]

  76. Arduino (IoT): Simple Tutorial GPS Top Titan 3 Glonass: Parte 1 – Santiapps – Arduino (IoT), iOS, Android & Glass

    [...] ser parsed a datos de ubicación, velocidad etc.  Esto lo logramos usando la TinyGPS library (http://arduiniana.org/libraries/tinygps/) que veremos en la Parte [...]

  77. The SX1276 Modules Shootout – HopeRF’s RFM95W vs NiceRF’s LORA1276-C1 vs HPDTEK’s HPD13 – Rocket Scream

    [...] the base station. If a valid acknowledgement packet is received, the current GPS information (using TinyGPS library)  is retrieved from L80 GPS module and stored. Some of you might have argue why not use the full [...]

  78. Shield o Módulo GPS con Arduino Introducción - Geek Factory

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

  79. Módulo GPS Skylab SKM53 | Diário de Nilton Felipe

    [...] a biblioteca TinyGPS (documentação e download da v13). Requer [...]

  80. Tutorial Arduino: monta un GPS con reloj con Arduino - Arduino, Genuino, Raspberry Pi. Noticias y proyectos.

    [...] LCDUn módulo GPS en este caso el EM-411Breadboard, jumperwires y un potenciometro.Biblioteca TinyGPS.Enlace al tutorial completo.Califique esto Sample rating [...]

  81. Living by Numbers | nr's blog

    [...] photo you can see the GPS shield, which has now turned up. A quick bit of poking with the lovely TinyGPS library has shown that it’s giving me location data, and as a bonus, there’s a function [...]

  82. Tutorial : Reading GPS data via Arduino – DISTRIBUTOR ALAT PENGUSIR TIKUS

    [...] Library Used : http://arduiniana.org/libraries/tinygps/ [...]

Leave a Reply