Library for Libelium’s GPS module

dcuartiellesApril 21st, 2009

I have been a little slow the last two months in reporting about my Xmass presents. Being on parental leave but being forced to arrange the moving of my lab to a new building seem to be two incompatible actions, but they are perfectly possible here in Sweden.

GPS on Mega

(c) 2009 BlushingBoy, GPS Shield on Arduino Mega

Leaving excuses on the side, I got a little jealous about Tom posting how he uses the Mega; therefore I decided to push a little harder for a library I am writing for the guys at Libelium. They sent me their GPS module and I decided to make a simple wrapper for users to plug their Tyco-GPS modules to Arduino Diecimila/Duemilanove/Mega from Arduino’s IDE 13/14/15. This is how much the whole thing has evolved since I started writing this piece of code in January… every time I thought I was done, we would release a new board or a new IDE and I had to debug the thing.

The library is running on a modified version of SoftwareSerial, and uses two functions by M. Hart, who wrote the brilliant tinyGPS library. My goal was to make something where unexperienced users would just have to write something like “GPS.init()” and “Serial.println(GPS.getLongitude())” and the thing would just work. Depending on how much you use the serial communication, this library weights between 4KB and 9KB … but it does everything for you ;-) On the other hand, on the Arduino Mega, 9KB is not even 10% of the available memory space. Download the library directly from this link.

GPS on Duemilanove

(c) 2009 BlushingBoy, GPS Shield on Arduino Duemilanove

I crafted three examples (basic, medium, advanced) featuring the use of different techniques to parse the GPS sentences. If you write something like a data logger, or a GPS toy, post your link here and I will be more than happy to include your code in the next revision of the library. Of course, if you found any errors or made any improvements, do the same thing.

This code compiles for Duemilanove and Mega, without any alterations. It works fine with the processors ATmega168 and up. Uses about 300 Bytes of memory space and is documented inside the code. Ah … there is a README.txt you shouldn’t miss; it explains how NOT to use the library.

[NOTE: If you are a linux user, please remember there is a bug in GCC-AVR that affects the way long ints are multiplied and this library makes an extensive use of that type of numbers. Please, read this note on Arduino's playground and upgrade!!]

15 Responses to “Library for Libelium’s GPS module”

  1. Helvis Says:

    I received today my shield and tried it with Arduino Diecimila. Works great. I only have some doubts with the third example about what means each one of the arguments. Have to read the rest of the specs.
    Now I am going to apply it to a robot and to use the gps info to produce some visuals.
    Thanks for the great work.

  2. Weekly Shared Items - 24. April, 2009 | toxin 2.0 - weblog of a german design student from wuerzburg Says:

    [...] Library for Libelium’s GPS module [...]

  3. dcuartielles Says:

    Hej Helvis,

    the third example is just parsing the GPS data into different arguments as specified in the datasheet to the GPS module. It is actually the standard way GPS data is stored in a string. This means:

    - arguments[0] is always the GPS sencence type, e.g. GPGGA, GPRMC, GPVTG …
    - arguments[1..12] are each one of the parts coming in the GPS sentence separated by commas. They depend on each one of the strings

    If you are just interested in getting the speed, you could call the function GPS.getSpeed() and it will answer with an integer for the speed in Km/h. I think I actually forgot to mention that in the examples. For the location there is GPS.getLocation() and so on.

  4. carlos Says:


    I have a Arduino Duemilanove connected to a Libelium GPS (
    I am accessing the GPS through the LB_GPS library Version 01a
    I am developing a small program (I am quite noob with Arduino) to read the data from the GPS and to show it in a LCD display.
    While I am connected to the computer through the USB port everything the GPS seems to work fine, I receive NMEA strings as expected.
    The problem comes when I want to power the system through batteries, not through the USB port.
    I disconnect the USB cable, reset the Arduino and everything goes running until the program tries to read data from the GPS. Then it is blocked.
    The following code shows what happens: working with a USB connection you can see at the display the strings “GETRAW IN” and “GETRAW OUT” swapping every 5 seconds approx.
    When the Arduino is powered through batteries the display shows one time “GETRAW IN” and the program hangs.

    Any idea on where is the problem?

    Thanks in advance


    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

    void setup()



    void loop()
    Visualiza(“GETRAW IN “);
    GPS.getRaw(100); // reads the GPS string and stores it in inBuffer
    Visualiza(“GETRAW OUT “);

    void Visualiza(const char *s1)
    lcd.print(” “);


  5. antonio Says:

    Estoy intentando conectar una duemilanove con el gps. He cambiado los pines 8 y 9 por el 1 y 0 de la librería. Sólo me aparace : setting up gps… done! pero no recibo nada más. Alguien me puede ayudar

  6. antonio Says:

    Ya funciona.

  7. Alejandro Says:

    A mí me ocurre lo mismo, ¿cómo lo arreglaste?

  8. antonio Says:

    Es por que no conecta con los satélites. Mete el módulo y el arduino en una fiambrera y lo pones en la calle sin que le haga sombra ningún edificio

  9. Angel Says:

    Pero con qué codigo lo haceis funcionar?

  10. Alfonso Says:

    Ponte en contacto conmigo porque hay un bug en la función GPSStringExplode() y te paso el fix.

  11. Alfonso Says:

    Lo dicho en el comentario anterior: ponte en contacto conmigo. He encontrado bastantes más bugs, así que te paso los fixes.
    Borra también mis comentarios. Utilizo este blog para ponerme en contacto contigo porque no he encontrado otra manera.

  12. Funcionamiento del GPS « Pfcan's Blog Says:

    [...] los datos del GPS se utilizará la libería(descargar) que pone a disposición Libelium, creada por D. Cuartielles, que ya provee las funciones necesarias para la comunicación serie por el puerto 8 y 9. A pesar de [...]

  13. avenue33 Says:


    • A mi me ocurre un problema de memoria con la versión el inicio se repite sin fin.

    Setting up GPS… done!
    LB_GPS 01a, (c) 2009 Cuartielles for

    Setting up GPS… done!
    LB_GPS 01a, (c) 2009 Cuartielles for

    • Otro problema, la conexión serie se come bytes. ¿Cómo podría utilizar la librería NewSoftSerial, que funciona de maravilla?


  14. dcuartielles Says:


    esa libreria – LB_GPS – la cree para Libelium en el 2009, y no esta revisada para la version actual del core de Arduino. En otras palabras, la cree para (hablo de memoria) Arduino 0012 y ahora andamos por Arduino 0022. Si has adquirido un producto de Libelium, te recomiendo que te pongas en contacto con ellos, tienen un buen soporte tecnico y te ayudaran con el tema.

    Por otra parte, decirte que este tipo de preguntas debieras preguntarlas en el foro de Arduino, el blog no es el mejor sitio para ellos ;-)

    Un saludo,


  15. Proyecto de Fin de Carrera de Alfonso Nishikawa : Funcionamiento del GPS Says:

    [...] los datos del GPS se utilizará la libería de Libelium (descargar la mía modificada) creada por D. Cuartielles, que ya provee las funciones necesarias para la comunicación serie por el puerto 8 y 9. A pesar de [...]