Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit d7f9b50

Browse files
committed
Merging PR 14.
1 parent 5e80910 commit d7f9b50

File tree

4 files changed

+258
-69
lines changed

4 files changed

+258
-69
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Thanks to:
2727
* We are always interested in adding SPI support with a checkUbloxSPI() function
2828
* [trycoon](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/pull/7) for fixing the lack of I2C buffer length defines
2929
* [tve](https://github.com/tve) for building out serial additions and examples
30+
* [Redstoned](https://github.com/Redstoned) and [davidallenmann](https://github.com/davidallenmann) for adding PVT date and time
3031

3132
Need a library for the Ublox and Particle? Checkout the [Particle library](https://github.com/aseelye/SparkFun_Ublox_Particle_Library) fork.
3233

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Getting time and date using Ublox commands
3+
By: davidallenmann
4+
SparkFun Electronics
5+
Date: April 16th, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to query a Ublox module for the current time and date. We also
10+
turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic
11+
dramatically.
12+
13+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
14+
15+
Feel like supporting open source hardware?
16+
Buy a board from SparkFun!
17+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
18+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
19+
SAM-M8Q: https://www.sparkfun.com/products/15106
20+
21+
Hardware Connections:
22+
Plug a Qwiic cable into the GPS and a BlackBoard
23+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
24+
Open the serial monitor at 115200 baud to see the output
25+
*/
26+
27+
#include <Wire.h> //Needed for I2C to GPS
28+
29+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
30+
SFE_UBLOX_GPS myGPS;
31+
32+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
33+
34+
void setup()
35+
{
36+
Serial.begin(115200);
37+
while (!Serial)
38+
; //Wait for user to open terminal
39+
Serial.println("SparkFun Ublox Example");
40+
41+
Wire.begin();
42+
43+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
44+
{
45+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
46+
while (1)
47+
;
48+
}
49+
50+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
51+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
52+
}
53+
54+
void loop()
55+
{
56+
//Query module only every second. Doing it more often will just cause I2C traffic.
57+
//The module only responds when a new position is available
58+
if (millis() - lastTime > 1000)
59+
{
60+
lastTime = millis(); //Update the timer
61+
62+
long latitude = myGPS.getLatitude();
63+
Serial.print(F("Lat: "));
64+
Serial.print(latitude);
65+
66+
long longitude = myGPS.getLongitude();
67+
Serial.print(F(" Long: "));
68+
Serial.print(longitude);
69+
Serial.print(F(" (degrees * 10^-7)"));
70+
71+
long altitude = myGPS.getAltitude();
72+
Serial.print(F(" Alt: "));
73+
Serial.print(altitude);
74+
Serial.print(F(" (mm)"));
75+
76+
byte SIV = myGPS.getSIV();
77+
Serial.print(F(" SIV: "));
78+
Serial.print(SIV);
79+
80+
Serial.println();
81+
Serial.print(myGPS.getYear());
82+
Serial.print("-");
83+
Serial.print(myGPS.getMonth());
84+
Serial.print("-");
85+
Serial.print(myGPS.getDay());
86+
Serial.print(" ");
87+
Serial.print(myGPS.getHour());
88+
Serial.print(":");
89+
Serial.print(myGPS.getMinute());
90+
Serial.print(":");
91+
Serial.println(myGPS.getSecond());
92+
93+
Serial.println();
94+
}
95+
}

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
466466
//If a UBX_NAV_PVT packet comes in asynchronously, we need to fudge the startingSpot
467467
uint16_t startingSpot = incomingUBX->startingSpot;
468468
if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
469-
startingSpot = 20;
469+
startingSpot = 0;
470470
//Begin recording if counter goes past startingSpot
471471
if ((incomingUBX->counter - 4) >= startingSpot)
472472
{
@@ -501,7 +501,15 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
501501
if (msg->id == UBX_NAV_PVT && msg->len == 92)
502502
{
503503
//Parse various byte fields into global vars
504-
constexpr int startingSpot = 20; //fixed value used in processUBX
504+
constexpr int startingSpot = 0; //fixed value used in processUBX
505+
506+
gpsYear = extractInt(4);
507+
gpsMonth = extractByte(6);
508+
gpsDay = extractByte(7);
509+
gpsHour = extractByte(8);
510+
gpsMinute = extractByte(9);
511+
gpsSecond = extractByte(10);
512+
505513
fixType = extractByte(20 - startingSpot);
506514
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
507515
SIV = extractByte(23 - startingSpot);
@@ -514,6 +522,13 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
514522
pDOP = extractLong(76 - startingSpot);
515523

516524
//Mark all datums as fresh (not read before)
525+
moduleQueried.gpsYear = true;
526+
moduleQueried.gpsMonth = true;
527+
moduleQueried.gpsDay = true;
528+
moduleQueried.gpsHour = true;
529+
moduleQueried.gpsMinute = true;
530+
moduleQueried.gpsSecond = true;
531+
517532
moduleQueried.all = true;
518533
moduleQueried.longitude = true;
519534
moduleQueried.latitude = true;
@@ -1204,6 +1219,60 @@ uint8_t SFE_UBLOX_GPS::extractByte(uint8_t spotToStart)
12041219
return (payloadCfg[spotToStart]);
12051220
}
12061221

1222+
//Get the current year
1223+
uint16_t SFE_UBLOX_GPS::getYear(uint16_t maxWait)
1224+
{
1225+
if (moduleQueried.gpsYear == false)
1226+
getPVT();
1227+
moduleQueried.gpsYear = false; //Since we are about to give this to user, mark this data as stale
1228+
return (gpsYear);
1229+
}
1230+
1231+
//Get the current month
1232+
uint8_t SFE_UBLOX_GPS::getMonth(uint16_t maxWait)
1233+
{
1234+
if (moduleQueried.gpsMonth == false)
1235+
getPVT();
1236+
moduleQueried.gpsMonth = false; //Since we are about to give this to user, mark this data as stale
1237+
return (gpsMonth);
1238+
}
1239+
1240+
//Get the current year
1241+
uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
1242+
{
1243+
if (moduleQueried.gpsDay == false)
1244+
getPVT();
1245+
moduleQueried.gpsDay = false; //Since we are about to give this to user, mark this data as stale
1246+
return (gpsDay);
1247+
}
1248+
1249+
//Get the current year
1250+
uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
1251+
{
1252+
if (moduleQueried.gpsHour == false)
1253+
getPVT();
1254+
moduleQueried.gpsHour = false; //Since we are about to give this to user, mark this data as stale
1255+
return (gpsHour);
1256+
}
1257+
1258+
//Get the current year
1259+
uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
1260+
{
1261+
if (moduleQueried.gpsMinute == false)
1262+
getPVT();
1263+
moduleQueried.gpsMinute = false; //Since we are about to give this to user, mark this data as stale
1264+
return (gpsMinute);
1265+
}
1266+
1267+
//Get the current year
1268+
uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
1269+
{
1270+
if (moduleQueried.gpsSecond == false)
1271+
getPVT();
1272+
moduleQueried.gpsSecond = false; //Since we are about to give this to user, mark this data as stale
1273+
return (gpsSecond);
1274+
}
1275+
12071276
//Get the latest Position/Velocity/Time solution and fill all global variables
12081277
boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
12091278
{

0 commit comments

Comments
 (0)