Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SparkFun Ublox Arduino Library
===========================================================

Added support for parsing date and time. See Example14_GetDateTime.

<table class="table table-hover table-striped table-bordered">
<tr align="center">
<td><a href="https://www.sparkfun.com/products/15136"><img src="https://cdn.sparkfun.com//assets/parts/1/3/5/1/4/15136-SparkFun_GPS-RTK2_Board_-_ZED-F9P__Qwiic_-03.jpg"></a></td>
Expand Down
98 changes: 98 additions & 0 deletions examples/Example14_GetDateTime/Example14_GetDateTime.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Reading lat and long via UBX binary commands - no more NMEA parsing!
By: Nathan Seidle
SparkFun Electronics
Date: January 3rd, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to query a Ublox module for its lat/long/altitude. We also
turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic
dramatically.

Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
to something google maps understands simply divide the numbers by 10,000,000. We
do this so that we don't have to use floating point numbers.

Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!

Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106

Hardware Connections:
Plug a Qwiic cable into the GPS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/

#include <Wire.h> //Needed for I2C to GPS

#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;

long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.

void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}

myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
}

void loop()
{
//Query module only every second. Doing it more often will just cause I2C traffic.
//The module only responds when a new position is available
if (millis() - lastTime > 1000)
{
lastTime = millis(); //Update the timer

long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));

long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));

byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);

Serial.println();
Serial.print(myGPS.getYear());
Serial.print("-");
Serial.print(myGPS.getMonth());
Serial.print("-");
Serial.print(myGPS.getDay());
Serial.print("T");
Serial.print(myGPS.getHour());
Serial.print(":");
Serial.print(myGPS.getMinute());
Serial.print(":");
Serial.println(myGPS.getSecond());


Serial.println();
}
}
77 changes: 73 additions & 4 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
Development environment specifics:
Arduino IDE 1.8.5

Modified by David Mann @ Loggerhead Instruments, 16 April 2019
- Added support for parsing date and time
- Added functions getYear(), getMonth(), getDay(), getHour(), getMinute(), getSecond()

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Expand All @@ -26,6 +30,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "SparkFun_Ublox_Arduino_Library.h"

SFE_UBLOX_GPS::SFE_UBLOX_GPS(void)
Expand Down Expand Up @@ -443,7 +448,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
//If a UBX_NAV_PVT packet comes in asynchronously, we need to fudge the startingSpot
uint16_t startingSpot = incomingUBX->startingSpot;
if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
startingSpot = 20;
startingSpot = 0;
//Begin recording if counter goes past startingSpot
if( (incomingUBX->counter - 4) >= startingSpot)
{
Expand Down Expand Up @@ -474,12 +479,22 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)

case UBX_CLASS_NAV:
if (msg->id == UBX_NAV_PVT && msg->len == 92)
{
{

//Parse various byte fields into global vars
constexpr int startingSpot = 20; //fixed value used in processUBX
constexpr int startingSpot = 0; //fixed value used in processUBX

gpsYear = extractInt(4);
gpsMonth = extractByte(6);
gpsDay = extractByte(7);
gpsHour = extractByte(8);
gpsMinute = extractByte(9);
gpsSecond = extractByte(10);


fixType = extractByte(20 - startingSpot);
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
SIV = extractByte(23 - startingSpot);
SIV = extractByte(23);
longitude = extractLong(24 - startingSpot);
latitude = extractLong(28 - startingSpot);
altitude = extractLong(32 - startingSpot);
Expand All @@ -489,6 +504,12 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
pDOP = extractLong(76 - startingSpot);

//Mark all datums as fresh (not read before)
moduleQueried.gpsYear = true;
moduleQueried.gpsMonth = true;
moduleQueried.gpsDay = true;
moduleQueried.gpsHour = true;
moduleQueried.gpsMinute = true;
moduleQueried.gpsSecond = true;
moduleQueried.all = true;
moduleQueried.longitude = true;
moduleQueried.latitude = true;
Expand Down Expand Up @@ -1106,6 +1127,54 @@ uint8_t SFE_UBLOX_GPS::extractByte(uint8_t spotToStart)
return(payloadCfg[spotToStart]);
}

//Get the current year
uint16_t SFE_UBLOX_GPS::getYear(uint16_t maxWait)
{
if(moduleQueried.gpsYear == false) getPVT();
moduleQueried.gpsYear = false; //Since we are about to give this to user, mark this data as stale
return(gpsYear);
}

//Get the current month
uint8_t SFE_UBLOX_GPS::getMonth(uint16_t maxWait)
{
if(moduleQueried.gpsMonth == false) getPVT();
moduleQueried.gpsMonth = false; //Since we are about to give this to user, mark this data as stale
return(gpsMonth);
}

//Get the current year
uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
{
if(moduleQueried.gpsDay == false) getPVT();
moduleQueried.gpsDay = false; //Since we are about to give this to user, mark this data as stale
return(gpsDay);
}

//Get the current year
uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
{
if(moduleQueried.gpsHour == false) getPVT();
moduleQueried.gpsHour = false; //Since we are about to give this to user, mark this data as stale
return(gpsHour);
}

//Get the current year
uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
{
if(moduleQueried.gpsMinute == false) getPVT();
moduleQueried.gpsMinute = false; //Since we are about to give this to user, mark this data as stale
return(gpsMinute);
}

//Get the current year
uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
{
if(moduleQueried.gpsSecond == false) getPVT();
moduleQueried.gpsSecond = false; //Since we are about to give this to user, mark this data as stale
return(gpsSecond);
}

//Get the latest Position/Velocity/Time solution and fill all global variables
boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
{
Expand Down
21 changes: 21 additions & 0 deletions src/SparkFun_Ublox_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ class SFE_UBLOX_GPS
int32_t getGroundSpeed(uint16_t maxWait = 250); //Returns speed in mm/s
int32_t getHeading(uint16_t maxWait = 250); //Returns heading in degrees * 10^-7
uint16_t getPDOP(uint16_t maxWait = 250); //Returns positional dillution of precision * 10^-2
uint16_t getYear(uint16_t maxWait = 250);
uint8_t getMonth(uint16_t maxWait = 250);
uint8_t getDay(uint16_t maxWait = 250);
uint8_t getHour(uint16_t maxWait = 250);
uint8_t getMinute(uint16_t maxWait = 250);
uint8_t getSecond(uint16_t maxWait = 250);



//Port configurations
boolean setPortOutput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = 250); //Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
Expand Down Expand Up @@ -273,6 +281,13 @@ class SFE_UBLOX_GPS
} svin;

//The major datums we want to globally store
uint16_t gpsYear;
uint8_t gpsMonth;
uint8_t gpsDay;
uint8_t gpsHour;
uint8_t gpsMinute;
uint8_t gpsSecond;

int32_t latitude; //Degrees * 10^-7 (more accurate than floats)
int32_t longitude; //Degrees * 10^-7 (more accurate than floats)
int32_t altitude; //Number of mm above ellipsoid
Expand Down Expand Up @@ -350,6 +365,12 @@ class SFE_UBLOX_GPS
//This reduces the number of times we have to call getPVT as this can take up to ~1s per read
//depending on update rate
struct {
uint16_t gpsYear: 1;
uint16_t gpsMonth: 1;
uint16_t gpsDay: 1;
uint16_t gpsHour: 1;
uint16_t gpsMinute: 1;
uint16_t gpsSecond: 1;
uint16_t all : 1;
uint16_t longitude : 1;
uint16_t latitude : 1;
Expand Down