Skip to content

Commit beb707a

Browse files
authored
Merge pull request #1 from sparkfun/release_candidate
Release candidate update
2 parents 82c4020 + c931a04 commit beb707a

File tree

7 files changed

+283
-55
lines changed

7 files changed

+283
-55
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ If you would like to learn more about how this library works, including the big
8787
* [GPS-15005](https://www.sparkfun.com/products/15005) - SparkFun GPS-RTK Board - NEO-M8P-2 (Qwiic)
8888
* [GPS-15210](https://www.sparkfun.com/products/15210) - SparkFun GPS Breakout - Chip Antenna, SAM-M8Q (Qwiic)
8989
* [GPS-15193](https://www.sparkfun.com/products/15193) - SparkFun GPS Breakout - Chip Antenna, ZOE-M8Q (Qwiic)
90+
* [GPS-17285](https://www.sparkfun.com/products/17285) - SparkFun GPS Breakout - NEO-M9N, SMA (Qwiic)
9091
* [GPS-15733](https://www.sparkfun.com/products/15733) - SparkFun GPS Breakout - NEO-M9N, Chip Antenna (Qwiic)
9192
* [GPS-15712](https://www.sparkfun.com/products/15712) - SparkFun GPS Breakout - NEO-M9N, U.FL (Qwiic)
9293
* [GPS-16329](https://www.sparkfun.com/products/16329) - SparkFun GPS Dead Reckoning Breakout - NEO-M8U (Qwiic)

Diff for: examples/Example24_GetUnixEpochAndMicros/Example24_GetUnixEpochAndMicros.ino

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
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.
99
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.
1010
11+
Note: this example works best on modules like the ZED_F9P. Modules like the ZOE_M8Q do not support confirmedTime.
12+
1113
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
1214
1315
Feel like supporting open source hardware?
@@ -29,8 +31,6 @@ SFE_UBLOX_GNSS myGNSS;
2931

3032

3133
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module.
32-
33-
uint32_t us; //microseconds returned by getUnixEpoch()
3434

3535
void setup()
3636
{
@@ -48,6 +48,9 @@ void setup()
4848
;
4949
}
5050

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+
5154
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
5255
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
5356

@@ -63,11 +66,15 @@ void loop()
6366
{
6467
lastTime = millis(); //Update the timer
6568

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);
6977

70-
Serial.print(" ");
7178
Serial.print(myGNSS.getYear());
7279
Serial.print("-");
7380
Serial.print(myGNSS.getMonth());
@@ -79,10 +86,6 @@ void loop()
7986
Serial.print(myGNSS.getMinute());
8087
Serial.print(":");
8188
Serial.print(myGNSS.getSecond());
82-
Serial.print(" getUnixEpoch(micros): ");
83-
Serial.print(myGNSS.getUnixEpoch(us));
84-
Serial.print(" micros: ");
85-
Serial.print(us, DEC);
8689

8790
Serial.print(" Time is ");
8891
if (myGNSS.getTimeValid() == false)
@@ -98,6 +101,8 @@ void loop()
98101
}
99102
Serial.print("confirmed");
100103

101-
Serial.println();
104+
byte SIV = myGNSS.getSIV();
105+
Serial.print(F(" SIV: "));
106+
Serial.println(SIV);
102107
}
103-
}
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

+8-2
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,7 +397,7 @@ getMinute KEYWORD2
391397
getSecond KEYWORD2
392398
getMillisecond KEYWORD2
393399
getNanosecond KEYWORD2
394-
getUnixEpoch KEYWORD2
400+
getUnixEpoch KEYWORD2
395401
getDateValid KEYWORD2
396402
getTimeValid KEYWORD2
397403
getConfirmedDate KEYWORD2
@@ -606,4 +612,4 @@ SFE_UBLOX_GNSS_ID_IMES LITERAL1
606612
SFE_UBLOX_GNSS_ID_QZSS LITERAL1
607613
SFE_UBLOX_GNSS_ID_GLONASS LITERAL1
608614

609-
DAYS_SINCE_MONTH LITERAL1
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.2
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/>

Diff for: src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+92-5
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,20 @@ uint16_t SFE_UBLOX_GNSS::getMaxFileBufferAvail(void)
30553055
return (fileBufferMaxAvail);
30563056
}
30573057

3058+
// Clear the file buffer - discard all contents
3059+
void SFE_UBLOX_GNSS::clearFileBuffer(void)
3060+
{
3061+
if (fileBufferSize == 0) // Bail if the user has not called setFileBufferSize (probably redundant)
3062+
return;
3063+
fileBufferTail = fileBufferHead;
3064+
}
3065+
3066+
// Reset fileBufferMaxAvail
3067+
void SFE_UBLOX_GNSS::clearMaxFileBufferAvail(void)
3068+
{
3069+
fileBufferMaxAvail = 0;
3070+
}
3071+
30583072
// PRIVATE: Create the file buffer. Called by .begin
30593073
boolean SFE_UBLOX_GNSS::createFileBuffer(void)
30603074
{
@@ -8569,7 +8583,7 @@ boolean SFE_UBLOX_GNSS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait
85698583
//Adjust the I2C polling timeout based on update rate
85708584
i2cPollingWait = 1000 / (((int)navFreq) * 4); //This is the number of ms to wait between checks for new I2C data
85718585

8572-
//Query the module for the latest lat/long
8586+
//Query the module
85738587
packetCfg.cls = UBX_CLASS_CFG;
85748588
packetCfg.id = UBX_CFG_RATE;
85758589
packetCfg.len = 0;
@@ -8606,6 +8620,79 @@ uint8_t SFE_UBLOX_GNSS::getNavigationFrequency(uint16_t maxWait)
86068620
return (measurementRate);
86078621
}
86088622

8623+
//Set the elapsed time between GNSS measurements in milliseconds, which defines the rate
8624+
boolean SFE_UBLOX_GNSS::setMeasurementRate(uint16_t rate, uint16_t maxWait)
8625+
{
8626+
//Adjust the I2C polling timeout based on update rate
8627+
i2cPollingWait = rate / 4; //This is the number of ms to wait between checks for new I2C data
8628+
8629+
//Query the module
8630+
packetCfg.cls = UBX_CLASS_CFG;
8631+
packetCfg.id = UBX_CFG_RATE;
8632+
packetCfg.len = 0;
8633+
packetCfg.startingSpot = 0;
8634+
8635+
//This will load the payloadCfg array with current settings of the given register
8636+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8637+
return (false); //If command send fails then bail
8638+
8639+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
8640+
payloadCfg[0] = rate & 0xFF; //measRate LSB
8641+
payloadCfg[1] = rate >> 8; //measRate MSB
8642+
8643+
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
8644+
}
8645+
8646+
//Return the elapsed time between GNSS measurements in milliseconds, which defines the rate
8647+
uint16_t SFE_UBLOX_GNSS::getMeasurementRate(uint16_t maxWait)
8648+
{
8649+
if (packetUBXCFGRATE == NULL) initPacketUBXCFGRATE(); //Check that RAM has been allocated for the RATE data
8650+
if (packetUBXCFGRATE == NULL) //Bail if the RAM allocation failed
8651+
return 0;
8652+
8653+
if (packetUBXCFGRATE->moduleQueried.moduleQueried.bits.measRate == false)
8654+
getNavigationFrequencyInternal(maxWait);
8655+
packetUBXCFGRATE->moduleQueried.moduleQueried.bits.measRate = false; //Since we are about to give this to user, mark this data as stale
8656+
packetUBXCFGRATE->moduleQueried.moduleQueried.bits.all = false;
8657+
8658+
return (packetUBXCFGRATE->data.measRate);
8659+
}
8660+
8661+
//Set the ratio between the number of measurements and the number of navigation solutions. Unit is cycles. Max is 127.
8662+
boolean SFE_UBLOX_GNSS::setNavigationRate(uint16_t rate, uint16_t maxWait)
8663+
{
8664+
//Query the module
8665+
packetCfg.cls = UBX_CLASS_CFG;
8666+
packetCfg.id = UBX_CFG_RATE;
8667+
packetCfg.len = 0;
8668+
packetCfg.startingSpot = 0;
8669+
8670+
//This will load the payloadCfg array with current settings of the given register
8671+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8672+
return (false); //If command send fails then bail
8673+
8674+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
8675+
payloadCfg[2] = rate & 0xFF; //navRate LSB
8676+
payloadCfg[3] = rate >> 8; //navRate MSB
8677+
8678+
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
8679+
}
8680+
8681+
//Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles
8682+
uint16_t SFE_UBLOX_GNSS::getNavigationRate(uint16_t maxWait)
8683+
{
8684+
if (packetUBXCFGRATE == NULL) initPacketUBXCFGRATE(); //Check that RAM has been allocated for the RATE data
8685+
if (packetUBXCFGRATE == NULL) //Bail if the RAM allocation failed
8686+
return 0;
8687+
8688+
if (packetUBXCFGRATE->moduleQueried.moduleQueried.bits.navRate == false)
8689+
getNavigationFrequencyInternal(maxWait);
8690+
packetUBXCFGRATE->moduleQueried.moduleQueried.bits.navRate = false; //Since we are about to give this to user, mark this data as stale
8691+
packetUBXCFGRATE->moduleQueried.moduleQueried.bits.all = false;
8692+
8693+
return (packetUBXCFGRATE->data.navRate);
8694+
}
8695+
86098696
// ***** DOP Helper Functions
86108697

86118698
uint16_t SFE_UBLOX_GNSS::getGeometricDOP(uint16_t maxWait)
@@ -8897,7 +8984,7 @@ uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint32_t& microsecond, uint16_t maxWait)
88978984
packetUBXNAVPVT->data.sec);
88988985
int32_t us = packetUBXNAVPVT->data.nano / 1000;
88998986
microsecond = (uint32_t)us;
8900-
// ajust t if nano is negative
8987+
// adjust t if nano is negative
89018988
if(us < 0) {
89028989
microsecond = (uint32_t)(us + 1000000);
89038990
t--;
@@ -9664,7 +9751,7 @@ boolean SFE_UBLOX_GNSS::getSensorFusionMeasurement(UBX_ESF_MEAS_sensorData_t *se
96649751
if (packetUBXESFMEAS == NULL) //Bail if the RAM allocation failed
96659752
return (false);
96669753

9667-
if (packetUBXESFMEAS->moduleQueried.moduleQueried.bits.data & (1 << sensor) == 0)
9754+
if (packetUBXESFMEAS->moduleQueried.moduleQueried.bits.data & ((1 << sensor) == 0))
96689755
getESFMEAS(maxWait);
96699756
packetUBXESFMEAS->moduleQueried.moduleQueried.bits.data &= ~(1 << sensor); //Since we are about to give this to user, mark this data as stale
96709757
packetUBXESFMEAS->moduleQueried.moduleQueried.bits.all = false;
@@ -9684,7 +9771,7 @@ boolean SFE_UBLOX_GNSS::getRawSensorMeasurement(UBX_ESF_RAW_sensorData_t *sensor
96849771
if (packetUBXESFRAW == NULL) //Bail if the RAM allocation failed
96859772
return (false);
96869773

9687-
if (packetUBXESFRAW->moduleQueried.moduleQueried.bits.data & (1 << sensor) == 0)
9774+
if (packetUBXESFRAW->moduleQueried.moduleQueried.bits.data & ((1 << sensor) == 0))
96889775
getESFRAW(maxWait);
96899776
packetUBXESFRAW->moduleQueried.moduleQueried.bits.data &= ~(1 << sensor); //Since we are about to give this to user, mark this data as stale
96909777
packetUBXESFRAW->moduleQueried.moduleQueried.bits.all = false;
@@ -9706,7 +9793,7 @@ boolean SFE_UBLOX_GNSS::getSensorFusionStatus(UBX_ESF_STATUS_sensorStatus_t *sen
97069793
if (packetUBXESFSTATUS == NULL) //Bail if the RAM allocation failed
97079794
return (false);
97089795

9709-
if (packetUBXESFSTATUS->moduleQueried.moduleQueried.bits.status & (1 << sensor) == 0)
9796+
if (packetUBXESFSTATUS->moduleQueried.moduleQueried.bits.status & ((1 << sensor) == 0))
97109797
getESFSTATUS(maxWait);
97119798
packetUBXESFSTATUS->moduleQueried.moduleQueried.bits.status &= ~(1 << sensor); //Since we are about to give this to user, mark this data as stale
97129799
packetUBXESFSTATUS->moduleQueried.moduleQueried.bits.all = false;

0 commit comments

Comments
 (0)