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

Commit 08e78b6

Browse files
authored
Merge pull request #2 from tve/serial-support
Add support for serial protocol, plus factory reset command
2 parents 77130a9 + 445bed8 commit 08e78b6

File tree

4 files changed

+410
-98
lines changed

4 files changed

+410
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Reading lat and long via UBX binary commands using UART @38400 baud - free from I2C
3+
By: Nathan Seidle, Adapted from Example3_GetPosition by Thorsten von Eicken
4+
SparkFun Electronics
5+
Date: January 28rd, 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 configure the library and U-Blox for serial port use as well as
10+
switching the module from the default 9600 baud to 38400.
11+
12+
Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
13+
to something google maps understands simply divide the numbers by 10,000,000. We
14+
do this so that we don't have to use floating point numbers.
15+
16+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
17+
18+
Feel like supporting open source hardware?
19+
Buy a board from SparkFun!
20+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
21+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
22+
SAM-M8Q: https://www.sparkfun.com/products/15106
23+
24+
Hardware Connections:
25+
Connect the U-Blox serial port to Serial1
26+
Open the serial monitor at 115200 baud to see the output
27+
*/
28+
29+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
30+
SFE_UBLOX_GPS myGPS;
31+
32+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
33+
34+
void setup()
35+
{
36+
Serial.begin(115200);
37+
while (!Serial); //Wait for user to open terminal
38+
Serial.println("SparkFun Ublox Example");
39+
40+
//Assume that the U-Blox GPS is running at 9600 baud (the default) or at 38400 baud.
41+
//Loop until we're in sync and then ensure it's at 38400 baud.
42+
do {
43+
Serial.println("GPS: trying 38400 baud");
44+
Serial1.begin(38400);
45+
if (myGPS.begin(Serial1)) break;
46+
47+
delay(100);
48+
Serial.println("GPS: trying 9600 baud");
49+
Serial1.begin(9600);
50+
if (myGPS.begin(Serial1)) {
51+
Serial.println("GPS: connected at 9600 baud, switching to 38400");
52+
myGPS.setSerialRate(38400);
53+
delay(100);
54+
} else {
55+
//gps.factoryReset();
56+
delay(2000); //Wait a bit before trying again to limit the Serial output
57+
}
58+
} while(1);
59+
Serial.println("GPS serial connected");
60+
61+
myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only
62+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
63+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
64+
}
65+
66+
void loop()
67+
{
68+
//Query module only every second. Doing it more often will just cause I2C traffic.
69+
//The module only responds when a new position is available
70+
if (millis() - lastTime > 1000)
71+
{
72+
lastTime = millis(); //Update the timer
73+
74+
long latitude = myGPS.getLatitude();
75+
Serial.print(F("Lat: "));
76+
Serial.print(latitude);
77+
78+
long longitude = myGPS.getLongitude();
79+
Serial.print(F(" Long: "));
80+
Serial.print(longitude);
81+
Serial.print(F(" (degrees * 10^-7)"));
82+
83+
long altitude = myGPS.getAltitude();
84+
Serial.print(F(" Alt: "));
85+
Serial.print(altitude);
86+
Serial.print(F(" (mm)"));
87+
88+
byte SIV = myGPS.getSIV();
89+
Serial.print(F(" SIV: "));
90+
Serial.print(SIV);
91+
92+
Serial.println();
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Test baud rate changes on serial, factory reset, and hard reset.
3+
By: Thorsten von Eicken
4+
Date: January 29rd, 2019
5+
License: MIT. See license file for more information but you can
6+
basically do whatever you want with this code.
7+
8+
This example shows how to reset the U-Box module.
9+
10+
Feel like supporting open source hardware?
11+
Buy a board from SparkFun!
12+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
13+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
14+
SAM-M8Q: https://www.sparkfun.com/products/15106
15+
16+
Hardware Connections:
17+
Connect the U-Blox serial port to Serial1
18+
Open the serial monitor at 115200 baud to see the output
19+
*/
20+
21+
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS
22+
SFE_UBLOX_GPS myGPS;
23+
24+
int state = 0; // steps through auto-baud, reset, etc states
25+
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
while (!Serial); //Wait for user to open terminal
30+
Serial.println("SparkFun Ublox Example");
31+
}
32+
33+
void loop()
34+
{
35+
Serial.print("===== STATE ");
36+
Serial.println(state);
37+
switch (state) {
38+
case 0: // auto-baud connection, then switch to 38400 and save config
39+
do {
40+
Serial.println("GPS: trying 38400 baud");
41+
Serial1.begin(38400);
42+
if (myGPS.begin(Serial1)) break;
43+
44+
delay(100);
45+
Serial.println("GPS: trying 9600 baud");
46+
Serial1.begin(9600);
47+
if (myGPS.begin(Serial1)) {
48+
Serial.println("GPS: connected at 9600 baud, switching to 38400");
49+
myGPS.setSerialRate(38400);
50+
delay(100);
51+
} else {
52+
delay(2000); //Wait a bit before trying again to limit the Serial output flood
53+
}
54+
} while(1);
55+
myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only
56+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
57+
Serial.println("GPS serial connected, saved config");
58+
state++;
59+
break;
60+
case 1: // hardReset, expect to see GPS back at 38400 baud
61+
Serial.println("Issuing hardReset (cold start)");
62+
myGPS.hardReset();
63+
delay(1000);
64+
Serial1.begin(38400);
65+
if (myGPS.begin(Serial1)) {
66+
Serial.println("Success.");
67+
state++;
68+
} else {
69+
Serial.println("*** GPS did not respond at 38400 baud, starting over.");
70+
state = 0;
71+
}
72+
break;
73+
case 2: // factoryReset, expect to see GPS back at 9600 baud
74+
Serial.println("Issuing factoryReset");
75+
myGPS.factoryReset();
76+
delay(2000); // takes more than one second... a loop to resync would be best
77+
Serial1.begin(9600);
78+
if (myGPS.begin(Serial1)) {
79+
Serial.println("Success.");
80+
state++;
81+
} else {
82+
Serial.println("*** GPS did not come back at 9600 baud, starting over.");
83+
state = 0;
84+
}
85+
break;
86+
case 3: // print version info
87+
Serial.print("GPS protocol version: ");
88+
Serial.print(myGPS.getProtocolVersionHigh());
89+
Serial.print('.');
90+
Serial.print(myGPS.getProtocolVersionLow());
91+
state = 0;
92+
}
93+
delay(1000);
94+
}

0 commit comments

Comments
 (0)