Skip to content

Commit 36e22cb

Browse files
committed
Add examples 4&5
1 parent d2f3042 commit 36e22cb

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Reading Position, Velocity and Time (PVT) via UBX binary commands
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: December 21st, 2022
6+
License: MIT. Please see LICENSE.md for more information.
7+
8+
This example shows how to query a u-blox module for its position, velocity and time (PVT) data.
9+
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.
10+
11+
Note: Lat/Lon are large numbers because they are * 10^7. To convert lat/lon
12+
to something google maps understands simply divide the numbers by 10,000,000.
13+
14+
Feel like supporting open source hardware?
15+
Buy a board from SparkFun!
16+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
17+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
18+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
19+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
20+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
21+
22+
Hardware Connections:
23+
Plug a Qwiic cable into the GNSS and your microcontroller board
24+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
25+
Open the serial monitor at 115200 baud to see the output
26+
*/
27+
28+
#include <Wire.h> //Needed for I2C to GNSS
29+
30+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
31+
32+
SFE_UBLOX_GNSS myGNSS;
33+
34+
#define myWire Wire1 // Connect using the Wire1 port. Change this if required
35+
36+
#define gnssAddress 0x42 // The default I2C address for u-blox modules is 0x42. Change this if required
37+
38+
void setup()
39+
{
40+
Serial.begin(115200);
41+
delay(1000);
42+
Serial.println("SparkFun u-blox Example");
43+
44+
myWire.begin(); // Start I2C
45+
46+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
47+
48+
while (myGNSS.begin(myWire, gnssAddress) == false) //Connect to the u-blox module using our custom port and address
49+
{
50+
Serial.println(F("u-blox GNSS not detected. Retrying..."));
51+
delay (1000);
52+
}
53+
54+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
55+
56+
//myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Optional: save (only) the communications port settings to flash and BBR
57+
}
58+
59+
void loop()
60+
{
61+
// Request (poll) the position, velocity and time (PVT) information.
62+
// The module only responds when a new position is available. Default is once per second.
63+
// getPVT() returns true when new data is received.
64+
if (myGNSS.getPVT() == true)
65+
{
66+
int32_t latitude = myGNSS.getLatitude();
67+
Serial.print(F("Lat: "));
68+
Serial.print(latitude);
69+
70+
int32_t longitude = myGNSS.getLongitude();
71+
Serial.print(F(" Long: "));
72+
Serial.print(longitude);
73+
Serial.print(F(" (degrees * 10^-7)"));
74+
75+
int32_t altitude = myGNSS.getAltitudeMSL(); // Altitude above Mean Sea Level
76+
Serial.print(F(" Alt: "));
77+
Serial.print(altitude);
78+
Serial.print(F(" (mm)"));
79+
80+
Serial.println();
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Reading Position, Velocity and Time (PVT) via UBX binary commands
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: December 21st, 2022
6+
License: MIT. Please see LICENSE.md for more information.
7+
8+
This example shows how to query a u-blox module for its position, velocity and time (PVT) data using UART2.
9+
10+
UART2 is only available on modules like the ZED-F9P/R/T/K etc.. It is not available on the MAX-M10.
11+
12+
Important note:
13+
By default, the UBX protocol is enabled for INPUT on UART2, but not for OUTPUT.
14+
The code needs to enable UBX output for the begin to succeed.
15+
16+
Feel like supporting open source hardware?
17+
Buy a board from SparkFun!
18+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
19+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
20+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
21+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
22+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
23+
24+
Hardware Connections:
25+
Hook up the TX, RX and GND pins, plus 3V3 or 5V depending on your needs
26+
Connect: GNSS TX to microcontroller RX; GNSS RX to microcontroller TX
27+
Open the serial monitor at 115200 baud to see the output
28+
*/
29+
30+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
31+
32+
SFE_UBLOX_GNSS_SERIAL myGNSS;
33+
34+
#define mySerial Serial1 // Use Serial1 to connect to the GNSS module. Change this if required
35+
36+
void setup()
37+
{
38+
Serial.begin(115200);
39+
delay(1000);
40+
Serial.println("SparkFun u-blox Example");
41+
42+
mySerial.begin(38400); // u-blox F9 and M10 modules default to 38400 baud. Change this if required
43+
44+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
45+
46+
myGNSS.connectedToUART2(); // This tells the library we are connecting to UART2 so it uses the correct configuration keys
47+
48+
while (myGNSS.begin(mySerial) == false) //Connect to the u-blox module using mySerial (defined above)
49+
{
50+
Serial.println(F("u-blox GNSS not detected"));
51+
52+
Serial.println(F("Attempting to enable the UBX protocol for output"));
53+
54+
myGNSS.setUART2Output(COM_TYPE_UBX); // Enable UBX output. Disable NMEA output
55+
56+
Serial.println(F("Retrying..."));
57+
delay (1000);
58+
}
59+
60+
//myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Optional: save (only) the communications port settings to flash and BBR
61+
}
62+
63+
void loop()
64+
{
65+
// Request (poll) the position, velocity and time (PVT) information.
66+
// The module only responds when a new position is available. Default is once per second.
67+
// getPVT() returns true when new data is received.
68+
if (myGNSS.getPVT() == true)
69+
{
70+
int32_t latitude = myGNSS.getLatitude();
71+
Serial.print(F("Lat: "));
72+
Serial.print(latitude);
73+
74+
int32_t longitude = myGNSS.getLongitude();
75+
Serial.print(F(" Long: "));
76+
Serial.print(longitude);
77+
Serial.print(F(" (degrees * 10^-7)"));
78+
79+
int32_t altitude = myGNSS.getAltitudeMSL(); // Altitude above Mean Sea Level
80+
Serial.print(F(" Alt: "));
81+
Serial.print(altitude);
82+
Serial.print(F(" (mm)"));
83+
84+
Serial.println();
85+
}
86+
}

0 commit comments

Comments
 (0)