8
8
This example shows how to query a u-blox module for the current time and date as Unix Epoch uint32_t type to avoid time.h dependency.
9
9
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.
10
10
11
+ Note: this example works best on modules like the ZED_F9P. Modules like the ZOE_M8Q do not support confirmedTime.
12
+
11
13
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
12
14
13
15
Feel like supporting open source hardware?
@@ -29,8 +31,6 @@ SFE_UBLOX_GNSS myGNSS;
29
31
30
32
31
33
long lastTime = 0 ; // Simple local timer. Limits amount if I2C traffic to u-blox module.
32
-
33
- uint32_t us; // microseconds returned by getUnixEpoch()
34
34
35
35
void setup ()
36
36
{
@@ -48,6 +48,9 @@ void setup()
48
48
;
49
49
}
50
50
51
+ // Uncomment the next line if you need to completely reset your module
52
+ // myGNSS.factoryDefault(); delay(5000); // Reset everything and wait while the module restarts
53
+
51
54
myGNSS.setI2COutput (COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
52
55
// myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
53
56
@@ -63,11 +66,15 @@ void loop()
63
66
{
64
67
lastTime = millis (); // Update the timer
65
68
66
- byte SIV = myGNSS.getSIV ();
67
- Serial.print (F (" SIV: " ));
68
- Serial.print (SIV);
69
+ // getUnixEpoch marks the PVT data as stale so you will get Unix time and PVT time on alternate seconds
70
+
71
+ uint32_t us; // microseconds returned by getUnixEpoch()
72
+ uint32_t epoch = myGNSS.getUnixEpoch (us);
73
+ Serial.print (" Unix Epoch: " );
74
+ Serial.print (epoch, DEC);
75
+ Serial.print (" micros: " );
76
+ Serial.println (us, DEC);
69
77
70
- Serial.print (" " );
71
78
Serial.print (myGNSS.getYear ());
72
79
Serial.print (" -" );
73
80
Serial.print (myGNSS.getMonth ());
@@ -79,10 +86,6 @@ void loop()
79
86
Serial.print (myGNSS.getMinute ());
80
87
Serial.print (" :" );
81
88
Serial.print (myGNSS.getSecond ());
82
- Serial.print (" getUnixEpoch(micros): " );
83
- Serial.print (myGNSS.getUnixEpoch (us));
84
- Serial.print (" micros: " );
85
- Serial.print (us, DEC);
86
89
87
90
Serial.print (" Time is " );
88
91
if (myGNSS.getTimeValid () == false )
@@ -98,6 +101,8 @@ void loop()
98
101
}
99
102
Serial.print (" confirmed" );
100
103
101
- Serial.println ();
104
+ byte SIV = myGNSS.getSIV ();
105
+ Serial.print (F (" SIV: " ));
106
+ Serial.println (SIV);
102
107
}
103
- }
108
+ }
0 commit comments