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

Commit 5d5387d

Browse files
committed
Adding examples
1 parent cae7884 commit 5d5387d

File tree

12 files changed

+190
-47
lines changed

12 files changed

+190
-47
lines changed

examples/Example1_BasicNMEARead/Example1_BasicNMEARead.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,16 @@ SFE_UBLOX_GPS myGPS;
2929
void setup()
3030
{
3131
Serial.begin(115200);
32-
Serial.println("Ublox GPS I2C Test");
32+
Serial.println("SparkFun Ublox Example");
3333

3434
Wire.begin();
3535

36-
myGPS.begin();
37-
if (myGPS.isConnected() == false)
36+
if (myGPS.begin() == false)
3837
{
3938
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
4039
while (1);
4140
}
4241

43-
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
44-
4542
//This will pipe all NMEA sentences to the serial port so we can see them
4643
myGPS.setNMEAOutputPort(Serial);
4744
}

examples/Example2_NMEAParsing/Example2_NMEAParsing.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));
3636
void setup()
3737
{
3838
Serial.begin(115200);
39-
Serial.println("Ublox GPS I2C Test");
39+
Serial.println("SparkFun Ublox Example");
4040

4141
Wire.begin();
4242

43-
myGPS.begin();
44-
if (myGPS.isConnected() == false)
43+
if (myGPS.begin() == false)
4544
{
4645
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
4746
while (1);
4847
}
49-
50-
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
5148
}
5249

5350
void loop()

examples/Example3_GetPosition/Example3_GetPosition.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
This example shows how to query a Ublox module for its lat/long/altitude.
1010
1111
Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
12-
to something google maps understands simply divide the numbers by 1,000,000. We
12+
to something google maps understands simply divide the numbers by 10,000,000. We
1313
do this so that we don't have to use floating point numbers.
1414
1515
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
@@ -31,13 +31,13 @@
3131
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
3232
SFE_UBLOX_GPS myGPS;
3333

34-
long lastTime = 0; //Tracks the passing of 2000ms (2 seconds)
34+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
3535

3636
void setup()
3737
{
3838
Serial.begin(115200);
3939
while (!Serial); //Wait for user to open terminal
40-
Serial.println("Reading Lat/Long Example");
40+
Serial.println("SparkFun Ublox Example");
4141

4242
Wire.begin();
4343

@@ -66,7 +66,7 @@ void loop()
6666
Serial.print(F(" (degrees * 10^-7)"));
6767

6868
long altitude = myGPS.getAltitude();
69-
Serial.print(F(" Alt (above mean sea level): "));
69+
Serial.print(F(" Alt: "));
7070
Serial.print(altitude);
7171
Serial.print(F(" (mm)"));
7272

examples/Example4_FixType/Example4_FixType.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void setup()
4343
{
4444
Serial.begin(115200);
4545
while (!Serial); //Wait for user to open terminal
46-
Serial.println("Reading Lat/Long Example");
46+
Serial.println("SparkFun Ublox Example");
4747

4848
Wire.begin();
4949
Wire.setClock(400000); //Optional. Increase I2C clock speed to 400kHz.

examples/Example5_SpeedHeadingPrecision/Example5_SpeedHeadingPrecision.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void setup()
3737
{
3838
Serial.begin(115200);
3939
while (!Serial); //Wait for user to open terminal
40-
Serial.println("Reading Lat/Long Example");
40+
Serial.println("SparkFun Ublox Example");
4141

4242
Wire.begin();
4343

examples/Example6_OutputRate/Example6_OutputRate.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void setup()
4040
{
4141
Serial.begin(115200);
4242
while (!Serial); //Wait for user to open terminal
43-
Serial.println("Reading Lat/Long Example");
43+
Serial.println("SparkFun Ublox Example");
4444

4545
Wire.begin();
4646
Wire.setClock(400000);

examples/Example8_GetProtocolVersion/Example8_GetProtocolVersion.ino renamed to examples/Example7_GetProtocolVersion/Example7_GetProtocolVersion.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void setup()
3737
{
3838
Serial.begin(115200);
3939
while (!Serial); //Wait for user to open terminal
40-
Serial.println("Reading Lat/Long Example");
40+
Serial.println("SparkFun Ublox Example");
4141

4242
Wire.begin();
4343

@@ -51,8 +51,8 @@ void setup()
5151
byte versionHigh = myGPS.getProtocolVersionHigh();
5252
Serial.print(versionHigh);
5353
Serial.print(".");
54-
//byte versionLow = myGPS.getProtocolVersionLow();
55-
//Serial.print(versionLow);
54+
byte versionLow = myGPS.getProtocolVersionLow();
55+
Serial.print(versionLow);
5656
}
5757

5858
void loop()

examples/Example8_ChangeI2CAddress/Example8_ChangeI2CAddress.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void setup()
3131
{
3232
Serial.begin(115200);
3333
while (!Serial); //Wait for user to open terminal
34-
Serial.println("Reading Lat/Long Example");
34+
Serial.println("SparkFun Ublox Example");
3535

3636
Wire.begin();
3737

examples/Example9_All/Example9_All.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
2727
SFE_UBLOX_GPS myGPS;
2828

29-
long lastTime = 0; //Tracks the passing of 2000ms (2 seconds)
29+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
3030

3131
void setup()
3232
{
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Reading two altitudes - Mean Sea Level and Ellipsode
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: January 3rd, 2019
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 query a Ublox module for its lat/long/altitude.
10+
11+
getAltitude() reports mm above ellipsode model of the globe. There are some
12+
instances where altitude above Mean Sea Level is better. This example shows how
13+
to use getAltitudeMSL(). The difference varies but is ~20m.
14+
Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html
15+
Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/
16+
17+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
18+
19+
Feel like supporting open source hardware?
20+
Buy a board from SparkFun!
21+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
22+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
23+
SAM-M8Q: https://www.sparkfun.com/products/15106
24+
25+
Hardware Connections:
26+
Plug a Qwiic cable into the GPS and a BlackBoard
27+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
28+
Open the serial monitor at 115200 baud to see the output
29+
*/
30+
31+
#include <Wire.h> //Needed for I2C to GPS
32+
33+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
34+
SFE_UBLOX_GPS myGPS;
35+
36+
long lastTime = 0; //Tracks the passing of 2000ms (2 seconds)
37+
38+
void setup()
39+
{
40+
Serial.begin(115200);
41+
while (!Serial); //Wait for user to open terminal
42+
Serial.println("SparkFun Ublox Example");
43+
44+
Wire.begin();
45+
46+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
47+
{
48+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
49+
while (1);
50+
}
51+
}
52+
53+
void loop()
54+
{
55+
//Query module only every second. Doing it more often will just cause I2C traffic.
56+
//The module only responds when a new position is available
57+
if (millis() - lastTime > 1000)
58+
{
59+
lastTime = millis(); //Update the timer
60+
61+
long latitude = myGPS.getLatitude();
62+
Serial.print(F("Lat: "));
63+
Serial.print(latitude);
64+
65+
long longitude = myGPS.getLongitude();
66+
Serial.print(F(" Long: "));
67+
Serial.print(longitude);
68+
Serial.print(F(" (degrees * 10^-7)"));
69+
70+
long altitude = myGPS.getAltitude();
71+
Serial.print(F(" Alt: "));
72+
Serial.print(altitude);
73+
Serial.print(F(" (mm)"));
74+
75+
long altitudeMSL = myGPS.getAltitudeMSL();
76+
Serial.print(F(" AltMSL: "));
77+
Serial.print(altitudeMSL);
78+
Serial.print(F(" (mm)"));
79+
80+
Serial.println();
81+
}
82+
}

0 commit comments

Comments
 (0)