WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation


A GPS sensor that interprets NMEA messages.
The sensor must be connected to a GPS device that sends NMEA messages over a serial link. You will therefore need to connect it via a UART (either a software UART or a hardware UART). The UART baud rate should be set by you - the standard value is 4800 baud but check the datasheet for your specific device.
Here is an example for a generic ATMega168 board that uses a software UART:-
#include "sys/atmega168.h"
#include "uartsw.h"
#include "NMEA/gpsNMEA.h"
// Create the software uart to listen via Timer Capture Input (ie pin B0)
SW_UART swUART = MAKE_SW_UART_BUFFERED( null, null, TIMER1, B0, null, FALSE, null,null,null);
// Create the gps and connect via the software UART at 4800 baud
GPS_NMEA myGps = MAKE_GPS_NMEA(&swUART, 4800);
// This routine is called once only and allows you to do any initialisation
// Dont use any 'clock' functions here - use 'delay' functions instead
void appInitHardware(void){
    // Initialise the GPS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
    return 0;
// This routine is called repeatedly - its your main loop
TICK_CONTROL appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
    // Call gpsNMEAprocess to upate the current readings
    // Test if we have received a msg and we have a valid satellite signal
        // We have got some valid gps data.
    return 0; // no delay - go at full speed




GPS_NMEA MAKE_GPS_NMEA(uart, baudrate)

Creates a GPS_NMEA sensor.
The first parameter is the address of a UART and the second parameter is the required baud rate. For example to use hardware UART0 at 4800 baud:

gpsNMEAinit(GPS_NMEA* gps)

Initialise the GPS.
This will set the UART to the correct baud rate and start listening for messages. It only needs to be called once - normally from appInitHardware.
If you are using Project Designer then this will be done for you.

boolean gpsNMEAprocess(GPS_NMEA* gps)

Reads the current values from the GPS sensor.
This function will return FALSE if no messages have been processed since you last called this function. Otherwise it will return TRUE.
When TRUE is returned then you can query which individual fields have been set during the call by examining the settings in the gps.info.changes.values structure. Note that just because a value has been received this doesn't mean that the GPS has got a satellite fix.
For example - if we have created a GPS receiver called 'myGPS' and we are only interested in changes to the longitude or latitude fields then we could write the following:
if( gpsNMEAprocess(&myGPS) ){
    // We have received something
        // And we have a satellite fix
        if( myGPS.gps.info.changes.values.longitude && myGPS.gps.info.changes.values.latitude){
            // Longitude and latitude have been updated - so fetch the values
            // NB It doesn't mean that the values have changed
            double longitude = myGPS.gps.info.logitude;
            double latitude = myGPS.gps.info.latitude;

Valid XHTML 1.0 Transitional