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

Commit b22eff8

Browse files
committed
Adding support for callbacks. Added the callback for PVT plus an example.
1 parent ea2aa70 commit b22eff8

File tree

4 files changed

+415
-264
lines changed

4 files changed

+415
-264
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Configuring the GPS to automatically send position reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: December 30th, 2020
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 to send navigation reports automatically
10+
and access the data via a callback.
11+
12+
Feel like supporting open source hardware?
13+
Buy a board from SparkFun!
14+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
16+
SAM-M8Q: https://www.sparkfun.com/products/15106
17+
18+
Hardware Connections:
19+
Plug a Qwiic cable into the GPS and a BlackBoard
20+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
21+
Open the serial monitor at 115200 baud to see the output
22+
*/
23+
24+
#include <Wire.h> //Needed for I2C to GPS
25+
26+
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GPS
27+
SFE_UBLOX_GPS myGPS;
28+
29+
void printPVTdata() // Define the callback for NAV PVT
30+
{
31+
Serial.println();
32+
33+
Serial.print(F("Time: "));
34+
uint8_t hms = myGPS.packetUBXNAVPVTcopy->hour;
35+
if (hms < 10) Serial.print(F("0")); Serial.print(hms); Serial.print(F(":"));
36+
hms = myGPS.packetUBXNAVPVTcopy->min;
37+
if (hms < 10) Serial.print(F("0")); Serial.print(hms); Serial.print(F(":"));
38+
hms = myGPS.packetUBXNAVPVTcopy->sec;
39+
if (hms < 10) Serial.print(F("0")); Serial.print(hms); Serial.print(F("."));
40+
unsigned long millisecs = myGPS.packetUBXNAVPVTcopy->iTOW % 1000;
41+
Serial.print(millisecs);
42+
43+
long latitude = myGPS.packetUBXNAVPVTcopy->lat;
44+
Serial.print(F(" Lat: "));
45+
Serial.print(latitude);
46+
47+
long longitude = myGPS.packetUBXNAVPVTcopy->lon;
48+
Serial.print(F(" Long: "));
49+
Serial.print(longitude);
50+
Serial.print(F(" (degrees * 10^-7)"));
51+
52+
long altitude = myGPS.packetUBXNAVPVTcopy->hMSL;
53+
Serial.print(F(" Height above MSL: "));
54+
Serial.print(altitude);
55+
Serial.println(F(" (mm)"));
56+
}
57+
58+
void setup()
59+
{
60+
Serial.begin(115200);
61+
while (!Serial); //Wait for user to open terminal
62+
Serial.println("SparkFun Ublox Example");
63+
64+
Wire.begin();
65+
66+
//myGPS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
67+
68+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
69+
{
70+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
71+
while (1);
72+
}
73+
74+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
75+
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
76+
77+
myGPS.setNavigationFrequency(2); //Produce two solutions per second
78+
79+
myGPS.setAutoPVT(printPVTdata); // Enable automatic PVT messages with callback
80+
}
81+
82+
void loop()
83+
{
84+
myGPS.checkUblox(); // Check for the arrival of new data and process it.
85+
myGPS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
86+
87+
Serial.print(".");
88+
delay(50);
89+
}

0 commit comments

Comments
 (0)