Skip to content

Commit 185c6c2

Browse files
committed
Add support for automatic NMEA
1 parent bdfb274 commit 185c6c2

File tree

4 files changed

+669
-0
lines changed

4 files changed

+669
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
Get the GPGGA NMEA sentence using getLatestNMEAGPGGA
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: January 12th, 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 turn on/off the NMEA sentences being output over I2C.
10+
It then demonstrates how to use the new getLatestNMEAGPGGA function to retrieve the latest GPGGA message.
11+
getLatestNMEAGPGGA returns immediately - it is not blocking.
12+
It returns:
13+
0 if no data is available
14+
1 if the data is valid but is stale (you have read it before)
15+
2 if the data is valid and fresh
16+
17+
This example turns off all sentences except for GPGGA.
18+
19+
Feel like supporting open source hardware?
20+
Buy a board from SparkFun!
21+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
22+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
23+
SAM-M8Q: https://www.sparkfun.com/products/15106
24+
25+
Hardware Connections:
26+
Plug a Qwiic cable into the GNSS and a RedBoard
27+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
28+
Open the serial monitor at 115200 baud to see the output
29+
*/
30+
31+
#include <Wire.h> //Needed for I2C to GNSS
32+
33+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
34+
SFE_UBLOX_GNSS myGNSS;
35+
36+
void setup()
37+
{
38+
39+
Serial.begin(115200);
40+
Serial.println(F("SparkFun u-blox GNSS Example"));
41+
42+
Wire.begin();
43+
44+
//myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
45+
46+
if (myGNSS.begin() == false)
47+
{
48+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
49+
while (1)
50+
;
51+
}
52+
53+
//Disable or enable various NMEA sentences over the I2C interface
54+
myGNSS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX); // Turn on both UBX and NMEA sentences on I2C. (Turn off RTCM and SPARTN)
55+
myGNSS.disableNMEAMessage(UBX_NMEA_GLL, COM_PORT_I2C); // Several of these are on by default on ublox board so let's disable them
56+
myGNSS.disableNMEAMessage(UBX_NMEA_GSA, COM_PORT_I2C);
57+
myGNSS.disableNMEAMessage(UBX_NMEA_GSV, COM_PORT_I2C);
58+
myGNSS.disableNMEAMessage(UBX_NMEA_RMC, COM_PORT_I2C);
59+
myGNSS.disableNMEAMessage(UBX_NMEA_VTG, COM_PORT_I2C);
60+
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C); // Leave only GGA enabled at current navigation rate
61+
62+
//myGNSS.saveConfiguration(); //Optional: Save these settings to NVM
63+
64+
Serial.println(F("Messages configured"));
65+
66+
//myGNSS.setNMEAOutputPort(Serial); // Uncomment this line to echo all NMEA data to Serial for debugging
67+
}
68+
69+
void loop()
70+
{
71+
// getLatestNMEAGPGGA calls checkUblox for us. We don't need to do it here
72+
73+
NMEA_GGA_data_t data; // Storage for the GPGGA data
74+
uint8_t result = myGNSS.getLatestNMEAGPGGA(&data); // Get the latest GPGGA data (if any)
75+
76+
if (result == 0)
77+
{
78+
Serial.println(F("No GPGGA data available"));
79+
}
80+
else if (result == 1)
81+
{
82+
Serial.println(F("GPGGA data is available but is stale"));
83+
}
84+
else if (result == 2)
85+
{
86+
// Data contains .length and .nmea
87+
Serial.print(F("NMEA: Length: "));
88+
Serial.print(data.length);
89+
Serial.print(F("\tData: "));
90+
Serial.println((const char *)data.nmea); // .nmea is printable (NULL-terminated)
91+
}
92+
else
93+
{
94+
Serial.print(F("result == "));
95+
Serial.print(result);
96+
Serial.println(F(". This should be impossible!"));
97+
}
98+
99+
result = myGNSS.getLatestNMEAGNGGA(&data); // Get the latest GNGGA data (if any)
100+
101+
if (result == 0)
102+
{
103+
Serial.println(F("No GNGGA data available"));
104+
}
105+
else if (result == 1)
106+
{
107+
Serial.println(F("GNGGA data is available but is stale"));
108+
}
109+
else if (result == 2)
110+
{
111+
// Data contains .length and .nmea
112+
Serial.print(F("NMEA: Length: "));
113+
Serial.print(data.length);
114+
Serial.print(F("\tData: "));
115+
Serial.println((const char *)data.nmea); // .nmea is printable (NULL-terminated)
116+
}
117+
else
118+
{
119+
Serial.print(F("result == "));
120+
Serial.print(result);
121+
Serial.println(F(". This should be impossible!"));
122+
}
123+
124+
delay(250);
125+
}

0 commit comments

Comments
 (0)