Library to operate GPS 20u7 with Mbed

Dependencies:   TinyGPS mbed

GP-20U7 is a GPS receiver build-in high performances -165dBm GPS chipset. GP-20U7 provides high position, velocity and time accuracy performances as well as high sensitivity and tracking capabilities. The low power consumption makes this GPS receiver deal for most portable applications. /media/uploads/zbraun6/img_7911.jpg

This 56-channel GPS module, that supports a standard NMEA-0183 and uBlox 7 protocol, has low power consumption of 40mA@3.3V (max), an antenna on board, and -162dBm tracking sensitivity. With 56 channels in search mode and 22 channels “all-in-view” tracking, the GP-20U7 is quite the work horse for its size.


  • 56-Channel Receiver (22 Channel All-in-View)
  • Sensitivity: -162dBm
  • 2.m Positional Accuracy
  • Cold Start: 29 seconds (Open Sky)
  • 40mA @ 3.3V
  • 3 pin JST connection

This module sends six National Marine Electronics Association(NMEA) messages in the form of strings. It is standardized with NMEA 0183 . It is slowly being phased out by NMEA 2000 It is also capable of using the UBLOX protocol. The serial configuration needed for the GP-20U7 is:

Serial Configuration

  • Baud Rate = 9600
  • Data Bits = 8
  • Parity = None
  • Stop Bits = 1
  • Handshake = None



A typical output will look similar to the following: /media/uploads/zbraun6/screen_shot_2016-10-30_at_1.30.16_am.png

It is a combination of 6 different standard strings GGA, GLL, GSA, GSV, RMC, and VTG.

The NMEA string parsing can be very tricky in order to combat this I imported a library that I was familiar with from Arduino tinkering called TinyGPS.

Import libraryTinyGPS

Port of Arduino TinyGPS library to mbed. Added extra methods to flag receipt/parsing of particular sentences.

The above library has been encapsulated in the new c++ class contained in my GPS 20u7 library.

Import libraryGPS_20u7

Library to operate GPS 20u7 with Mbed

Here is the Hello World example code to use the GPS 20u7 library.


#include "gps.h"

// serial
GPS gps(p13, p14);
Serial serial_pc(USBTX, USBRX);    // tx, rx

int main() {
   serial_pc.printf("Hello World\n");

 while(1) {
               //serial_pc.printf("Serial device is here \n"); 
            serial_pc.printf("UTC: %d-%02d-%02d %02d:%02d:%02d, \n\r", gps.year, gps.month,, gps.hour, gps.minute, gps.second);
            serial_pc.printf("As doubles- Latitude: %f, Longitude: %f Altitude: %f Course: %f \n\r", gps.f_lat, gps.f_lon, gps.f_altitude, gps.f_course);
            serial_pc.printf("Speed: %f mph, %f mps, %f kmph \n\r", gps.mph, gps.mps, gps.kmph);
            serial_pc.printf("Horizontal Dilution as double: %f \n\r", gps.f_hdop);  
            serial_pc.printf("Less Precise- Latitude: %l, Longitude: %l Altitude: %l Course: %ul \n\r",, gps.lon, gps.altitude, gps.course);
            serial_pc.printf("Horizontal Dilution as long: %f \n\r", gps.hdop); 
            serial_pc.printf("Age of fix: %lu ms \n\r", gps.age); 
            serial_pc.printf("Number of Satelites: %lu Speed: %lu 1/100ths of a knot \n\r", gps.sat_count, gps.speed);  




File content as of revision 0:8a73b09fcbe6:

#include "gps.h"

GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {

bool GPS::isConnected() {
     return _gps.readable();
bool GPS::isLocked(){
void GPS::parseNMEA(){
    (void)gpsr.crack_datetime(&year, &month, &day, &hour, &minute, &second);
     sat_count = gpsr.sat_count(); 
     (void)gpsr.f_get_position(&f_lat, &f_lon, &age); //fix age in milliseoconds
     f_altitude = gpsr.f_altitude(); 
     f_course = gpsr.f_course(); //course over ground Magnetic Variation in degrees 
     f_hdop = gpsr.f_hdop(); //horizontal dilution of precision
     kmph = gpsr.f_speed_kmph();
     knots = gpsr.f_speed_knots();
     mph = gpsr.f_speed_mph();
     mps = gpsr.f_speed_mps();
     (void)gpsr.get_position(&lat, &lon, &age); //fix age in milliseoconds
     altitude = gpsr.altitude(); 
     course = gpsr.course(); //course over ground Magnetic Variation in degrees 
     hdop = gpsr.hdop(); //horizontal dilution of precision
     speed = gpsr.speed(); //speed in 100ths of a knot