Arduino library for communicating with uBlox GPS receivers.
This library is licensed under the GPLV3. Please contact us at [email protected] to obtain other licenses.
uBlox produces standard and high precision GPS receivers with options for RTK, PPP, and multi-constellation GNSS. These receivers feature high sensitivity, minimal acquisition times, and small form factors.
This library communicates with the uBlox receivers using the UBX protocol and the UBX-NAV-PVT packet, which is available on uBlox 7 and 8 series receivers. Hardware serial is used for receiving the data packets.
Simply clone or download and extract the zipped library into your Arduino/libraries folder.
Setup your uBlox receiver to output the UBX-NAV-PVT packet. Additional setup options include the desired GPS update frequency, the serial baud rate, and the expected dynamical environment. Setup of uBlox receivers can be accomplished using the uBlox u-center software.
UBLOX(HardwareSerial& bus,uint32_t baud) A UBLOX object should be declared, specifying the hardware serial port the uBlox GPS receiver is connected to and the baud rate. The specified baud rate should match the baud rate setup in the GPS receiver configuration. For example, the following code declares a UBLOX object called gps located on the hardware serial port 1 with a baud rate of 115200:
UBLOX gps(Serial1,115200);
void begin() This should be called in your setup function. It initializes the serial communication between the microcontroller and uBlox GPS receiver. For example, the following code begins serial communication:
gps.begin();
bool readSensor() readSensor() reads data from the uBlox receiver and parses the UBX-NAV-PVT packet. When a complete packet is received with a valid checksum, readSensor() returns true. For example, placing the following code in the loop function will print the latitude, in degrees, to the screen at the GPS update frequency.
if(gps.readSensor()) {
Serial.println(gps.getLatitude_deg(),10);
}
The most recent valid packet is stored in the UBLOX object. Data fields can be retrieved using the following functions, which support both Imperial and SI units.
Imperial | SI | Description |
---|---|---|
uint32_t getTow_ms() | GPS time of week of the navigation solution, ms | |
uint16_t getYear() | UTC year | |
uint8_t getMonth() | UTC month | |
uint8_t getDay() | UTC day | |
uint8_t getHour() | UTC hour | |
uint8_t getMin() | UTC minute | |
uint8_t getSec() | UTC second | |
int32_t getNanoSec() | UTC fraction of a second, ns* | |
uint8_t getNumSatellites() | Number of satellites used in the navigation solution | |
double getLongitude_deg() | double getLongitude_rad() | Longitude |
double getLatitude_deg() | double getLatitude_rad() | Latitude |
double getEllipsoidHeight_ft() | double getEllipsoidHeight_m() | Height above the ellipsoid |
double getMSLHeight_ft() | double getMSLHeight_m() | Height above mean sea level |
double getHorizontalAccuracy_ft() | double getHorizontalAccuracy_m() | Horizontal accuracy estimate |
double getVerticalAccuracy_ft() | double getVerticalAccuracy_m() | Vertical accuracy estimate |
double getNorthVelocity_fps() | double getNorthVelocity_ms() | NED north velocity |
double getEastVelocity_fps() | double getEastVelocity_ms() | NED east velocity |
double getDownVelocity_fps() | double getDownVelocity_ms() | NED down velocity |
double getGroundSpeed_fps() | double getGroundSpeed_ms() | 2D ground speed |
double getSpeedAccuracy_fps() | double getSpeedAccuracy_ms() | Speed accuracy estimate |
double getMotionHeading_deg() | double getMotionHeading_rad() | 2D heading of motion |
double getVehicleHeading_deg() | double getVehicleHeading_rad() | 2D vehicle heading |
double getHeadingAccuracy_deg() | double getHeadingAccuracy_rad() | Heading accuracy estimate |
float getMagneticDeclination_deg() | float getMagneticDeclination_rad() | Magnetic declination |
float getMagneticDeclinationAccuracy_deg() | float getMagneticDeclinationAccuracy_rad() | Magnetic declination accuracy estimate |
float getpDOP() | Position dilution of precision | |
enum FixType getFixType() | Fix type, see below | |
enum PowerSaveMode getPowerSaveMode() | Power save mode, see below | |
enum CarrierPhaseStatus getCarrierPhaseStatus() | Carrier phase status, see below | |
bool isGnssFixOk() | Valid fix, within DOP and accuracy masks | |
bool isDiffCorrApplied() | Differential corrections were applied | |
bool isHeadingValid() | Heading of vehicle is valid | |
bool isConfirmedDate() | UTC date validity could be confirmed | |
bool isConfirmedTime() | UTC time validity could be confirmed | |
bool isTimeDateConfirmationAvail() | Info about UTC date and time validity confirmation is available | |
bool isValidDate() | Valid UTC date | |
bool isValidTime() | Valid UTC time | |
bool isTimeFullyResolved() | UTC time of day has been fully resolved, no seconds uncertainty | |
bool isMagneticDeclinationValid() | Valid magnetic declination estimate |
* The various agencies try to keep the GNSS and UTC references synchronized at the tick event of the second. Short term perturbations in clocks may result in GPS second event being ahead of or behind the UTC second event by up to a microsecond. Hence, fraction of a second may be positive or negative.
The following enum describes the fix type:
enum UBLOX::FixType | Description |
---|---|
NO_FIX | No Fix |
DEAD_RECKONING | Dead reckoning only |
FIX_2D | 2D-fix |
FIX_3D | 3D-fix |
GNSS_AND_DEAD_RECKONING | GNSS + dead reckoning combined |
TIME_ONLY | time only fix |
The following enum describes the power save modes:
enum UBLOX::PowerSaveMode | Description |
---|---|
NOT_ACTIVE | PSM is not active |
ENABLED | Enabled (an intermediate state before Acquisition state) |
ACQUISITION | Acquisition |
TRACKING | Tracking |
OPTIMIZED_TRACKING | Power optimized tracking |
INACTIVE | Inactive |
The following enum describes the carrier phase status:
enum UBLOX::CarrierPhaseStatus | Description |
---|---|
NO_SOL | No carrier phase range solution |
FLOAT_SOL | Float solution (no fixed integer carrier phase measurements used to calculate the solution) |
FIXED_SOL | Fixed solution (one or more fixed integer carrier phase range measurements used to calculate the solution) |
Please refer to your microcontroller documentation for hardware serial port pin information. For development purposes, the uBlox NEO 7P receiver available from CSG Shop and the uBlox M8 receiver available from HobbyKing were used.
For the uBlox M8 receiver available from HobbyKing, taking the red wire as pin 1, the following is the GPS receiver pinout:
Pin | Description |
---|---|
1 | Not Connected |
2 | Not Connected |
3 | 5V |
4 | RX (connect to TX) |
5 | TX (connect to RX) |
6 | GND |