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

Commit e687f07

Browse files
committed
Adding example 5 - base station with LCD
1 parent 9aca60e commit e687f07

File tree

3 files changed

+184
-1
lines changed

3 files changed

+184
-1
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The NEO-M8P-2 module is the top-of-the-line module for high accuracy GNSS and GP
99

1010
This library allows the reading of NMEA data over I2C as well as sending binary UBX configuration commands over I2C. This is helpful for configuring advanced modules like the NEO-M8P-2.
1111

12+
Need a library for the Ublox and Particle? Checkout the [Particle library](https://github.com/aseelye/SparkFun_Ublox_Particle_Library) fork.
13+
1214
Repository Contents
1315
-------------------
1416

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
Send UBX binary commands to enable RTCM sentences on Ublox NEO-M8P-2 module
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: September 7th, 2018
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 does all steps to configure and enable a NEO-M8P-2 as a base station:
10+
Begin Survey-In
11+
Once we've achieved 2m accuracy and 300s have passed, survey is complete
12+
Enable four RTCM messages
13+
Begin outputting RTCM bytes
14+
15+
Feel like supporting open source hardware?
16+
Buy a board from SparkFun! https://www.sparkfun.com/products/14980
17+
18+
Hardware Connections:
19+
Plug a Qwiic cable into the GPS and a BlackBoard
20+
Plug a SerLCD onto the Qwiic bus
21+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
22+
Watch the output on the LCD or open the serial monitor at 115200 baud to see the output
23+
*/
24+
25+
#define STAT_LED 13
26+
27+
#include <Wire.h> //Needed for I2C to GPS
28+
29+
#include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS
30+
SFE_UBLOX_GPS myGPS;
31+
32+
#include <SerLCD.h> //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD
33+
SerLCD lcd; // Initialize the library with default I2C address 0x72
34+
35+
void setup()
36+
{
37+
Serial.begin(115200);
38+
while (!Serial); //Wait for user to open terminal
39+
Serial.println("Ublox GPS I2C Test");
40+
41+
pinMode(STAT_LED, OUTPUT);
42+
digitalWrite(STAT_LED, LOW);
43+
44+
lcd.begin(Wire); //Set up the LCD for Serial communication at 9600bps
45+
lcd.setBacklight(0x4B0082); //indigo, a kind of dark purplish blue
46+
lcd.clear();
47+
lcd.print(F("LCD Ready"));
48+
49+
myGPS.begin(Wire);
50+
if (myGPS.isConnected() == false)
51+
{
52+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
53+
lcd.setCursor(0, 1);
54+
lcd.print(F("No GPS detected"));
55+
while (1);
56+
}
57+
58+
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
59+
60+
lcd.setCursor(0, 1);
61+
lcd.print("GPS Detected");
62+
63+
//Check if Survey is in Progress before initiating one
64+
boolean response;
65+
response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time)
66+
if (response == false)
67+
{
68+
Serial.println(F("Failed to get Survey In status"));
69+
while (1); //Freeze
70+
}
71+
72+
if (myGPS.svin.active == true)
73+
{
74+
Serial.print(F("Survey already in progress."));
75+
lcd.setCursor(0, 2);
76+
lcd.print(F("Survey already going"));
77+
}
78+
else
79+
{
80+
//Start survey
81+
response = myGPS.enableSurveyMode(300, 2.000); //Enable Survey in, 300 seconds, 2.0m
82+
if (response == false)
83+
{
84+
Serial.println(F("Survey start failed"));
85+
lcd.setCursor(0, 3);
86+
lcd.print(F("Survey start failed"));
87+
while (1);
88+
}
89+
Serial.println(F("Survey started. This will run until 300s has passed and less than 2m accuracy is achieved."));
90+
}
91+
92+
while (Serial.available()) Serial.read(); //Clear buffer
93+
94+
lcd.clear();
95+
lcd.print(F("Survey in progress"));
96+
97+
//Begin waiting for survey to complete
98+
while (myGPS.svin.valid == false)
99+
{
100+
if (Serial.available())
101+
{
102+
byte incoming = Serial.read();
103+
if (incoming == 'x')
104+
{
105+
//Stop survey mode
106+
response = myGPS.disableSurveyMode(); //Disable survey
107+
Serial.println(F("Survey stopped"));
108+
break;
109+
}
110+
}
111+
112+
response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time)
113+
if (response == true)
114+
{
115+
Serial.print(F("Press x to end survey - "));
116+
Serial.print(F("Time elapsed: "));
117+
Serial.print((String)myGPS.svin.observationTime);
118+
119+
lcd.setCursor(0, 1);
120+
lcd.print(F("Elapsed: "));
121+
lcd.print((String)myGPS.svin.observationTime);
122+
123+
Serial.print(F(" Accuracy: "));
124+
Serial.print((String)myGPS.svin.meanAccuracy);
125+
Serial.println();
126+
127+
lcd.setCursor(0, 2);
128+
lcd.print(F("Accuracy: "));
129+
lcd.print((String)myGPS.svin.meanAccuracy);
130+
}
131+
else
132+
{
133+
Serial.println(F("SVIN request failed"));
134+
}
135+
136+
delay(1000);
137+
}
138+
Serial.println(F("Survey valid!"));
139+
140+
response = true;
141+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, UBX_RTCM_I2C_PORT, 1); //Enable message 1005 to output through I2C port, message every second
142+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, UBX_RTCM_I2C_PORT, 1);
143+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, UBX_RTCM_I2C_PORT, 1);
144+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, UBX_RTCM_I2C_PORT, 10); //Enable message every 10 seconds
145+
146+
if (response == true)
147+
{
148+
Serial.println(F("RTCM messages enabled"));
149+
}
150+
else
151+
{
152+
Serial.println(F("RTCM failed to enable. Are you sure you have an NEO-M8P?"));
153+
while (1); //Freeze
154+
}
155+
156+
Serial.println(F("Base survey complete! RTCM now broadcasting."));
157+
lcd.clear();
158+
lcd.print(F("Transmitting RTCM"));
159+
}
160+
161+
void loop()
162+
{
163+
myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
164+
165+
//Do anything you want. Call checkUblox() every second. NEO-M8P-2 has TX buffer of 4k bytes.
166+
167+
delay(250); //Don't pound too hard on the I2C bus
168+
}
169+
170+
//This function gets called from the SparkFun Ublox Arduino Library.
171+
//As each RTCM byte comes in you can specify what to do with it
172+
//Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc.
173+
void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
174+
{
175+
//Let's just pretty-print the HEX values for now
176+
if (myGPS.rtcmFrameCounter % 16 == 0) Serial.println();
177+
Serial.print(" ");
178+
if (incoming < 0x10) Serial.print("0");
179+
Serial.print(incoming, HEX);
180+
}
181+

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Ublox Arduino Library
2-
version=1.0.1
2+
version=1.0.2
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C Communication with Ublox modules

0 commit comments

Comments
 (0)