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

Commit 1b0fa3f

Browse files
committed
Add support for Nanosecond
1 parent 45e987c commit 1b0fa3f

File tree

4 files changed

+124
-4
lines changed

4 files changed

+124
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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(500000); //Increase serial speed to maximize
37+
while (!Serial)
38+
; //Wait for user to open terminal
39+
Serial.println("SparkFun Ublox Example");
40+
41+
Wire.begin();
42+
Wire.setClock(400000);
43+
44+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
45+
{
46+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
47+
while (1)
48+
;
49+
}
50+
51+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
52+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
53+
54+
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
55+
56+
myGPS.setNavigationFrequency(10); //Set output to 10 times a second
57+
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
58+
Serial.print("Current update rate:");
59+
Serial.println(rate);
60+
61+
}
62+
63+
void loop()
64+
{
65+
//Query module only every second. Doing it more often will just cause I2C traffic.
66+
//The module only responds when a new position is available
67+
if (millis() - lastTime > 10)
68+
{
69+
lastTime = millis(); //Update the timer
70+
71+
long latitude = myGPS.getLatitude();
72+
Serial.print(F("Lat: "));
73+
Serial.print(latitude);
74+
75+
long longitude = myGPS.getLongitude();
76+
Serial.print(F(" Long: "));
77+
Serial.print(longitude);
78+
Serial.print(F(" (degrees * 10^-7)"));
79+
80+
long altitude = myGPS.getAltitude();
81+
Serial.print(F(" Alt: "));
82+
Serial.print(altitude);
83+
Serial.print(F(" (mm)"));
84+
85+
byte SIV = myGPS.getSIV();
86+
Serial.print(F(" SIV: "));
87+
Serial.print(SIV);
88+
89+
Serial.print(myGPS.getYear());
90+
Serial.print("-");
91+
Serial.print(myGPS.getMonth());
92+
Serial.print("-");
93+
Serial.print(myGPS.getDay());
94+
Serial.print(" ");
95+
Serial.print(myGPS.getHour());
96+
Serial.print(":");
97+
Serial.print(myGPS.getMinute());
98+
Serial.print(":");
99+
Serial.print(myGPS.getSecond());
100+
Serial.print(".");
101+
Serial.print(myGPS.getNanosecond());
102+
103+
Serial.println();
104+
}
105+
}

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ getDay KEYWORD2
9595
getHour KEYWORD2
9696
getMinute KEYWORD2
9797
getSecond KEYWORD2
98+
getNanosecond KEYWORD2
9899

99100
getHPPOSLLH KEYWORD2
100101
getTimeOfWeek KEYWORD2

src/SparkFun_Ublox_Arduino_Library.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
535535
gpsHour = extractByte(8);
536536
gpsMinute = extractByte(9);
537537
gpsSecond = extractByte(10);
538+
gpsNanosecond = extractLong(16);
538539

539540
fixType = extractByte(20 - startingSpot);
540541
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
@@ -554,6 +555,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
554555
moduleQueried.gpsHour = true;
555556
moduleQueried.gpsMinute = true;
556557
moduleQueried.gpsSecond = true;
558+
moduleQueried.gpsNanosecond = true;
557559

558560
moduleQueried.all = true;
559561
moduleQueried.longitude = true;
@@ -1307,7 +1309,7 @@ uint8_t SFE_UBLOX_GPS::getMonth(uint16_t maxWait)
13071309
return (gpsMonth);
13081310
}
13091311

1310-
//Get the current year
1312+
//Get the current day
13111313
uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
13121314
{
13131315
if (moduleQueried.gpsDay == false)
@@ -1316,7 +1318,7 @@ uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
13161318
return (gpsDay);
13171319
}
13181320

1319-
//Get the current year
1321+
//Get the current hour
13201322
uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
13211323
{
13221324
if (moduleQueried.gpsHour == false)
@@ -1325,7 +1327,7 @@ uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
13251327
return (gpsHour);
13261328
}
13271329

1328-
//Get the current year
1330+
//Get the current minute
13291331
uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
13301332
{
13311333
if (moduleQueried.gpsMinute == false)
@@ -1334,7 +1336,7 @@ uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
13341336
return (gpsMinute);
13351337
}
13361338

1337-
//Get the current year
1339+
//Get the current second
13381340
uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
13391341
{
13401342
if (moduleQueried.gpsSecond == false)
@@ -1343,6 +1345,15 @@ uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
13431345
return (gpsSecond);
13441346
}
13451347

1348+
//Get the current nanosecond
1349+
int32_t SFE_UBLOX_GPS::getNanosecond(uint16_t maxWait)
1350+
{
1351+
if (moduleQueried.gpsNanosecond == false)
1352+
getPVT();
1353+
moduleQueried.gpsNanosecond = false; //Since we are about to give this to user, mark this data as stale
1354+
return (gpsNanosecond);
1355+
}
1356+
13461357
//Get the latest Position/Velocity/Time solution and fill all global variables
13471358
boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
13481359
{

src/SparkFun_Ublox_Arduino_Library.h

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class SFE_UBLOX_GPS
252252
uint8_t getHour(uint16_t maxWait = 250);
253253
uint8_t getMinute(uint16_t maxWait = 250);
254254
uint8_t getSecond(uint16_t maxWait = 250);
255+
int32_t getNanosecond(uint16_t maxWait = 250);
255256

256257
uint32_t getTimeOfWeek(uint16_t maxWait = 250);
257258
int32_t getHighResLatitude(uint16_t maxWait = 250);
@@ -347,6 +348,7 @@ class SFE_UBLOX_GPS
347348
uint8_t gpsHour;
348349
uint8_t gpsMinute;
349350
uint8_t gpsSecond;
351+
int32_t gpsNanosecond;
350352

351353
int32_t latitude; //Degrees * 10^-7 (more accurate than floats)
352354
int32_t longitude; //Degrees * 10^-7 (more accurate than floats)
@@ -443,6 +445,7 @@ class SFE_UBLOX_GPS
443445
uint16_t gpsHour : 1;
444446
uint16_t gpsMinute : 1;
445447
uint16_t gpsSecond : 1;
448+
uint16_t gpsNanosecond : 1;
446449

447450
uint16_t all : 1;
448451
uint16_t longitude : 1;

0 commit comments

Comments
 (0)