ESP8266 Peripherals: uBlox GPS Module

Almost 20 years ago when I studied a few semesters of electrical engineering at the famous ETH in Zurich I had a lecture about the basics of digital electronics. And I remember the professor doing many practical demonstrations such as drilling holes into a CD to show the quality of error correction in different price categories of CD players. I also remember that he talked about tiny and cost efficient GPS receivers that soon would be part of every cell phone (remember, 20 years ago the real age of smart phones had still been a few years away). That Professor, Gerhard Tröster, followed that vision and co-founded a company called u-blox, a non-fab producer of positioning systems with about 450 employees today. I was very excited indeed when I found a very affordable GPS module in my favourite Chines online shop, with a design by u-blox! So in this second post of my ESP8266 peripheral series I will review this module, show you how to use it with the ESP8266 and give you some ideas for applications.

uBloxGPS
The uBlox module VK2828U7G5LF for under $10

 

What is this module doing?

At least since the iPhone 3G came to the market GPS based navigation has become a commodity for many people. The global positioning system receives signals from satellites. If the signals of at least four satellites are received the position of the device can be calculated. It can do this by comparing small differences in the  time the signal took to reach the receiver. Since the satellites broadcast these signals with relatively weak signal the receiver requires direct line-of-sight to the satellites and this means pure GPS often doesn’t work well indoors.

Enough about the theory, how can the ESP8266 talk to the u-blox module? The module exposes the positioning information through a serial interface, just like the one you are using to program the ESP8266. By default it is set to 9600 baud but this value can be changed also through the serial interface. Apparently it is a very common thing that GPS modules have a serial interface and another partially standardized aspect is the message format. This module sends messages in the NMEA (0183 V3.0) format. This format knows many different types of messages, some of them are vendor specific. We are here interested in general messages. If you look directly at the serial output you will see messages like this:


$GPGSV,5,1,19,01,,,29,02,,,30,05,,,27,07,,,29*72
$GPGSV,5,2,19,08,,,23,10,,,28,12,,,32,13,,,29*7F
$GPGSV,5,3,19,15,,,26,16,,,28,18,,,27,21,,,26*71
$GPGSV,5,4,19,22,,,29,23,,,30,24,,,27,28,,,27*75
$GPGSV,5,5,19,29,,,29,33,,,30,40,,,30*75

 

Setting up the module with the ESP8266

Connecting the uBlox Module to the ESP8266
Connecting the uBlox Module to the ESP8266
PinColorESP8266
EYellow3.3V
GBlackGND
RGreenD6
TBlueD5
VRed3.3V
PWhiteN/A

Now that we have connected the u-blox module it is ready for our first code. We want to read the NMEA messages in the NodeMCU and forward them to the serial console on the PC. This code here does the trick:


#include <SoftwareSerial.h>

// if you are not using a NodeMCU but another type of ESP8266
// you might want to replace this with the correct GPIO pin numbers you used
SoftwareSerial mySerial(D5, D6); // RX, TX

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

}

void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Upload the sketch to your ESP and open the serial console. Now you should see the NMEA messages come in.
At first there might be values missing, but the more satellite signals the module receives the more complete the positioning information will be. After this first smoke test lets continue with a library that can make sense of the NMEA messages.

 

The TinyGPS+ library

By installing this library you can finally get to the core of the GPS information: latitude, longitude, altitude, speed, etc. Go to http://arduiniana.org/libraries/tinygpsplus/ and download the library, extract it to your Arduino/libraries folder and restart your Arduino IDE. Then go to File > Examples > TinyGPSPlus and open the FullExample file. Now you have to adapt the baud rate to 9600 (this is the default serial speed of our u-blox module) and change the serial pins to D5 and D6 and run the code.


static const int RXPin = D5, TXPin = D6;
static const uint32_t GPSBaud = 9600;

If you are not getting any position information you might want to get closer to the window or even go outside. Pure GPS is notoriously famous for not working indoors, due to the weak satellite signals and interference with other RF sources.

 

Application Ideas

Ok, great. Now we have a working GPS module. But what can we do with it? Here are a few ideas:

  • Bike computer: mix together an OLED display, NodeMCU, a USB power bank and the GPS module and mount everything on your bike. With a little bit of code you can display information on the OLED display such as speed, altitude and you can use way points even to some basic navigation. Store the tracking data in the EEPROM and upload it to the cloud as soon as the device detects your home device
  • War Drive Module: okay, I admit, this might not have the relevance anymore that it once had, but you could build it for less than USD $20! Wire up the GPS module and the NodeMCU and a Power Bank and bring it with you to work while it is running. Every 30 seconds or so list the SSID the NodeMCU lists through the Wifi Interface together with the location and store it in the EEPROM. Later use that information to create a map of (free?) Wifi access points
  • High precision real time clock: In order to calculate your current position the satellite send highly precise time stamps which you can read with help of the TinyGPS+ library. True, you can use the network time protocol (NTP) to fetch the current time if your ESP is connected to the internet. But if you are offline for some reason the GPS clock might be handy. You could actually implement your own NTP server, backed by the GPS module

 

Review

The module is easy to use and with less than USD $10 it was a no-brainer to order it and to try it out. The serial interface makes it very convenient to use if you have two GPIO pins to spare. Without problems I could use the SoftwareSerial module so I still could be using the hardware serial interface for debugging. While I think it is a great module for your outdoor positioning project it doesn’t work very well indoors. Nowadays we are spoiled by quickly locking GPS modules on smartphones which also perform well indoors. But be warned: the GPS module isn’t as good as that, since it cannot use information like (GSM) cell Ids or Wifi SSIDs to improve speed and accuracy of the position signal. But the module will be a great addition to your tool box for your next project (see ideas above). I forgot to mention that the GPS module has a convenient way to save energy in case you don’t need it: setting the yellow pin to LOW will basically shutdown the module completely.

Order the module now from Banggood

Posted by Daniel Eichhorn

Daniel Eichhorn is a software engineer and an enthusiastic maker. He loves working on projects related to the Internet of Things, electronics, and embedded software. He owns two 3D printers: a Creality Ender 3 V2 and an Elegoo Mars 3. In 2018, he co-founded ThingPulse along with Marcel Stör. Together, they develop IoT hardware and distribute it to various locations around the world.

10 comments

  1. Hi Simon
    Thank you! So this module has nothing to do with u-blox or “just” the chip is from u-blox and the the rest is from V.Kel? It also has been pointed out that the role of Prof. Tröster in the founding of u-blox was a different one than I stated in this post. Is that correct?
    Thanks for clearing these questions..

  2. Hello,
    what about connecting this GPS-module with your weather station? And adapting the software of the weatherstation to use the data from the GPS-module to get the weather from just this place you are?
    Would this be possible with the wunderground API?
    This would be a nice package: The weatherstation, the GPS-module and a powerbank.
    Best regards

    • Hi Thomas. Cool idea, maybe slightly over-engineered:-). How would you use it? The code would not need the city and country anymore but you would still be tied to your WiFi. Anyhow, it looks like this is possible: https://www.wunderground.com/weather/api/d/docs?d=data/index

      In order to do it just copy the wunderground client class and adapt it to accept coordinates instead of city/country…

      Cheers,
      Dani

      • Hello Dani,

        thx for your answer. You are right, this package needs WiFi. So the next step could be using the WiFiManager to connect…
        If I find enough time I will give it a try!
        BTW: Thanks a lot for your work with the WeatherStation and the OLED-display! To honour your efforts I placed an order at your shop (WeMos + OLED).
        Best regards
        Thomas

  3. Hello,
    I have bought one of these GPS devices from your store. It works perfectly with your code but does not seem to work with the TinyGPS class – I have made the pin and baud rate changes but it simply says that no GPS is connected. Any clues? Southern hemishpere problem?? Thanks in advance ..

Leave a Reply