This Arduino library was developed for the fastest and simplest communication with u-blox GPS modules, which support proprietary UBX protocol that is binary and therefore more compact than common NMEA. Main idea was to achieve real 10 Hz from NEO-7M and it was done. Huge thanks to iforce2d for a tutorial video whose code is laid in the basics of the library.
This library depends on GPS module configuration and can handle only one type of UBX packet at a time, which you can choose during GPS module configuration. UbxGps provides easy-to-use interface to all the available data in accordance with the Protocol Specification that you can find in the u-blox directory. Also, full description of properties is accessible in the source codes.
UBX packet types supported by the library are listed below. Feel free to add other packets to the library, since the library is designed to make new types as easy as it can be.
NAV-POSECEF (Position Solution in ECEF): iTOW, ecefX, ecefY, ecefZ, pAcc.
NAV-POSLLH (Geodetic Position Solution): iTOW, lon, lat, height, hMSL, hAcc, vAcc.
NAV-PVT (Navigation Position Velocity Time Solution): iTOW, year, month, day, hour, min, sec, valid, tAcc, nano, fixType, flags, reserved1, numSV, lon, lat, height, hMSL, hAcc, vAcc, velN, velE, velD, gSpeed, heading, sAcc, headingAcc, pDOP, reserved2, reserved3.
Similar to UbxGpsNavPvt.h, but for u-blox NEO-8M.
NAV-SOL (Navigation Solution Information): iTOW, fTOW, week, gpsFix, flags, ecefX, ecefY, ecefZ, pAcc, ecefVX, ecefVY, ecefVZ, sAcc, pDOP, reserved1, numSV, reserved2.
Download UbxGps
and place it to the Arduino libraries directory. Refer to
Installing Libraries for details.
Next step is configuring your GPS module properly, to find out how to do this check section GPS module configuration. Also, take a look at the Auto-configuration sketch for the Arduino Mega boards to configure your GPS module automatically to get NAV-PVT messages with 100 ms frequency and 115200 baudrate.
After that you can use included examples or play with the following simple sketch:
#include "UbxGpsNavPvt.h"
UbxGpsNavPvt<HardwareSerial> gps(Serial3);
void setup()
{
Serial.begin(9600);
gps.begin(9600);
}
void loop()
{
if (gps.ready())
{
Serial.print(gps.lon / 10000000.0, 7);
Serial.print(',');
Serial.print(gps.lat / 10000000.0, 7);
Serial.print(',');
Serial.print(gps.height / 1000.0, 3);
Serial.print(',');
Serial.println(gps.gSpeed * 0.0036, 5);
}
}
The library is designed to work with GPS module through a hardware serial port, but Uno has only one. It means that you
can configure GPS module, but the library will occupy serial port and you need to do something more to get the data from
it. For example: add an SD card to store the data, or transmit it through the Bluetooth or Ethernet. SoftwareSerial
can be used, but I can't guarantee it will work without bugs on a high frequency.
So we have an Arduino board and a GPS module. Wiring is pretty simple: GND
to GND
, VCC
to 5V
, TX
to RX
and
RX
to TX
. Because Uno has only one TX/RX pair, we should connect GPS module TX
to the 2
pin and RX
to the
3
pin and use SoftwareSerial
library to communicate with the GPS. If you have something with more than one TX/RX pair
on the board you can use it, for example for Mega we can connect GPS RX
to the TX3
and TX
to the RX3
.
After wiring you can upload the Auto-configuration sketch for the Arduino Mega boards to configure your GPS module automatically.
At the moment it configures the receiver to get NAV-PVT messages with 100 ms frequency and 115200 baudrate, but you can change it according to your needs.
This step is optional and is only needed to use u-center. If you don't want to do it, feel free to skip to Checks.
Let's make a bridge between the GPS module and the computer: upload Uno_SerialBridge.cpp or Mega_SerialBridge.cpp sketch to the board, it allows us to communicate with GPS module directly from computer. Open Serial Monitor, and if your GPS module is new or have default settings you will see something like on the picture below. If everything is OK, GPS will send some data.
For u-blox GPS module configuration we will use u-center program that you can find here (Windows only). It parses data from GPS module and provides useful tools to work with it. Launch program, choose appropriate COM port and set baudrate, 9600 for default. It will start getting some data.
If you have something with more than one TX/RX pair it will be useful to raise the baudrate of GPS module. It can helps if you gonna work with high frequency like 5 or 10 Hz. Open View — Messages View window and find UBX — CGF — PRT item. Set the baudrate to 115200 for example and click Send button at the bottom left corner.
Changing baudrate using SoftwareSerial
library can cause errors!
GPS module will stops getting data, because our sketch works with old baudrate. Disconnect from COM port in u-center,
update GPS_BAUDRATE
and COMPUTER_BAUDRATE
if you want and uploads it to the board. Reconnect u-center and it should works!
In Messages View in the UBX — CFG — RATE tab you can change Measurement Period to raise frequency of getting data. I want to achieve 10 Hz, so I change Measurement Period to the 100 milliseconds and click Send button.
To make GPS module life easier, we can disable unnecessary channels in the UBX — CFG — GNSS tab. We only need GPS, so uncheck other channels at enable column. Again, click Send to save changes.
UBX GPS library works with only one type of UBX packet, so we need to fully disable NMEA packets and enable one
of the UBX group. Open context menu on Messages View — NMEA and click Disable Child Messages. u-center will send
appropriate command to the GPS module and getting data will stops. If you're using SoftwareSerial
it can takes a time
to get things right, try to click Disable Child Messages again if it not works.
Then, choose a UBX packet type you want to work with, for example UBX — NAV — PVT, open context menu on it and click Enable Message, GPS module will start getting data again. Open View — Packet Console to see if everything is OK, it should get one type of UBX packet with chosen frequency.
Go to UBX — CFG — CFG and click Send to save current configuration.
Important! GPS module will remember what we've done, but sometimes it is not enough: GPS module can return to factory settings after a long time without power, so check your battery on the GPS module.
Close u-center and open an example NavPvt
sketch, check baudrate and upload it to the board. If everything is OK
you'll get desired data. That's all Folks!
More details about u-blox GPS module configuration are in Receiver Description — Receiver Configuration found in u-blox directory.
- NEO-7M - tested
- NEO-8M - tested
- Other u-blox GPS modules supporting UBX protocol
Please create an issue to report if you tested UbxGps with other u-blox GPS modules. Thank you!
- u-blox Website
- u-center Download page (Windows only)