TinyGPS

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.

Usage

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();

Statistics

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!");
else
  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.

Download

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.

Acknowledgements

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

    10 years ago

    @Fernando, perhaps your baud rate is wrong? The sample code uses 4800 as a common default, but there are many devices out there that work at higher rates.

    It’s a good debug technique to print out the characters as they arrive just to see if they look reasonable:

    char c = ss.read();
    Serial.write(c);
    

  2. Amin

    10 years ago

    Does anyone know if there is any C library for this sensor?
    I’d like top integrate it to CoIDE/Coocox for stm32f4.
    Thanks,
    Amin


  3. Mikal

    10 years ago

    @Amin,

    This library isn’t tied to any particular sensor. It’s a generic NMEA GPS parsing library. It’s only thinly tied to Arduino (via the dependence on millis()), and could be ported to C fairly easily.


  4. Fernando

    10 years ago

    Thanks replay
    I have changed the “ss” baud rate to 9600/38400 But nothing change
    The only device I used is just the GPS module and an arduino uno
    Did I miss something?
    Thank you in advance.


  5. Mulham Harrasi

    10 years ago

    hello guys,
    I need HELP to program Arduino to get Lat and Long from GPS em406 with the following parts: EM406 GPS without shield, Arduino UNO,LCD 18×2, potentiometre and circuit board.

    My question: can I use GPS with out SD shield??

    Urgent please !!


  6. John

    10 years ago

    Hello, I am having a problem with this code. My IDE keeps giving me errors compiling. Last one was, “expected constructor, destructor or type conversion before ” token” I have added the library as required. From the IDE, I can see it in the File > Examples. However, from C: drive, it was not there. So I added it manually. To begin with, it would not add it to library because of dash character. I had to rename it just to get it to add. My version of Arduino IDE is 1.0.5. Any help is greatly appreciated. Thank you.


  7. Pete

    10 years ago

    I am using a ITEAD studio GPS shield V1.1 with an Arduino Uno R3. Both are recent purchases.
    I am using the code:

    #include

    #include

    /* This sample code demonstrates the normal use of a TinyGPS object.
    It requires the use of SoftwareSerial, and assumes that you have a
    4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
    */

    TinyGPS gps;
    SoftwareSerial ss(3,4);

    void setup()
    {
    Serial.begin(115200);
    ss.begin(38400);

    Serial.print(“Simple TinyGPS library v. “); Serial.println(TinyGPS::library_version());
    Serial.println(“by Mikal Hart”);
    Serial.println();
    }

    void loop()
    {
    bool newData = false;
    unsigned long chars;
    unsigned short sentences, failed;

    // For one second we parse GPS data and report some key values
    for (unsigned long start = millis(); millis() – start < 1000;)
    {
    while (ss.available())
    {
    char c = ss.read();
    Serial.write(c); // uncomment this line if you want to see the GPS data flowing
    if (gps.encode(c)) // Did a new valid sentence come in?
    newData = true;
    }
    }

    if (newData)
    {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
    }

    gps.stats(&chars, &sentences, &failed);
    Serial.print(" CHARS=");
    Serial.print(chars);
    Serial.print(" SENTENCES=");
    Serial.print(sentences);
    Serial.print(" CSUM ERR=");
    Serial.println(failed);
    }

    It took a while, but I figured out the RX, TX numbers had to be from the perspective of the Uno – so mine are (3,4).
    I also found that the GPS shield wishes to communicate at 38,400 BPS.
    The antenna is outdoors and has an unobstructed view of the sky. The output below was obtained after a 30 minute period.

    When set this way, I do get output, but not correct sentences. By adding the Serial.write (c) line, I can list the output, which seems to lack the checksum and occasionally the terminating CR, I think. There is only one sentence type ($GPRMC) received. Is this normal? Does it indicate no fix?

    Any help solving the problem would be appreciated.

    Here's a sample of the output:

    Simple TinyGPS library v. 13
    by Mikal Hart

    $GPRMC,182149.00,A,4308.16235,N,07344.93820,W,0.010,,010114,,,D1L CHARS=65 SENTENCES=0 CSUM ERR=0
    $GPRMC,182150.00,A,4308.16242,N,07344.93820,W,0.010,,010114,,,D61$GPRMC,182151.00,A,4308.16247,N,07344.93819,W,0.039,,010114,,,D4 CHARS=194 SENTENCES=0 CSUM ERR=0
    $GPRMC,182152.00,A,4308.16257,N,07344.93821,W,0.025,,010114,,,D, CHARS=258 SENTENCES=0 CSUM ERR=0
    $GPRMC,182153.00,A,4308.16264,N,07344.93822,W,0.021,,010114,,,D, CHARS=322 SENTENCES=0 CSUM ERR=0
    $GPRMC,182154.00,A,4308.16270,N,07344.93822,W,0.005,,010114,,,D, CHARS=386 SENTENCES=0 CSUM ERR=0
    $GPRMC,182155.00,A,4308.16274,N,07344.93823,W,0.036,,010114,,,D
    3 CHARS=451 SENTENCES=0 CSUM ERR=0
    $GPRMC,182156.00,A,4308.16279,N,07344.93827,W,0.011,,010114,,,DD4 CHARS=516 SENTENCES=0 CSUM ERR=0
    $GPRMC,182157.00,A,4308.16286,N,07344.93834,W,0.020,,010114,,,D33$GPRMC,182158.00,A,4308.16290,N,07344.93836,W,0.023,,010114,,,D24 CHARS=646 SENTENCES=0 CSUM ERR=0
    $GPRMC,182159.00,A,4308.16291,N,07344.93831,W,0.057,,010114,,,D2 CHARS=710 SENTENCES=0 CSUM ERR=0
    $GPRMC,182200.00,A,4308.16289,N,07344.93826,W,0.036,,010114,,,D01 CHARS=775 SENTENCES=0 CSUM ERR=0
    $GPRMC,182201.00,A,4308.16287,N,07344.93822,W,0.014,,010114,,,DV CHARS=839 SENTENCES=0 CSUM ERR=0
    $GPRMC,182202.00,A,4308.16284,N,07344.93818,W,0.013,,010114,,,D, CHARS=903 SENTENCES=0 CSUM ERR=0
    $GPRMC,182203.00,A,4308.16280,N,07344.93814,W,0.010,,010114,,,D01$GPRMC,182204.00,A,4308.16274,N,07344.93808,W,0.040,,010114,,,D61 CHARS=1033 SENTENCES=0 CSUM ERR=0
    $GPRMC,182205.00,A,4308.16265,N,07344.93804,W,0.034,,010114,,,D2 CHARS=1097 SENTENCES=0 CSUM ERR=0
    $GPRMC,182206.00,A,4308.16258,N,07344.93801,W,0.038,,010114,,,D6L CHARS=1162 SENTENCES=0 CSUM ERR=0
    $GPRMC,182207.00,A,4308.16250,N,07344.93797,W,0.022,,010114,,,D0A CHARS=1227 SENTENCES=0 CSUM ERR=0


  8. Mikal

    10 years ago

    @Mulham Harrasi,

    All you need to get the EM406 to work is 4 connections to the Arduino: +5V and GND, then two pins for TX and RX. No shield required if you can manage to connect to the tiny connector on the GPS module.


  9. Mikal

    10 years ago

    @John,

    Yeah, it’s annoying that a github archive necessarily has a dash in the name, but an Arduino library must NOT have one. But if you unzip it, rename it simply to “TinyGPSPlus”, then place that folder under the “libraries” folder, i.e. at the same level as, say, LiquidCrystal, you should be good.


  10. Mikal

    10 years ago

    @Pete,

    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?


  11. Peter

    10 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?


  12. Pete

    10 years ago

    Mikal:

    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?

    Peter


  13. Mikal

    10 years ago

    @Pete,

    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.


  14. Pete

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


  15. Pete

    10 years ago

    Mikal:

    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.

    Pete


  16. Randy

    10 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
    ss.flush();
    delay(50);

    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.
    http://ukhas.org.uk/guides:ublox6#software_serial_configuration_example

    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.


  17. Mikal

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


  18. Peter

    10 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:

    #include

    // 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.begin(38400);
    Serial.println(“AltSoftSerial Test Begin”);
    altSerial.begin(38400);
    altSerial.println(“Hello World”);
    }

    void loop() {
    char c;

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

    Hope this helps.


  19. Mikal

    10 years ago

    @Peter,

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


  20. Matt

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


  21. Brendan

    10 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?

    Thanks


  22. Mikal

    10 years ago

    @Brendan,

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


  23. T Arnerich

    10 years ago

    Mikal,

    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.


  24. Mikal

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


  25. Tim

    10 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


  26. john

    10 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


  27. Mikal

    10 years ago

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


  28. Nagaraj

    10 years ago

    Hello.,
    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.


  29. Brian

    10 years ago

    Hi!

    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)

    Thanks!


  30. Racheney

    10 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?


  31. Antonio Ladeia

    10 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…


  32. Kevin

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


  33. Nic

    10 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?


  34. Mikal

    10 years ago

    @Kevin,

    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?


  35. Kevin

    10 years ago

    @Mikal,

    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.


  36. Mikal

    10 years ago

    @Kevin–

    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?


  37. Aaron Hall

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

    Thanks,
    @AaronHAll


  38. sherbahdur

    10 years ago

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


  39. Mikal

    10 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
    }
    

  40. Syah

    10 years ago

    Hello,

    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.


  41. Joe

    10 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:

    4137228,-8142981,25760,30,29900,170514,16013800
    4137228,-8142981,25760,30,29900,170514,16013800
    4137227,-8142980,25740,106,29612,170514,16014000

    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?

    Thanks,
    Joe


  42. Joe

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

    Thanks,
    Joe


  43. Robin

    10 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?

    Thanks


  44. Mikal

    10 years ago

    @Joe,

    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.


  45. Mikal

    10 years ago

    @Joe,

    Ah! Great solution!


  46. Mikal

    10 years ago

    @Robin,

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


  47. Robin

    10 years ago

    @Mikal

    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

3 Trackbacks For This Post
  1. 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 […]

  2. 86duino

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

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

    […] biblioteca tinyGPS sau […]

Leave a Reply