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.

Features

  • 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 https://en.wikipedia.org/wiki/NMEA_0183 . It is slowly being phased out by NMEA 2000 https://en.wikipedia.org/wiki/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

/media/uploads/zbraun6/screen_shot_2016-10-30_at_1.40.23_am.png

/media/uploads/zbraun6/img_7910.jpg

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.

main.cpp

#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) {
           if(gps.isConnected()){
               //serial_pc.printf("Serial device is here \n"); 
               if(gps.isLocked()){
                   gps.parseNMEA();
                    
            serial_pc.printf("UTC: %d-%02d-%02d %02d:%02d:%02d, \n\r", gps.year, gps.month, gps.day, 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.lat, 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);  
            wait(5);  
        }
    }
}
}

Demo

Files at this revision

API Documentation at this revision

Comitter:
zbraun6
Date:
Sun Oct 30 05:15:44 2016 +0000
Commit message:
push;

Changed in this revision

TinyGPS.lib Show annotated file Show diff for this revision Revisions of this file
gps.cpp Show annotated file Show diff for this revision Revisions of this file
gps.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8a73b09fcbe6 TinyGPS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TinyGPS.lib	Sun Oct 30 05:15:44 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/shimniok/code/TinyGPS/#f522b8bdf987
diff -r 000000000000 -r 8a73b09fcbe6 gps.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gps.cpp	Sun Oct 30 05:15:44 2016 +0000
@@ -0,0 +1,41 @@
+#include "gps.h"
+
+
+GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
+    _gps.baud(9600);
+            
+}
+
+bool GPS::isConnected() {
+     
+     return _gps.readable();
+     
+    }
+    
+bool GPS::isLocked(){
+        
+        return(gpsr.encode(_gps.getc()));
+        
+        }
+        
+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   
+}    
\ No newline at end of file
diff -r 000000000000 -r 8a73b09fcbe6 gps.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gps.h	Sun Oct 30 05:15:44 2016 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "TinyGPS.h"
+
+#ifndef MBED_GPS_H
+#define MBED_GPS_H
+
+ 
+/**  A GPS interface for reading from a Globalsat EM-406 GPS Module */
+class GPS {
+public:
+ 
+    /** Create the GPS interface, connected to the specified serial port
+     */    
+    GPS(PinName tx, PinName rx);
+    
+    //Checks if GPS (Serial Object) is connected
+    bool isConnected();
+    
+    //Does GPS Module have lock on satellite
+    bool isLocked();
+    
+    //parses incoming NMEA standard strings from GPS Module 
+    void parseNMEA(); 
+    
+    double f_lat, f_lon, f_altitude, f_course, knots,mph, mps,kmph, f_hdop;
+    
+    long lat, lon, altitude, hdop; 
+    
+    unsigned long course, age; //how long a fix has lasted to satellite in ms
+    
+    int year;
+    byte month, day, hour, minute, second;
+    
+    unsigned long sat_count,speed;
+    
+     
+private:
+
+Serial _gps; 
+
+TinyGPS gpsr;
+  
+ 
+};
+ 
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8a73b09fcbe6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 30 05:15:44 2016 +0000
@@ -0,0 +1,33 @@
+#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) {
+           if(gps.isConnected()){
+               //serial_pc.printf("Serial device is here \n"); 
+               if(gps.isLocked()){
+                   gps.parseNMEA();
+                    
+            serial_pc.printf("UTC: %d-%02d-%02d %02d:%02d:%02d, \n\r", gps.year, gps.month, gps.day, 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.lat, 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);  
+            wait(5);  
+        }
+    }
+}
+}
diff -r 000000000000 -r 8a73b09fcbe6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 30 05:15:44 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0
\ No newline at end of file