Skip to content

Commit 5989aec

Browse files
authored
Merge pull request #139 from sparkfun/release_candidate
v2.2.10
2 parents f9e4311 + c385606 commit 5989aec

File tree

3 files changed

+123
-4
lines changed

3 files changed

+123
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Configuring the GNSS to automatically send position reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: April 15th, 2022
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 access the callback data from the main loop.
10+
The simple way to check if new data is available is to use a global flag: set it in the callback, check it and clear it in the main loop.
11+
Or, you can be more sophisticated and use the callback flags themselves.
12+
This example shows how to use the sophisticated method.
13+
14+
Feel like supporting open source hardware?
15+
Buy a board from SparkFun!
16+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
17+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
18+
SAM-M8Q: https://www.sparkfun.com/products/15106
19+
20+
Hardware Connections:
21+
Plug a Qwiic cable into the GPS and a BlackBoard
22+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
23+
Open the serial monitor at 115200 baud to see the output
24+
*/
25+
26+
#include <Wire.h> //Needed for I2C to GPS
27+
28+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
29+
SFE_UBLOX_GNSS myGNSS;
30+
31+
// Callback: callbackPVT will be called when new NAV PVT data arrives
32+
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
33+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoPVTcallbackPtr
34+
// / _____ This _must_ be UBX_NAV_PVT_data_t
35+
// | / _____ You can use any name you like for the struct
36+
// | | /
37+
// | | |
38+
void callbackPVT(UBX_NAV_PVT_data_t *ubxDataStruct)
39+
{
40+
Serial.println(F("Hey! The NAV PVT callback has been called!"));
41+
}
42+
43+
void setup()
44+
{
45+
Serial.begin(115200);
46+
while (!Serial); //Wait for user to open terminal
47+
Serial.println("SparkFun u-blox Example");
48+
49+
Wire.begin();
50+
51+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
52+
53+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
54+
{
55+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
56+
while (1);
57+
}
58+
59+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
60+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
61+
62+
myGNSS.setNavigationFrequency(2); //Produce two solutions per second
63+
64+
myGNSS.setAutoPVTcallbackPtr(&callbackPVT); // Enable automatic NAV PVT messages with callback to callbackPVT
65+
}
66+
67+
void loop()
68+
{
69+
70+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
71+
72+
// Check if new NAV PVT data has been received:
73+
// If myGNSS.packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid is true, it indicates new PVT data has been received and has been copied.
74+
// automaticFlags.flags.bits.callbackCopyValid will be cleared automatically when the callback is called.
75+
76+
if (myGNSS.packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid == true)
77+
{
78+
// But, we can manually clear the callback flag too. This will prevent the callback from being called!
79+
myGNSS.packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid = false; // Comment this line if you still want the callback to be called
80+
81+
Serial.println();
82+
83+
Serial.print(F("Time: ")); // Print the time
84+
uint8_t hms = myGNSS.packetUBXNAVPVT->callbackData->hour; // Print the hours
85+
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
86+
Serial.print(hms);
87+
Serial.print(F(":"));
88+
hms = myGNSS.packetUBXNAVPVT->callbackData->min; // Print the minutes
89+
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
90+
Serial.print(hms);
91+
Serial.print(F(":"));
92+
hms = myGNSS.packetUBXNAVPVT->callbackData->sec; // Print the seconds
93+
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
94+
Serial.print(hms);
95+
Serial.print(F("."));
96+
unsigned long millisecs = myGNSS.packetUBXNAVPVT->callbackData->iTOW % 1000; // Print the milliseconds
97+
if (millisecs < 100) Serial.print(F("0")); // Print the trailing zeros correctly
98+
if (millisecs < 10) Serial.print(F("0"));
99+
Serial.print(millisecs);
100+
101+
long latitude = myGNSS.packetUBXNAVPVT->callbackData->lat; // Print the latitude
102+
Serial.print(F(" Lat: "));
103+
Serial.print(latitude);
104+
105+
long longitude = myGNSS.packetUBXNAVPVT->callbackData->lon; // Print the longitude
106+
Serial.print(F(" Long: "));
107+
Serial.print(longitude);
108+
Serial.print(F(" (degrees * 10^-7)"));
109+
110+
long altitude = myGNSS.packetUBXNAVPVT->callbackData->hMSL; // Print the height above mean sea level
111+
Serial.print(F(" Height above MSL: "));
112+
Serial.print(altitude);
113+
Serial.println(F(" (mm)"));
114+
}
115+
116+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed. There will not be any in this example, unless you commented the line above
117+
118+
Serial.print(".");
119+
delay(50);
120+
}

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.2.9
2+
version=2.2.10
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3959,8 +3959,7 @@ void SFE_UBLOX_GNSS::processUBXpacket(ubxPacket *msg)
39593959
packetUBXCFGPRT->dataValid = true;
39603960
}
39613961
}
3962-
break;
3963-
if (msg->id == UBX_CFG_RATE && msg->len == UBX_CFG_RATE_LEN)
3962+
else if (msg->id == UBX_CFG_RATE && msg->len == UBX_CFG_RATE_LEN)
39643963
{
39653964
// Parse various byte fields into storage - but only if we have memory allocated for it
39663965
if (packetUBXCFGRATE != NULL)
@@ -12994,7 +12993,7 @@ bool SFE_UBLOX_GNSS::getPortSettingsInternal(uint8_t portID, uint16_t maxWait)
1299412993
if (result == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
1299512994
retVal = true;
1299612995

12997-
// Now disable automatic support for CFG-RATE (see above)
12996+
// Now disable automatic support for CFG-PRT (see above)
1299812997
delete packetUBXCFGPRT;
1299912998
packetUBXCFGPRT = NULL;
1300012999

0 commit comments

Comments
 (0)