Skip to content

Arduino library for the fastest and simplest communication with u-blox GPS modules

License

Notifications You must be signed in to change notification settings

jiri-jirus/UbxGps

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UbxGps

This Arduino library was developed for the fastest and simplest communication with u-blox GPS modules, which support proprietary UBX protocol that is 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 Docs directory. Also, full description of properties is accessible in the source codes.

Supported UBX packets

UBX packets supported by the library are listed below. Feel free to add other packets to the library, since the library is designed to make new packets as easy as it can be.

UbxGpsNavPosecef.h

NAV-POSECEF (Position Solution in ECEF): iTOW, ecefX, ecefY, ecefZ, pAcc.

UbxGpsNavPosllh.h

NAV-POSLLH (Geodetic Position Solution): iTOW, lon, lat, height, hMSL, hAcc, vAcc.

UbxGpsNavPvt.h

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.

UbxGpsNavSol.h

NAV-SOL (Navigation Solution Information): iTOW, fTOW, week, gpsFix, flags, ecefX, ecefY, ecefZ, pAcc, ecefVX, ecefVY, ecefVZ, sAcc, pDOP, reserved1, numSV, reserved2.

Quick Start

Download UbxGps and place it to the Arduino libraries directory. Refer to How to install 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 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);
    }
}

Note for Uno users

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.

GPS module configuration

Step 1. Wiring

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 of 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 for communicate with 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.

Wiring

Auto-configuration

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 your needs.

You are not required to follow next steps and use u-center after that, you can pass to the Checks step instead.

Auto-configuration

Step 2. Serial bridge

Let's make a bridge between GPS module and computer: upload Serial-Bridge-Uno.ino or Serial-Bridge-Mega.ino sketch on 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.

Serial bridge

Step 3. Meet u-center

For u-blox GPS module configuration we will use u-center program that you can find here. 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.

Meet u-center

Step 4. Change baudrate (if you want)

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 PC_BAUDRATE if you want and uploads it to the board. Reconnect u-center and it should works!

Change baudrate

Step 5. Change frequency (if you want)

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.

Change frequency

Step 6. Disable unnecessary channels

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.

Serial bridge

Step 7. Choose packet

UBX GPS library works with only one type of packet which is UBX, 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 UBX packet 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.

Choose packet

Step 8. Save configuration

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.

Save configuration

Step 9. Checks

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!

Checks

More details about u-blox GPS module configuration you can find in Receiver Description — Receiver Configuration in the Docs directory.

Compatible GPS modules

  • NEO-7M — tested
  • Other u-blox GPS modules, which supports UBX protocol
  • Please, notice me if it works with your GPS module

Contribution

Feel free to add something useful to this library ☺️ For example new classes for UBX packets!

Please, use the dev branch for contribution.

Links

About

Arduino library for the fastest and simplest communication with u-blox GPS modules

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C++ 100.0%