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

Commit cae7884

Browse files
committed
Adding examples. Removing a few.
1 parent 67f7919 commit cae7884

File tree

7 files changed

+516
-110
lines changed

7 files changed

+516
-110
lines changed

examples/Example3_GetPosition/Example3_GetPosition.ino

Lines changed: 34 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
License: MIT. See license file for more information but you can
77
basically do whatever you want with this code.
88
9-
This example shows how to query a Ublox module for its lat/long/altitude. Leave NMEA
10-
parsing behind. Now you can simply ask the module for the datums you want!
9+
This example shows how to query a Ublox module for its lat/long/altitude.
10+
11+
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
13+
do this so that we don't have to use floating point numbers.
14+
15+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
1116
1217
Feel like supporting open source hardware?
1318
Buy a board from SparkFun!
@@ -36,120 +41,39 @@ void setup()
3641

3742
Wire.begin();
3843

39-
myGPS.begin(); //Connect to the Ublox module using Wire port
40-
if (myGPS.isConnected() == false)
44+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
4145
{
4246
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
4347
while (1);
4448
}
45-
46-
//Wire.setClock(400000); //Increase I2C clock speed to 400kHz
47-
48-
/*byte response;
49-
response = myGPS.getVal(VAL_GROUP_I2C, VAL_ID_I2C_ADDRESS, VAL_GROUP_I2C_SIZE, VAL_LAYER_RAM);
50-
Serial.print("res: 0x");
51-
Serial.println(response, HEX);
52-
53-
delay(100);
54-
55-
response = myGPS.getVal(VAL_GROUP_I2COUTPROT, VAL_ID_I2COUTPROT_NMEA, VAL_GROUP_I2COUTPROT_SIZE, VAL_LAYER_RAM);
56-
Serial.print("res: 0x");
57-
Serial.print(response, HEX);
58-
while(1);*/
59-
60-
61-
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
62-
myGPS.setNavigationFrequency(4); //Set output to 4 times a second
63-
64-
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
65-
Serial.print("Update rate:");
66-
Serial.println(rate);
67-
68-
while(1);
69-
70-
/*long pos = myGPS.getPositionAccuracy();
71-
Serial.print("pos: ");
72-
Serial.println(pos);
73-
74-
byte version = myGPS.getProtocolVersionHigh();
75-
Serial.print("version: ");
76-
Serial.println(version);*/
77-
78-
long latitude = myGPS.getLatitude(1000);
79-
Serial.print("Lat: ");
80-
Serial.print(latitude);
81-
82-
83-
long longitude = myGPS.getLongitude(2000);
84-
Serial.print(" Long: ");
85-
Serial.print(longitude);
86-
Serial.print(" (degrees * 10^-7)");
87-
88-
long altitude = myGPS.getAltitude();
89-
Serial.print(" Alt (above mean sea level): ");
90-
Serial.print(altitude);
91-
Serial.print(" (mm)");
92-
93-
byte SIV = myGPS.getSIV();
94-
Serial.print(" SIV: ");
95-
Serial.print(SIV);
96-
97-
byte fixType = myGPS.getFixType();
98-
Serial.print(" Fix: ");
99-
Serial.print(fixType);
100-
101-
byte RTK = myGPS.getCarrierSolutionType();
102-
Serial.print(" RTK: ");
103-
Serial.print(RTK);
104-
if (RTK == 1) Serial.println("High precision float fix!");
105-
if (RTK == 2) Serial.println("High precision fix!");
106-
107-
long speed = myGPS.getGroundSpeed();
108-
Serial.print(" Speed: ");
109-
Serial.print(speed);
110-
Serial.print(" (mm/s)");
111-
112-
long heading = myGPS.getHeading();
113-
Serial.print(" Heading: ");
114-
Serial.print(heading);
115-
Serial.print(" (degrees * 10^-5)");
116-
117-
int pDOP = myGPS.getPDOP();
118-
Serial.print(" pDOP: ");
119-
Serial.print(pDOP / 100.0, 2);
120-
121-
while (1);
12249
}
12350

12451
void loop()
12552
{
126-
/* myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
127-
128-
delay(250); //Don't pound too hard on the I2C bus
129-
130-
//Every other second print the current 3D position accuracy
131-
if (millis() - lastTime > 1000)
132-
{
133-
long latitude = myGPS.getLatitude();
134-
Serial.print("Lat: ");
135-
Serial.print(latitude);
136-
137-
while (1);
138-
139-
long longitude = myGPS.getLongitude();
140-
Serial.print(" Long: ");
141-
Serial.print(longitude);
142-
Serial.print(" (degrees * 10^-7)");
143-
144-
long altitude = myGPS.getAltitude();
145-
Serial.print(" Alt (above mean sea level): ");
146-
Serial.print(altitude);
147-
Serial.print(" (mm)");
148-
149-
long altitudeEllipsoid = myGPS.getAltitudeEllipsoid();
150-
Serial.print(" AltMSL (above Ellipsoid model surface of earth): ");
151-
Serial.print(altitudeEllipsoid);
152-
Serial.println(" (mm)");
153-
}*/
154-
53+
//Query module only every second. Doing it more often will just cause I2C traffic.
54+
//The module only responds when a new position is available
55+
if (millis() - lastTime > 1000)
56+
{
57+
lastTime = millis(); //Update the timer
58+
59+
long latitude = myGPS.getLatitude();
60+
Serial.print(F("Lat: "));
61+
Serial.print(latitude);
62+
63+
long longitude = myGPS.getLongitude();
64+
Serial.print(F(" Long: "));
65+
Serial.print(longitude);
66+
Serial.print(F(" (degrees * 10^-7)"));
67+
68+
long altitude = myGPS.getAltitude();
69+
Serial.print(F(" Alt (above mean sea level): "));
70+
Serial.print(altitude);
71+
Serial.print(F(" (mm)"));
72+
73+
byte SIV = myGPS.getSIV();
74+
Serial.print(F(" SIV: "));
75+
Serial.print(SIV);
76+
77+
Serial.println();
78+
}
15579
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Get fix type and RTK fix type if available
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 fix type and RTK fix type.
10+
The fix type is as follows:
11+
0 = no fix
12+
1 = dead reckoning (requires external sensors)
13+
2 = 2D (not quite enough satellites in view)
14+
3 = 3D (the standard fix)
15+
4 = GNSS + dead reckoning (requires external sensors)
16+
5 = Time fix only
17+
18+
Additionally, if we are doing RTK, we can figure out if we have a floating
19+
RTK solution or if we have been able to resolve a fixec solution (better precision).
20+
21+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
22+
23+
Feel like supporting open source hardware?
24+
Buy a board from SparkFun!
25+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
26+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
27+
SAM-M8Q: https://www.sparkfun.com/products/15106
28+
29+
Hardware Connections:
30+
Plug a Qwiic cable into the GPS and a BlackBoard
31+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
32+
Open the serial monitor at 115200 baud to see the output
33+
*/
34+
35+
#include <Wire.h> //Needed for I2C to GPS
36+
37+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
38+
SFE_UBLOX_GPS myGPS;
39+
40+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
41+
42+
void setup()
43+
{
44+
Serial.begin(115200);
45+
while (!Serial); //Wait for user to open terminal
46+
Serial.println("Reading Lat/Long Example");
47+
48+
Wire.begin();
49+
Wire.setClock(400000); //Optional. Increase I2C clock speed to 400kHz.
50+
51+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
52+
{
53+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
54+
while (1);
55+
}
56+
}
57+
58+
void loop()
59+
{
60+
//Query module only every second. Doing it more often will just cause I2C traffic.
61+
if (millis() - lastTime > 1000)
62+
{
63+
lastTime = millis(); //Update the timer
64+
65+
long latitude = myGPS.getLatitude();
66+
Serial.print(F("Lat: "));
67+
Serial.print(latitude);
68+
69+
long longitude = myGPS.getLongitude();
70+
Serial.print(F(" Long: "));
71+
Serial.print(longitude);
72+
73+
long altitude = myGPS.getAltitude();
74+
Serial.print(F(" Alt: "));
75+
Serial.print(altitude);
76+
77+
byte fixType = myGPS.getFixType();
78+
Serial.print(F(" Fix: "));
79+
if(fixType == 0) Serial.print(F("No fix"));
80+
else if(fixType == 1) Serial.print(F("Dead reckoning"));
81+
else if(fixType == 2) Serial.print(F("2D"));
82+
else if(fixType == 3) Serial.print(F("3D"));
83+
else if(fixType == 4) Serial.print(F("GNSS+Dead reckoning"));
84+
85+
byte RTK = myGPS.getCarrierSolutionType();
86+
Serial.print(" RTK: ");
87+
Serial.print(RTK);
88+
if (RTK == 1) Serial.print(F("High precision float fix!"));
89+
if (RTK == 2) Serial.print(F("High precision fix!"));
90+
91+
Serial.println();
92+
}
93+
94+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Get Speed/Heading and dilution of precision via UBX binary commands - no more NMEA parsing!
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+
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
13+
do this so that we don't have to use floating point numbers.
14+
15+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
16+
17+
Feel like supporting open source hardware?
18+
Buy a board from SparkFun!
19+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
20+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
21+
SAM-M8Q: https://www.sparkfun.com/products/15106
22+
23+
Hardware Connections:
24+
Plug a Qwiic cable into the GPS and a BlackBoard
25+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
26+
Open the serial monitor at 115200 baud to see the output
27+
*/
28+
29+
#include <Wire.h> //Needed for I2C to GPS
30+
31+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
32+
SFE_UBLOX_GPS myGPS;
33+
34+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
35+
36+
void setup()
37+
{
38+
Serial.begin(115200);
39+
while (!Serial); //Wait for user to open terminal
40+
Serial.println("Reading Lat/Long Example");
41+
42+
Wire.begin();
43+
44+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
45+
{
46+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
47+
while (1);
48+
}
49+
}
50+
51+
void loop()
52+
{
53+
//Query module only every second. Doing it more often will just cause I2C traffic.
54+
//The module only responds when a new position is available
55+
if (millis() - lastTime > 1000)
56+
{
57+
lastTime = millis(); //Update the timer
58+
59+
long latitude = myGPS.getLatitude();
60+
Serial.print(F("Lat: "));
61+
Serial.print(latitude);
62+
63+
long longitude = myGPS.getLongitude();
64+
Serial.print(F(" Long: "));
65+
Serial.print(longitude);
66+
67+
long speed = myGPS.getGroundSpeed();
68+
Serial.print(F(" Speed: "));
69+
Serial.print(speed);
70+
Serial.print(F(" (mm/s)"));
71+
72+
long heading = myGPS.getHeading();
73+
Serial.print(F(" Heading: "));
74+
Serial.print(heading);
75+
Serial.print(F(" (degrees * 10^-5)"));
76+
77+
int pDOP = myGPS.getPDOP();
78+
Serial.print(F(" pDOP: "));
79+
Serial.print(pDOP / 100.0, 2);
80+
81+
Serial.println();
82+
}
83+
}

0 commit comments

Comments
 (0)