Recent changes
Slingshot user guide
tag Guide, user
NFCLamp user guide
tag Guide, user
Homepage
MPL115A2
Compiler Error 42
From the mbed microcontroller Cookbook.  

MODGPS

MODGPS is an easy to use library that allows you to get basic time/date and location information from an attached GPS module.

Connecting up the GPS module

The MODGPS library only requires you to connect the TX serial out from your GPS module to one of the three available RX serial inputs on the Mbed.

Optionally, if your GPS module has a One Pulse Per Socond (1PPS) output you can connect this to any of the Mbed pins that is supported as an InterruptIn. Without this the GPS the library will return the time to within +/-0.5 of a second. However, connecting the 1PPS signal if available will increase the acuracy to +/-0.001 of a second. Note, the 1PPS output is sometimes incomaptible with the Mbed input. In this case you may need to buffer the signal using a transistor or FET. Buffering the signal will often turn a default 1PPS active leading edge to an active trailing edge. More on this later.

Connecting a GPS module

Using the MODGPS library

First, import the library into the online compiler.

ยป Import this library into a programMODGPS

Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data. New feature, added Mbed/LPC17xx RTC synchronisation

Once imported, change your projects main.cpp to:-

Code

#define COMPILE_EXAMPLE_CODE_MODGPS
#define PCBAUD 115200
#define GPSRX p25
#define GPSBAUD 9600
//#define PPSPIN p29
#include "/MODGPS/example1.cpp"

Note, please set PCBAUD to whatever you normally connect your Mbed to Pc/Mac/Linux box. The GPSBAUD is set to 9600 which is common amoung many GPS modules. If it is different set that too. The PC serial isn't required but you will get more infomation. Optionally define PPSPIN if you have connected it. If it's not connected leave the #define commented out, otherwise remove the leading comment.

Now switch everything on. LED1 should begin slowly flashing. If you connected any optional 1PPS singal then LED2 will flash once per second.

When the library receives a GPS NMEA RMC data packet LED3 flashes and when a NMEA GGA packet is received LED4 flashes.

If you have a PC connected to the USB serial port on the Mbed, additional data is displayed.

Using the MODGPS library

First, create an instance of the GPS object and pass in the RX pin it's connected to:-

Code

#include "mbed.h"
#include "GPS.h"

GSP gps(NC, p25);

Getting data from the MODGPS library is very simple. There are several ways, the simplest of them shown below.

Code

    double latitude  = gps.latitude();
    double longitude = gps.longitude();
    double altitude  = gps.altitude();

Code

    GPS_Geodetic g;
    gps.geodetic(&g);
    double latitude  = g.lat;
    double longitude = g.lon;
    double altitude  = g.alt;

Code

    GPS_Time t;
    gps->timeNow(&t);
    pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", 
            t.hour, t.minute, t.second, t.day, t.month, t.year);

The API contains many more functions such as Julian Date, Sidereal time and more. Follow the link to find the full list and documentation.




calendar Page history
Last modified 29 Dec 2010, by   user Andy Kirkham   tag GPS | 8 comments  

8 comments on MODGPS:

07 Dec 2010

Are the coordinates decimal degrees or degrees-minute-second coordinates? Very useful library by the way, works like a charm. Thanks!

29 Dec 2010

decimal degrees :)

17 Jan 2011

In your example code you connect GPSRX to p25, but this is not an UART pin. Is this a mistake?

17 Jan 2011

No, this is not a mistake. As the Serial handbook page states you can use up to three serial ports using pin pairs p9/p10, p13/p14 and/or p27/p28.

However, it's a little known fact that you can swap the pin pair p13/p14 for p26/p25 (in other words you can use a Serial with (p26, p25) but you then cannot have a serial on p13/p14). The Mbed libraries appear to take this possible swap into account. It just doesn't appear on the handbook page.

Btw, I should add, this can be a useful feature. In a recent project I needed all three serial ports AND both SPI ports. However, one SPI and one Serial both use p13 so "following the manual" you cannot have 3 Serial + 2 SPI. However, if you swap the p13/p14 to p26/p25 then you can in fact have 3 Serial + 2 SPI. In fact, p26/p25 are just documened as PwmOut pins. Imho having UART1 shown on p26/p25 is probably a better place.

17 Jan 2011
/media/uploads/AjK/pinout-standard.png/media/uploads/AjK/pinout-alternate.png
17 Jan 2011

Still nothing happens, but maybe there is just no reception. Is there a way to view the last nmea sentence?

17 Jan 2011

BTW, I attached a led-blink to the GGA string, and that works OK.

17 Jan 2011

Please use the forums to ask questions, I don't see these comments except when I come to edit the page, which is rare.

Please login to post comments.