Skip to content

Commit fb76790

Browse files
committed
Add Example24
1 parent 0c576c9 commit fb76790

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed
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+
}

src/SparkFun_u-blox_GNSS_Arduino_Library.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ class SFE_UBLOX_GNSS
11701170
//Limit checking of new data to every X ms
11711171
//If we are expecting an update every X Hz then we should check every half that amount of time
11721172
//Otherwise we may block ourselves from seeing new data
1173-
uint8_t i2cPollingWait = 100; //Default to 100ms. Adjusted when user calls setNavigationFrequency() or setHNRNavigationRate()
1173+
uint8_t i2cPollingWait = 100; //Default to 100ms. Adjusted when user calls setNavigationFrequency() or setHNRNavigationRate() or setMeasurementRate()
11741174

11751175
unsigned long lastCheck = 0;
11761176

0 commit comments

Comments
 (0)