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

Commit ae6b284

Browse files
authored
Merge pull request #4 from tve/autoPVT
Add support for auto-reporting of navigation solutions using UBX_NAV_PVT
2 parents 9d71472 + d13d4c4 commit ae6b284

File tree

6 files changed

+277
-59
lines changed

6 files changed

+277
-59
lines changed

Diff for: README.md

+33
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ Documentation
3838

3939
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
4040

41+
Polling vs. auto-reporting
42+
--------------------------
43+
44+
This library supports two modes of operation for getting navigation information with the `getPVT`
45+
function (based on the `UBX_NAV_PVT` protocol packet): polling and auto-reporting.
46+
47+
The standard method is for the sketch to call `getPVT` (or one of the `getLatitude`, `getLongitude`,
48+
etc. methods) when it needs a fresh navigation solution. At that point the library sends a request
49+
to the GPS to produce a fresh solution. The GPS then waits until the next measurement occurs (e.g.
50+
once per second or as set using `setNavigationFrequency`) and then sends the fresh data.
51+
The advantage of this method is that the data received is always fresh, the downside is that getPVT
52+
can block until the next measurement is made by the GPS, e.g. up to 1 second if the nav frequency is
53+
set to one second.
54+
55+
An alternate method can be chosen using `setAutoPVT(true)` which instructs the GPS to send the
56+
navigation information (`UBX_NAV_PVT` packet) as soon as it is produced. This is the way the older
57+
NMEA navigation data has been used for years. The sketch continues to call `getPVT` as before but
58+
under the hood the library returns the data of the last solution received from the GPS, which may be
59+
a bit out of date (how much depends on the `setNavigationFrequency` value).
60+
61+
The advantage of this method is that getPVT does not block: it returns true if new data is available
62+
and false otherwise. The disadvantages are that the data may be a bit old and that buffering for
63+
these spontaneus `UBX_NAV_PVT` packets is required (100 bytes each). When using Serial the buffering
64+
is an issue because the std serial buffer is 32 or 64 bytes long depending on Arduino version. When
65+
using I2C the buffering is not an issue because the GPS device has at least 1KB of internal buffering
66+
(possibly as large as 4KB).
67+
68+
As an example, assume that the GPS is set to produce 5 navigation
69+
solutions per second and that the sketch only calls getPVT once a second, then the GPS will queue 5
70+
packets in its internal buffer (about 500 bytes) and the library will read those when getPVT is
71+
called, update its internal copy of the nav data 5 times, and return `true` to the sketch. The
72+
skecth calls `getLatitude`, etc. and retrieve the data of the most recent of those 5 packets.
73+
4174
Products That Use This Library
4275
---------------------------------
4376

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Test baud rate changes on serial, factory reset, and hard reset.
3+
By: Thorsten von Eicken
4+
Date: January 29rd, 2019
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 reset the U-Blox module to factory defaults.
9+
10+
Feel like supporting open source hardware?
11+
Buy a board from SparkFun!
12+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
13+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
14+
SAM-M8Q: https://www.sparkfun.com/products/15106
15+
16+
Hardware Connections:
17+
Connect the U-Blox serial port to Serial1
18+
If you're using an Uno or don't have a 2nd serial port (Serial1), consider using software serial
19+
Open the serial monitor at 115200 baud to see the output
20+
*/
21+
22+
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS
23+
SFE_UBLOX_GPS myGPS;
24+
25+
int state = 0; // steps through auto-baud, reset, etc states
26+
27+
void setup()
28+
{
29+
Serial.begin(115200);
30+
while (!Serial); //Wait for user to open terminal
31+
Serial.println("SparkFun Ublox Example");
32+
33+
Wire.begin();
34+
35+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
36+
{
37+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
38+
while (1);
39+
}
40+
41+
while (Serial.available()) Serial.read(); //Trash any incoming chars
42+
Serial.println("Press a key to reset module to factory defaults");
43+
while (Serial.available() == false) ; //Wait for user to send character
44+
45+
myGPS.factoryReset();
46+
47+
if (myGPS.begin() == false) //Attempt to re-connect
48+
{
49+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
50+
while (1);
51+
}
52+
53+
Serial.println("Unit has now been factory reset. Freezing...");
54+
while(1);
55+
}
56+
57+
void loop()
58+
{
59+
60+
}

Diff for: examples/Example13_AutoPVT/Example13_AutoPVT.ino

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Configuring the GPS to automatically send position reports over I2C
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: January 3rd, 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 configure the U-Blox GPS the send navigation reports automatically
10+
and retrieving the latest one via getPVT. This eliminates the blocking in getPVT while the GPS
11+
produces a fresh navigation solution at the expense of returning a slighly old solution.
12+
13+
This can be used over serial or over I2C, this example shows the I2C use. With serial the GPS
14+
simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in
15+
size?) where it can be retrieved in the next I2C poll.
16+
17+
Feel like supporting open source hardware?
18+
Buy a board from SparkFun!
19+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
20+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
21+
SAM-M8Q: https://www.sparkfun.com/products/15106
22+
23+
Hardware Connections:
24+
Plug a Qwiic cable into the GPS and a BlackBoard
25+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
26+
Open the serial monitor at 115200 baud to see the output
27+
*/
28+
29+
#include <Wire.h> //Needed for I2C to GPS
30+
31+
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS
32+
SFE_UBLOX_GPS myGPS;
33+
34+
void setup()
35+
{
36+
Serial.begin(115200);
37+
while (!Serial); //Wait for user to open terminal
38+
Serial.println("SparkFun Ublox Example");
39+
40+
Wire.begin();
41+
42+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
43+
{
44+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
45+
while (1);
46+
}
47+
48+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
49+
myGPS.setNavigationFrequency(2); //Produce two solutions per second
50+
myGPS.setAutoPVT(true); //Tell the GPS to "send" each solution
51+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
52+
}
53+
54+
void loop()
55+
{
56+
// Calling getPVT returns true if there actually is a fresh navigation solution available.
57+
if (myGPS.getPVT())
58+
{
59+
Serial.println();
60+
long latitude = myGPS.getLatitude();
61+
Serial.print(F("Lat: "));
62+
Serial.print(latitude);
63+
64+
long longitude = myGPS.getLongitude();
65+
Serial.print(F(" Long: "));
66+
Serial.print(longitude);
67+
Serial.print(F(" (degrees * 10^-7)"));
68+
69+
long altitude = myGPS.getAltitude();
70+
Serial.print(F(" Alt: "));
71+
Serial.print(altitude);
72+
Serial.print(F(" (mm)"));
73+
74+
byte SIV = myGPS.getSIV();
75+
Serial.print(F(" SIV: "));
76+
Serial.print(SIV);
77+
78+
Serial.println();
79+
} else {
80+
Serial.print(".");
81+
delay(50);
82+
}
83+
}

Diff for: keywords.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ getPositionAccuracy KEYWORD2
7676

7777
getProtocolVersionHigh KEYWORD2
7878
getProtocolVersionLow KEYWORD2
79-
getProtocolVersion KEYWORD2
79+
getProtocolVersion KEYWORD2
80+
81+
factoryReset KEYWORD2
82+
setAutoPVT KEYWORD2
8083

8184
#######################################
8285
# Constants (LITERAL1)

0 commit comments

Comments
 (0)