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

Commit dc08739

Browse files
authored
Merge branch 'master' into master
2 parents c7c8397 + bd8eff6 commit dc08739

File tree

6 files changed

+551
-4
lines changed

6 files changed

+551
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ SparkFun Ublox Arduino Library
77
<td><a href="https://www.sparkfun.com/products/15005"><img src="https://cdn.sparkfun.com//assets/parts/1/3/3/2/0/15005-SparkFun_GPS-RTK__Qwiic__-_NEO-M8P-2-00.jpg"></a></td>
88
<td><a href="https://www.sparkfun.com/products/15193"><img src="https://cdn.sparkfun.com//assets/parts/1/3/6/1/4/15193-SparkFun_GPS_Breakout_-_U.FL__ZOE-M8__Qwiic_-01.jpg"></a></td>
99
<td><a href="https://www.sparkfun.com/products/15210"><img src="https://cdn.sparkfun.com//assets/parts/1/3/6/4/8/15210-SparkFun_GPS_Breakout_-_Chip_Antenna__SAM-M8Q__Qwiic_-01.jpg"></a></td>
10+
<td><a href="https://www.sparkfun.com/products/15733"><img src="https://cdn.sparkfun.com//assets/parts/1/4/3/2/2/15733-SparkFun_GPS_Breakout_-_NEO-M9N__Chip_Antenna__Qwiic_-01.jpg"></a></td>
1011
</tr>
1112
<tr align="center">
1213
<td><a href="https://www.sparkfun.com/products/15136">SparkFun GPS-RTK2 - ZED-F9P (GPS-15136)</a></td>
1314
<td><a href="https://www.sparkfun.com/products/15005">SparkFun GPS-RTK - NEO-M8P-2 (GPS-15005)</a></td>
1415
<td><a href="https://www.sparkfun.com/products/15193">SparkFun ZOE-M8Q Breakout (GPS-15193)</a></td>
1516
<td><a href="https://www.sparkfun.com/products/15210">SparkFun SAM-M8Q Breakout (GPS-15210)</a></td>
17+
<td><a href="https://www.sparkfun.com/products/15733">SparkFun NEO-M9N Breakout (GPS-15733)</a></td>
1618
</tr>
1719
</table>
1820

@@ -30,7 +32,7 @@ Thanks to:
3032
* [tve](https://github.com/tve) for building out serial additions and examples
3133
* [Redstoned](https://github.com/Redstoned) and [davidallenmann](https://github.com/davidallenmann) for adding PVT date and time
3234
* [wittend](https://forum.sparkfun.com/viewtopic.php?t=49874) for pointing out the RTCM print bug
33-
* Big thanks to [PaulZC](https://github.com/PaulZC) for implementing the combined key ValSet method
35+
* Big thanks to [PaulZC](https://github.com/PaulZC) for implementing the combined key ValSet method and geofence functions
3436
* [RollieRowland](https://github.com/RollieRowland) for adding HPPOSLLH (High Precision Geodetic Position)
3537
* [tedder](https://github.com/tedder) for moving iTOW to PVT instead of HPPOS and comment cleanup
3638

@@ -89,6 +91,8 @@ Products That Use This Library
8991
* [GPS-15005](https://www.sparkfun.com/products/15005) - SparkFun GPS-RTK NEO-M8P-2
9092
* [GPS-15210](https://www.sparkfun.com/products/15210) - SparkFun GPS Breakout - Chip Antenna, SAM-M8Q (Qwiic)
9193
* [GPS-15193](https://www.sparkfun.com/products/15193) - SparkFun GPS Breakout - Chip Antenna, ZOE-M8Q (Qwiic)
94+
* [GPS-15733](https://www.sparkfun.com/products/15733) - SparkFun GPS Breakout - NEO-M9N, Chip Antenna (Qwiic)
95+
* [GPS-15712](https://www.sparkfun.com/products/15712) - SparkFun GPS Breakout - NEO-M9N, U.FL (Qwiic)
9296
* [SPX-14980](https://www.sparkfun.com/products/14980) - SparkX GPS-RTK Black
9397
* [SPX-15106](https://www.sparkfun.com/products/15106) - SparkX SAM-M8Q
9498

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
u-blox M8 geofence example
3+
4+
Written by Paul Clark (PaulZC)
5+
10th December 2019
6+
7+
License: MIT. See license file for more information but you can
8+
basically do whatever you want with this code.
9+
10+
This example demonstrates how to use the addGeofence and getGeofenceState functions
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/15210
17+
ZOE-M8Q: https://www.sparkfun.com/products/15193
18+
19+
This example powers up the GPS and reads the fix.
20+
Once a valid 3D fix has been found, the code reads the latitude and longitude.
21+
The code then sets four geofences around that position with a radii of 5m, 10m, 15m and 20m with 95% confidence.
22+
The code then monitors the geofence status.
23+
The LED will be illuminated if you are inside the _combined_ geofence (i.e. within the 20m radius).
24+
25+
This code has been tested on the ZOE-M8Q.
26+
*/
27+
28+
#define LED LED_BUILTIN // Change this if your LED is on a different pin
29+
30+
#include <Wire.h> // Needed for I2C
31+
32+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
33+
SFE_UBLOX_GPS myGPS;
34+
35+
void setup()
36+
{
37+
pinMode(LED, OUTPUT);
38+
39+
// Set up the I2C pins
40+
Wire.begin();
41+
42+
// Start the console serial port
43+
Serial.begin(115200);
44+
while (!Serial); // Wait for the user to open the serial monitor
45+
delay(100);
46+
Serial.println();
47+
Serial.println();
48+
Serial.println(F("u-blox M8 geofence example"));
49+
Serial.println();
50+
Serial.println();
51+
52+
delay(1000); // Let the GPS power up
53+
54+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
55+
{
56+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
57+
while (1);
58+
}
59+
60+
//myGPS.enableDebugging(); // Enable debug messages
61+
myGPS.setI2COutput(COM_TYPE_UBX); // Limit I2C output to UBX (disable the NMEA noise)
62+
63+
Serial.println(F("Waiting for a 3D fix..."));
64+
65+
byte fixType = 0;
66+
67+
while (fixType != 3)
68+
{
69+
fixType = myGPS.getFixType(); // Get the fix type
70+
Serial.print(F("Fix: ")); // Print it
71+
Serial.print(fixType);
72+
if(fixType == 0) Serial.print(F(" = No fix"));
73+
else if(fixType == 1) Serial.print(F(" = Dead reckoning"));
74+
else if(fixType == 2) Serial.print(F(" = 2D"));
75+
else if(fixType == 3) Serial.print(F(" = 3D"));
76+
else if(fixType == 4) Serial.print(F(" = GNSS + Dead reckoning"));
77+
Serial.println();
78+
delay(1000);
79+
}
80+
81+
Serial.println(F("3D fix found!"));
82+
83+
long latitude = myGPS.getLatitude(); // Get the latitude in degrees * 10^-7
84+
Serial.print(F("Lat: "));
85+
Serial.print(latitude);
86+
87+
long longitude = myGPS.getLongitude(); // Get the longitude in degrees * 10^-7
88+
Serial.print(F(" Long: "));
89+
Serial.println(longitude);
90+
91+
uint32_t radius = 500; // Set the radius to 5m (radius is in m * 10^-2 i.e. cm)
92+
93+
byte confidence = 2; // Set the confidence level: 0=none, 1=68%, 2=95%, 3=99.7%, 4=99.99%
94+
95+
// Call clearGeofences() to clear all existing geofences.
96+
Serial.print(F("Clearing any existing geofences. clearGeofences returned: "));
97+
Serial.println(myGPS.clearGeofences());
98+
99+
// It is possible to define up to four geofences.
100+
// Call addGeofence up to four times to define them.
101+
Serial.println(F("Setting the geofences:"));
102+
103+
Serial.print(F("addGeofence for geofence 1 returned: "));
104+
Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence));
105+
106+
radius = 1000; // 10m
107+
Serial.print(F("addGeofence for geofence 2 returned: "));
108+
Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence));
109+
110+
radius = 1500; // 15m
111+
Serial.print(F("addGeofence for geofence 3 returned: "));
112+
Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence));
113+
114+
radius = 2000; // 20m
115+
Serial.print(F("addGeofence for geofence 4 returned: "));
116+
Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence));
117+
}
118+
119+
void loop()
120+
{
121+
geofenceState currentGeofenceState; // Create storage for the geofence state
122+
123+
boolean result = myGPS.getGeofenceState(currentGeofenceState);
124+
125+
Serial.print(F("getGeofenceState returned: ")); // Print the combined state
126+
Serial.print(result); // Get the geofence state
127+
128+
if (!result) // If getGeofenceState did not return true
129+
{
130+
Serial.println(F(".")); // Tidy up
131+
return; // and go round the loop again
132+
}
133+
134+
Serial.print(F(". status is: ")); // Print the status
135+
Serial.print(currentGeofenceState.status);
136+
137+
Serial.print(F(". numFences is: ")); // Print the numFences
138+
Serial.print(currentGeofenceState.numFences);
139+
140+
Serial.print(F(". combState is: ")); // Print the combined state
141+
Serial.print(currentGeofenceState.combState);
142+
143+
if (currentGeofenceState.combState == 0)
144+
{
145+
Serial.print(F(" = Unknown"));
146+
digitalWrite(LED, LOW);
147+
}
148+
if (currentGeofenceState.combState == 1)
149+
{
150+
Serial.print(F(" = Inside"));
151+
digitalWrite(LED, HIGH);
152+
}
153+
else if (currentGeofenceState.combState == 2)
154+
{
155+
Serial.print(F(" = Outside"));
156+
digitalWrite(LED, LOW);
157+
}
158+
159+
Serial.print(F(". The individual states are: ")); // Print the state of each geofence
160+
for(int i = 0; i < currentGeofenceState.numFences; i++)
161+
{
162+
if (i > 0) Serial.print(F(","));
163+
Serial.print(currentGeofenceState.states[i]);
164+
}
165+
Serial.println();
166+
167+
delay(1000);
168+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
Power Save Mode
3+
By: Paul Clark (PaulZC)
4+
Date: December 18th, 2019
5+
6+
Based extensively on Example3_GetPosition
7+
By: Nathan Seidle
8+
SparkFun Electronics
9+
Date: January 3rd, 2019
10+
License: MIT. See license file for more information but you can
11+
basically do whatever you want with this code.
12+
13+
This example shows how to put the Ublox module into power save mode and then
14+
query its lat/long/altitude. We also turn off the NMEA output on the I2C port.
15+
This decreases the amount of I2C traffic dramatically.
16+
17+
** When it is able to ** the module will reduce its current draw.
18+
For the ZOE-M8Q with a passive antenna, you should see the current drop
19+
from (approx.) 25-28mA to (approx.) 9mA when power save mode kicks in.
20+
21+
Note: this will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
22+
23+
Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
24+
to something google maps understands simply divide the numbers by 10,000,000. We
25+
do this so that we don't have to use floating point numbers.
26+
27+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
28+
29+
Feel like supporting open source hardware?
30+
Buy a board from SparkFun!
31+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
32+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
33+
SAM-M8Q: https://www.sparkfun.com/products/15106
34+
35+
Hardware Connections:
36+
Plug a Qwiic cable into the GPS and a BlackBoard
37+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
38+
Open the serial monitor at 115200 baud to see the output
39+
*/
40+
41+
#include <Wire.h> //Needed for I2C to GPS
42+
43+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
44+
SFE_UBLOX_GPS myGPS;
45+
46+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
47+
48+
void setup()
49+
{
50+
Serial.begin(115200);
51+
while (!Serial)
52+
; //Wait for user to open terminal
53+
Serial.println("SparkFun Ublox Example");
54+
55+
Wire.begin();
56+
57+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
58+
{
59+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
60+
while (1)
61+
;
62+
}
63+
64+
//myGPS.enableDebugging(); // Uncomment this line to enable debug messages
65+
66+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
67+
//myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR
68+
69+
Serial.println("Power save example.");
70+
Serial.println("1) Enable power saving");
71+
Serial.println("2) Disable power saving");
72+
}
73+
74+
void loop()
75+
{
76+
if (Serial.available())
77+
{
78+
byte incoming = Serial.read();
79+
80+
if (incoming == '1')
81+
{
82+
// Put the GNSS into power save mode
83+
// (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead)
84+
// This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
85+
if (myGPS.powerSaveMode())
86+
Serial.println(F("Power Save Mode enabled."));
87+
else
88+
Serial.println(F("***!!! Power Save Mode FAILED !!!***"));
89+
}
90+
else if (incoming == '2')
91+
{
92+
//Go to normal power mode (not power saving mode)
93+
if (myGPS.powerSaveMode(false))
94+
Serial.println(F("Power Save Mode disabled."));
95+
else
96+
Serial.println(F("***!!! Power Save Disable FAILED !!!***"));
97+
}
98+
}
99+
100+
//Query module every 10 seconds so it is easier to monitor the current draw
101+
if (millis() - lastTime > 10000)
102+
{
103+
lastTime = millis(); //Update the timer
104+
105+
byte fixType = myGPS.getFixType(); // Get the fix type
106+
Serial.print(F("Fix: "));
107+
Serial.print(fixType);
108+
if (fixType == 0)
109+
Serial.print(F("(No fix)"));
110+
else if (fixType == 1)
111+
Serial.print(F("(Dead reckoning)"));
112+
else if (fixType == 2)
113+
Serial.print(F("(2D)"));
114+
else if (fixType == 3)
115+
Serial.print(F("(3D)"));
116+
else if (fixType == 4)
117+
Serial.print(F("(GNSS + Dead reckoning)"));
118+
119+
long latitude = myGPS.getLatitude();
120+
Serial.print(F(" Lat: "));
121+
Serial.print(latitude);
122+
123+
long longitude = myGPS.getLongitude();
124+
Serial.print(F(" Long: "));
125+
Serial.print(longitude);
126+
Serial.print(F(" (degrees * 10^-7)"));
127+
128+
long altitude = myGPS.getAltitude();
129+
Serial.print(F(" Alt: "));
130+
Serial.print(altitude);
131+
Serial.print(F(" (mm)"));
132+
133+
Serial.println();
134+
}
135+
}

keywords.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ getGeoidSeparation KEYWORD2
121121
getHorizontalAccuracy KEYWORD2
122122
getVerticalAccuracy KEYWORD2
123123

124+
addGeofence KEYWORD2
125+
clearGeofences KEYWORD2
126+
getGeofenceState KEYWORD2
127+
128+
powerSaveMode KEYWORD2
129+
124130
#######################################
125131
# Constants (LITERAL1)
126132
#######################################

0 commit comments

Comments
 (0)