Skip to content

Commit cd2f388

Browse files
committed
Adding GNSS functionality
1 parent 9513961 commit cd2f388

File tree

4 files changed

+227
-84
lines changed

4 files changed

+227
-84
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Use the GPS RMC sentence read feature to get position, speed, and clock data
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: October 20th 2020
6+
7+
Please see LICENSE.md for the license information
8+
9+
This example demonstrates how to use the gpsGetRmc feature.
10+
11+
This code is intend to run on the MicroMod Asset Tracker Carrier Board
12+
using (e.g.) the MicroMod Artemis Processor Board
13+
14+
Select the SparkFun RedBoard Artemis ATP from the SparkFun Apollo3 boards
15+
16+
*/
17+
18+
//Click here to get the library: http://librarymanager/All#SparkFun_u-blox_SARA-R5_Arduino_Library
19+
#include <SparkFun_u-blox_SARA-R5_Arduino_Library.h>
20+
21+
// Uncomment the next line to connect to the SARA-R5 using hardware Serial1
22+
#define saraSerial Serial1
23+
24+
// Uncomment the next line to create a SoftwareSerial object to pass to the SARA-R5 library instead
25+
//SoftwareSerial saraSerial(8, 9);
26+
27+
// Create a SARA_R5 object to use throughout the sketch
28+
SARA_R5 assetTracker;
29+
30+
PositionData gps;
31+
SpeedData spd;
32+
ClockData clk;
33+
boolean valid;
34+
35+
#define GPS_POLL_RATE 5000 // Read GPS every 2 seconds
36+
unsigned long lastGpsPoll = 0;
37+
38+
void setup() {
39+
Serial.begin(9600);
40+
41+
// Wait for user to press key in terminal to begin
42+
Serial.println("Press any key to begin GPS'ing");
43+
while (!Serial.available()) ;
44+
while (Serial.available()) Serial.read();
45+
46+
// Initialize the SARA
47+
if (assetTracker.begin(saraSerial, 9600) ) {
48+
Serial.println(F("Asset Tracker (SARA-R5) connected!"));
49+
}
50+
51+
// Enable the GPS's RMC sentence output. This will also turn the
52+
// GPS module on ((assetTracker.gpsPower(true)) if it's not already
53+
if (assetTracker.gpsEnableRmc(true) != SARA_R5_SUCCESS) {
54+
Serial.println(F("Error initializing GPS. Freezing..."));
55+
while (1) ;
56+
}
57+
}
58+
59+
void loop() {
60+
if ((lastGpsPoll == 0) || (lastGpsPoll + GPS_POLL_RATE < millis())) {
61+
// Call (assetTracker.gpsGetRmc to get coordinate, speed, and timing data
62+
// from the GPS module. Valid can be used to check if the GPS is
63+
// reporting valid data
64+
if (assetTracker.gpsGetRmc(&gps, &spd, &clk, &valid) == SARA_R5_SUCCESS) {
65+
printGPS();
66+
lastGpsPoll = millis();
67+
} else {
68+
delay(1000); // If RMC read fails, wait a second and try again
69+
}
70+
}
71+
}
72+
73+
void printGPS(void) {
74+
Serial.println();
75+
Serial.println("UTC: " + String(gps.utc));
76+
Serial.print("Time: ");
77+
if (clk.time.hour < 10) Serial.print('0'); // Print leading 0
78+
Serial.print(String(clk.time.hour) + ":");
79+
if (clk.time.minute < 10) Serial.print('0'); // Print leading 0
80+
Serial.print(String(clk.time.minute) + ":");
81+
if (clk.time.second < 10) Serial.print('0'); // Print leading 0
82+
Serial.print(String(clk.time.second) + ".");
83+
if (clk.time.ms < 10) Serial.print('0'); // Print leading 0
84+
Serial.println(String(clk.time.ms));
85+
Serial.println("Latitude: " + String(gps.lat, 7));
86+
Serial.println("Longitude: " + String(gps.lon, 7));
87+
Serial.println("Speed: " + String(spd.speed, 4) + " @ " + String(spd.cog, 4));
88+
Serial.println("Date: " + String(clk.date.month) + "/" +
89+
String(clk.date.day) + "/" + String(clk.date.year));
90+
Serial.println("Magnetic variation: " + String(spd.magVar));
91+
Serial.println("Status: " + String(gps.status));
92+
Serial.println("Mode: " + String(gps.mode));
93+
Serial.println();
94+
}

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ socketWrite KEYWORD2
9090
socketRead KEYWORD2
9191
socketListen KEYWORD2
9292
IPAddress lastRemoteIP KEYWORD2
93-
boolean gpsOn KEYWORD2
93+
boolean isGPSon KEYWORD2
9494
gpsPower KEYWORD2
9595
gpsEnableClock KEYWORD2
9696
gpsGetClock KEYWORD2

0 commit comments

Comments
 (0)