Skip to content

Commit 7f38fcd

Browse files
authored
Merge pull request #17 from sparkfun/release_candidate
v2.0.4
2 parents b1eb847 + c931a04 commit 7f38fcd

File tree

8 files changed

+558
-38
lines changed

8 files changed

+558
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Configuring the GNSS to automatically send RXM RZWX reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: March 11th, 2021
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 configure the u-blox GNSS to send RXM RAWX reports automatically
10+
and access the data via a callback. No more polling!
11+
12+
Feel like supporting open source hardware?
13+
Buy a board from SparkFun!
14+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15+
16+
Hardware Connections:
17+
Plug a Qwiic cable into the GPS and a BlackBoard
18+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
19+
Open the serial monitor at 115200 baud to see the output
20+
*/
21+
22+
#include <Wire.h> //Needed for I2C to GPS
23+
24+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
25+
SFE_UBLOX_GNSS myGNSS;
26+
27+
// Callback: newRAWX will be called when new RXM RAWX data arrives
28+
// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t
29+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMRAWXcallback
30+
// / _____ This _must_ be UBX_RXM_RAWX_data_t
31+
// | / _____ You can use any name you like for the struct
32+
// | | /
33+
// | | |
34+
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct)
35+
{
36+
Serial.println();
37+
38+
Serial.print(F("New RAWX data received. It contains "));
39+
Serial.print(ubxDataStruct.header.numMeas); // Print numMeas (Number of measurements / blocks)
40+
Serial.println(F(" data blocks:"));
41+
42+
for (uint8_t block = 0; block < ubxDataStruct.header.numMeas; block++) // For each block
43+
{
44+
Serial.print(F("GNSS ID: "));
45+
if (ubxDataStruct.blocks[block].gnssId < 100) Serial.print(F(" ")); // Align the gnssId
46+
if (ubxDataStruct.blocks[block].gnssId < 10) Serial.print(F(" ")); // Align the gnssId
47+
Serial.print(ubxDataStruct.blocks[block].gnssId);
48+
Serial.print(F(" SV ID: "));
49+
if (ubxDataStruct.blocks[block].svId < 100) Serial.print(F(" ")); // Align the svId
50+
if (ubxDataStruct.blocks[block].svId < 10) Serial.print(F(" ")); // Align the svId
51+
Serial.print(ubxDataStruct.blocks[block].svId);
52+
53+
if (sizeof(double) == 8) // Check if our processor supports 64-bit double
54+
{
55+
// Convert prMes from uint8_t[8] to 64-bit double
56+
// prMes is little-endian
57+
double pseudorange;
58+
memcpy(&pseudorange, &ubxDataStruct.blocks[block].prMes, 8);
59+
Serial.print(F(" PR: "));
60+
Serial.print(pseudorange, 3);
61+
62+
// Convert cpMes from uint8_t[8] to 64-bit double
63+
// cpMes is little-endian
64+
double carrierPhase;
65+
memcpy(&carrierPhase, &ubxDataStruct.blocks[block].cpMes, 8);
66+
Serial.print(F(" m CP: "));
67+
Serial.print(carrierPhase, 3);
68+
Serial.print(F(" cycles"));
69+
}
70+
Serial.println();
71+
}
72+
}
73+
74+
void setup()
75+
{
76+
Serial.begin(115200);
77+
while (!Serial); //Wait for user to open terminal
78+
Serial.println("SparkFun u-blox Example");
79+
80+
Wire.begin();
81+
82+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
83+
84+
myGNSS.disableUBX7Fcheck(); // RAWX data can legitimately contain 0x7F, so we need to disable the "7F" check in checkUbloxI2C
85+
86+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
87+
{
88+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
89+
while (1);
90+
}
91+
92+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
93+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
94+
95+
myGNSS.setNavigationFrequency(1); //Produce one solution per second (RAWX produces a _lot_ of data!)
96+
97+
myGNSS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
98+
}
99+
100+
void loop()
101+
{
102+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
103+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
104+
105+
Serial.print(".");
106+
delay(50);
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Getting Unix Epoch Time and micros using u-blox commands
3+
By: UT2UH
4+
Date: March 30th, 2021
5+
License: MIT. See license file for more information but you can
6+
basically do whatever you want with this code.
7+
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+
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.
10+
11+
Note: this example works best on modules like the ZED_F9P. Modules like the ZOE_M8Q do not support confirmedTime.
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 GNSS 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 GNSS
28+
29+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
30+
SFE_UBLOX_GNSS myGNSS;
31+
32+
33+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module.
34+
35+
void setup()
36+
{
37+
Serial.begin(115200);
38+
while (!Serial)
39+
; //Wait for user to open terminal
40+
Serial.println("SparkFun u-blox Example");
41+
42+
Wire.begin();
43+
44+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
45+
{
46+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
47+
while (1)
48+
;
49+
}
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+
54+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
55+
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
56+
57+
Serial.println("Compare Unix Epoch given with reference one from https://www.epochconverter.com/");
58+
59+
}
60+
61+
void loop()
62+
{
63+
//Query module only every second. Doing it more often will just cause I2C traffic.
64+
//The module only responds when a new position is available
65+
if (millis() - lastTime > 1000)
66+
{
67+
lastTime = millis(); //Update the timer
68+
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);
77+
78+
Serial.print(myGNSS.getYear());
79+
Serial.print("-");
80+
Serial.print(myGNSS.getMonth());
81+
Serial.print("-");
82+
Serial.print(myGNSS.getDay());
83+
Serial.print(" ");
84+
Serial.print(myGNSS.getHour());
85+
Serial.print(":");
86+
Serial.print(myGNSS.getMinute());
87+
Serial.print(":");
88+
Serial.print(myGNSS.getSecond());
89+
90+
Serial.print(" Time is ");
91+
if (myGNSS.getTimeValid() == false)
92+
{
93+
Serial.print("not ");
94+
}
95+
Serial.print("valid ");
96+
if (myGNSS.getConfirmedTime() == false)
97+
{
98+
Serial.print("but not ");
99+
} else {
100+
Serial.print("and ");
101+
}
102+
Serial.print("confirmed");
103+
104+
byte SIV = myGNSS.getSIV();
105+
Serial.print(F(" SIV: "));
106+
Serial.println(SIV);
107+
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Demonstrate get/setMeasurementRate and get/setNavigationRate
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: March 30th, 2021
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 slow down the measurement and navigation rates.
10+
This should run on any GNSS module but has only been tested on the ZED_F9P and ZOE_M8Q.
11+
12+
Feel like supporting open source hardware?
13+
Buy a board from SparkFun!
14+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
16+
SAM-M8Q: https://www.sparkfun.com/products/15106
17+
18+
Hardware Connections:
19+
Plug a Qwiic cable into the GNSS and a BlackBoard
20+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
21+
Open the serial monitor at 115200 baud to see the output
22+
*/
23+
24+
#include <Wire.h> //Needed for I2C to GNSS
25+
26+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
27+
SFE_UBLOX_GNSS myGNSS;
28+
29+
unsigned long lastTime = 0; //Simple local timer. Used to calc the message interval.
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
while (!Serial); //Wait for user to open terminal
35+
Serial.println("SparkFun u-blox Example");
36+
37+
Wire.begin();
38+
39+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
40+
41+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
42+
{
43+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
44+
while (1);
45+
}
46+
47+
// Uncomment the next line if you need to completely reset your module
48+
//myGNSS.factoryDefault(); delay(5000); // Reset everything and wait while the module restarts
49+
50+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
51+
52+
// Begin by printing the current measurement rate and navigation rate
53+
54+
uint16_t rate = myGNSS.getMeasurementRate(); //Get the measurement rate of this module
55+
Serial.print("Current measurement interval (ms): ");
56+
Serial.println(rate);
57+
58+
rate = myGNSS.getNavigationRate(); //Get the navigation rate of this module
59+
Serial.print("Current navigation ratio (cycles): ");
60+
Serial.println(rate);
61+
62+
// The measurement rate is the elapsed time between GNSS measurements, which defines the rate
63+
// e.g. 100 ms => 10 Hz, 1000 ms => 1 Hz, 10000 ms => 0.1 Hz.
64+
// Let's set the measurement rate (interval) to 5 seconds = 5000 milliseconds
65+
if (myGNSS.setMeasurementRate(5000) == false)
66+
{
67+
Serial.println(F("Could not set the measurement rate. Freezing."));
68+
while (1);
69+
}
70+
71+
// setMeasurementRate will set i2cPollingWait to a quarter of the interval
72+
// Let's override that so we can poll the module more frequently and avoid timeouts
73+
myGNSS.setI2CpollingWait(25); // Set i2cPollingWait to 25ms
74+
75+
// The navigation rate is the ratio between the number of measurements and the number of navigation solutions
76+
// e.g. 5 means five measurements for every navigation solution. Maximum value is 127
77+
// Let's set the navigation rate (ratio) to 12 to produce a solution every minute
78+
if (myGNSS.setNavigationRate(12) == false)
79+
{
80+
Serial.println(F("Could not set the navigation rate. Freezing."));
81+
while (1);
82+
}
83+
84+
// Another trick we can use is to mark the CFG RATE data as stale so we can be sure we read fresh data
85+
myGNSS.packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0; // Mark all of the CFG RATE data as stale
86+
87+
// Read and print the updated measurement rate and navigation rate
88+
89+
rate = myGNSS.getMeasurementRate(); //Get the measurement rate of this module
90+
Serial.print("New measurement interval (ms): ");
91+
Serial.println(rate);
92+
93+
rate = myGNSS.getNavigationRate(); //Get the navigation rate of this module
94+
Serial.print("New navigation ratio (cycles): ");
95+
Serial.println(rate);
96+
97+
lastTime = millis();
98+
}
99+
100+
void loop()
101+
{
102+
// i2cPollingWait will prevent us from thrashing the I2C bus
103+
104+
if (myGNSS.getPVT()) //Check for new Position, Velocity, Time data. getPVT returns true if new data is available.
105+
{
106+
long latitude = myGNSS.getLatitude();
107+
Serial.print(F("Lat: "));
108+
Serial.print(latitude);
109+
110+
long longitude = myGNSS.getLongitude();
111+
Serial.print(F(" Long: "));
112+
Serial.print(longitude);
113+
114+
//Calculate the interval since the last message
115+
Serial.print(F(" Interval: "));
116+
Serial.print(((float)(millis() - lastTime)) / 1000.0, 2);
117+
Serial.print(F("s"));
118+
119+
Serial.println();
120+
121+
lastTime = millis(); //Update lastTime
122+
}
123+
}

Diff for: keywords.txt

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ setFileBufferSize KEYWORD2
8484
extractFileBufferData KEYWORD2
8585
fileBufferAvailable KEYWORD2
8686
getMaxFileBufferAvail KEYWORD2
87+
clearFileBuffer KEYWORD2
88+
clearMaxFileBufferAvail KEYWORD2
8789

8890
getPortSettings KEYWORD2
8991
setPortOutput KEYWORD2
@@ -369,6 +371,10 @@ logHNRPVT KEYWORD2
369371

370372
setNavigationFrequency KEYWORD2
371373
getNavigationFrequency KEYWORD2
374+
setMeasurementRate KEYWORD2
375+
getMeasurementRate KEYWORD2
376+
setNavigationRate KEYWORD2
377+
getNavigationRate KEYWORD2
372378

373379
getGeometricDOP KEYWORD2
374380
getPositionDOP KEYWORD2
@@ -391,8 +397,11 @@ getMinute KEYWORD2
391397
getSecond KEYWORD2
392398
getMillisecond KEYWORD2
393399
getNanosecond KEYWORD2
400+
getUnixEpoch KEYWORD2
394401
getDateValid KEYWORD2
395402
getTimeValid KEYWORD2
403+
getConfirmedDate KEYWORD2
404+
getConfirmedTime KEYWORD2
396405
getFixType KEYWORD2
397406
getGnssFixOk KEYWORD2
398407
getDiffSoln KEYWORD2
@@ -602,3 +611,5 @@ SFE_UBLOX_GNSS_ID_BEIDOU LITERAL1
602611
SFE_UBLOX_GNSS_ID_IMES LITERAL1
603612
SFE_UBLOX_GNSS_ID_QZSS LITERAL1
604613
SFE_UBLOX_GNSS_ID_GLONASS LITERAL1
614+
615+
DAYS_SINCE_MONTH LITERAL1

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun u-blox GNSS Arduino Library
2-
version=2.0.3
2+
version=2.0.4
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C and Serial Communication with u-blox GNSS modules<br/><br/>

0 commit comments

Comments
 (0)