-
Notifications
You must be signed in to change notification settings - Fork 23
/
Example7_Auto_PositionVelocityTime.ino
88 lines (68 loc) · 2.98 KB
/
Example7_Auto_PositionVelocityTime.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Reading Position, Velocity and Time (PVT) via UBX binary commands
By: Paul Clark
SparkFun Electronics
Date: December 21st, 2022
License: MIT. Please see LICENSE.md for more information.
This example shows how to instruct a u-blox module to output its position, velocity and time (PVT) data periodically.
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.
Note: Lat/Lon are large numbers because they are * 10^7. To convert lat/lon
to something google maps understands simply divide the numbers by 10,000,000.
Feel like supporting open source hardware?
Buy a board from SparkFun!
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
Hardware Connections:
Plug a Qwiic cable into the GNSS and your microcontroller board
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/
#include <Wire.h> //Needed for I2C to GNSS
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
SFE_UBLOX_GNSS myGNSS;
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("SparkFun u-blox Example");
Wire.begin(); // Start I2C
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
while (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
{
Serial.println(F("u-blox GNSS not detected at default I2C address. Retrying..."));
delay (1000);
}
myGNSS.setI2COutput(COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
myGNSS.setNavigationFrequency(2); // Produce two solutions per second
myGNSS.setAutoPVT(true); // Tell the GNSS to output each solution periodically
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
}
void loop()
{
// Check if fresh position, velocity and time (PVT) information is available.
// getPVT returns true if there is a fresh navigation solution available.
if (myGNSS.getPVT() == true)
{
Serial.println();
int32_t latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
int32_t longitude = myGNSS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
int32_t altitude = myGNSS.getAltitudeMSL(); // Altitude above Mean Sea Level
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
Serial.println();
}
else
{
Serial.print(".");
delay(50);
}
}