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

Commit 146aa31

Browse files
committed
Adding configurable debug example 14
1 parent a3621c2 commit 146aa31

File tree

4 files changed

+131
-49
lines changed

4 files changed

+131
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 debug output from the library.
10+
Debug shows various packet and status outputs. These prints can be directed
11+
towards Serial (as in Serial.print) or any other port (Serial1, SerialUSB, etc).
12+
13+
Feel like supporting open source hardware?
14+
Buy a board from SparkFun!
15+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
16+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
17+
SAM-M8Q: https://www.sparkfun.com/products/15106
18+
19+
Hardware Connections:
20+
Connect the U-Blox serial TX pin to Uno pin 10
21+
Connect the U-Blox serial RX pin to Uno pin 11
22+
Open the serial monitor at 115200 baud to see the output
23+
*/
24+
25+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
26+
SFE_UBLOX_GPS myGPS;
27+
28+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
while (!Serial); //Wait for user to open terminal
34+
Serial.println("SparkFun Ublox Example");
35+
36+
Wire.begin();
37+
38+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
39+
{
40+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
41+
while (1);
42+
}
43+
44+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
45+
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
46+
47+
myGPS.enableDebugging(); //Enable debug messages over Serial (default)
48+
//myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB
49+
50+
}
51+
52+
void loop()
53+
{
54+
//Query module only every second. Doing it more often will just cause I2C traffic.
55+
//The module only responds when a new position is available
56+
if (millis() - lastTime > 1000)
57+
{
58+
lastTime = millis(); //Update the timer
59+
60+
long latitude = myGPS.getLatitude();
61+
Serial.print(F("Lat: "));
62+
Serial.print(latitude);
63+
64+
long longitude = myGPS.getLongitude();
65+
Serial.print(F(" Long: "));
66+
Serial.print(longitude);
67+
Serial.print(F(" (degrees * 10^-7)"));
68+
69+
long altitude = myGPS.getAltitude();
70+
Serial.print(F(" Alt: "));
71+
Serial.print(altitude);
72+
Serial.print(F(" (mm)"));
73+
74+
byte SIV = myGPS.getSIV();
75+
Serial.print(F(" SIV: "));
76+
Serial.print(SIV);
77+
78+
Serial.println();
79+
}
80+
}

keywords.txt

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ getProtocolVersion KEYWORD2
8080

8181
getRELPOSNED KEYWORD2
8282

83+
enableDebugging KEYWORD2
84+
disableDebugging KEYWORD2
85+
8386
factoryReset KEYWORD2
8487
setAutoPVT KEYWORD2
8588

src/SparkFun_Ublox_Arduino_Library.cpp

+45-41
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ boolean SFE_UBLOX_GPS::begin(Stream &serialPort)
6363

6464
//Enable or disable the printing of sent/response HEX values.
6565
//Use this in conjunction with 'Transport Logging' from the Universal Reader Assistant to see what they're doing that we're not
66-
void RFID::enableDebugging(Stream &debugPort)
66+
void SFE_UBLOX_GPS::enableDebugging(Stream &debugPort)
6767
{
6868
_debugSerial = &debugPort; //Grab which port the user wants us to use for debugging
6969

7070
_printDebug = true; //Should we print the commands we send? Good for debugging
7171
}
72-
void RFID::disableDebugging(void)
72+
void SFE_UBLOX_GPS::disableDebugging(void)
7373
{
7474
_printDebug = false; //Turn off extra print statements
7575
}
@@ -115,8 +115,8 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
115115

116116
if (_printDebug == true)
117117
{
118-
debug.print("Current baud rate: ");
119-
debug.println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
118+
_debugSerial->print("Current baud rate: ");
119+
_debugSerial->println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
120120
}
121121

122122
packetCfg.cls = UBX_CLASS_CFG;
@@ -132,8 +132,8 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
132132

133133
if (_printDebug == true)
134134
{
135-
debug.print("New baud rate:");
136-
debug.println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
135+
_debugSerial->print("New baud rate:");
136+
_debugSerial->println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
137137
}
138138

139139
sendCommand(packetCfg);
@@ -203,7 +203,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
203203
{
204204
if (_printDebug == true)
205205
{
206-
debug.println("No bytes available");
206+
_debugSerial->println("No bytes available");
207207
}
208208
lastCheck = millis(); //Put off checking to avoid I2C bus traffic
209209
return true;
@@ -259,10 +259,10 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
259259
if (_printDebug == true)
260260
{
261261
//if (currentSentence == NONE && incoming == 0xB5) //UBX binary frames start with 0xB5, aka μ
262-
// debug.println(); //Show new packet start
262+
// _debugSerial->println(); //Show new packet start
263263

264-
//debug.print(" ");
265-
//debug.print(incoming, HEX);
264+
//_debugSerial->print(" ");
265+
//_debugSerial->print(incoming, HEX);
266266
}
267267

268268
if (currentSentence == NONE || currentSentence == NMEA)
@@ -447,15 +447,18 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
447447
{
448448
if (_printDebug == true)
449449
{
450-
debug.print("Received: ");
450+
_debugSerial->print("Received: ");
451451
printPacket(incomingUBX);
452452
}
453453
incomingUBX->valid = true;
454454
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
455455
}
456-
if (_printDebug == true)
456+
else
457457
{
458-
else debug.println("Checksum failed. Response too big?");
458+
if (_printDebug == true)
459+
{
460+
_debugSerial->println("Checksum failed. Response too big?");
461+
}
459462
}
460463
}
461464
else //Load this byte into the payload array
@@ -488,7 +491,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
488491
//The ack we just received matched the CLS/ID of last packetCfg sent
489492
if (_printDebug == true)
490493
{
491-
debug.println("Command sent/ack'd successfully");
494+
_debugSerial->println("Command sent/ack'd successfully");
492495
}
493496
commandAck = true;
494497
}
@@ -535,7 +538,7 @@ boolean SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t maxWait)
535538

536539
if (_printDebug == true)
537540
{
538-
debug.print("Sending: ");
541+
_debugSerial->print("Sending: ");
539542
printPacket(&outgoingUBX);
540543
}
541544
if (commType == COMM_TYPE_I2C)
@@ -697,23 +700,23 @@ void SFE_UBLOX_GPS::printPacket(ubxPacket *packet)
697700
{
698701
if (_printDebug == true)
699702
{
700-
debug.print("CLS:");
701-
debug.print(packet->cls, HEX);
703+
_debugSerial->print("CLS:");
704+
_debugSerial->print(packet->cls, HEX);
702705

703-
debug.print(" ID:");
704-
debug.print(packet->id, HEX);
706+
_debugSerial->print(" ID:");
707+
_debugSerial->print(packet->id, HEX);
705708

706-
//debug.print(" Len: 0x");
707-
//debug.print(packet->len, HEX);
709+
//_debugSerial->print(" Len: 0x");
710+
//_debugSerial->print(packet->len, HEX);
708711

709-
debug.print(" Payload:");
712+
_debugSerial->print(" Payload:");
710713

711714
for (int x = 0; x < packet->len; x++)
712715
{
713-
debug.print(" ");
714-
debug.print(packet->payload[x], HEX);
716+
_debugSerial->print(" ");
717+
_debugSerial->print(packet->payload[x], HEX);
715718
}
716-
debug.println();
719+
_debugSerial->println();
717720
}
718721
}
719722

@@ -740,15 +743,15 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
740743
{
741744
if (_printDebug == true)
742745
{
743-
debug.println(F("CLS/ID match!"));
746+
_debugSerial->println(F("CLS/ID match!"));
744747
}
745748
return (true); //If the packet we just sent was a NAV packet then we'll just get data back
746749
}
747-
if (_printDebug == true)
750+
else
748751
{
749-
else
752+
if (_printDebug == true)
750753
{
751-
debug.print(F("Packet didn't match CLS/ID"));
754+
_debugSerial->print(F("Packet didn't match CLS/ID"));
752755
printPacket(&packetCfg);
753756
}
754757
}
@@ -759,7 +762,7 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
759762

760763
if (_printDebug == true)
761764
{
762-
debug.println(F("waitForResponse timeout"));
765+
_debugSerial->println(F("waitForResponse timeout"));
763766
}
764767

765768
return (false);
@@ -832,9 +835,9 @@ uint8_t SFE_UBLOX_GPS::getVal(uint16_t group, uint16_t id, uint8_t size, uint8_t
832835

833836
if (_printDebug == true)
834837
{
835-
debug.print("key: 0x");
836-
debug.print(key, HEX);
837-
debug.println();
838+
_debugSerial->print("key: 0x");
839+
_debugSerial->print(key, HEX);
840+
_debugSerial->println();
838841
}
839842

840843
//Load key into outgoing payload
@@ -849,9 +852,9 @@ uint8_t SFE_UBLOX_GPS::getVal(uint16_t group, uint16_t id, uint8_t size, uint8_t
849852

850853
if (_printDebug == true)
851854
{
852-
debug.print("response (should be 0x01): 0x");
853-
debug.print(payloadCfg[0], HEX);
854-
debug.println();
855+
_debugSerial->print("response (should be 0x01): 0x");
856+
_debugSerial->print(payloadCfg[0], HEX);
857+
_debugSerial->println();
855858
}
856859

857860
//Pull the requested value from the response
@@ -1349,17 +1352,18 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
13491352

13501353
if (_printDebug == true)
13511354
{
1352-
debug.print("Extension ");
1353-
debug.print(extensionNumber);
1354-
debug.print(": ");
1355+
_debugSerial->print("Extension ");
1356+
_debugSerial->print(extensionNumber);
1357+
_debugSerial->print(": ");
13551358
for (int location = 0; location < MAX_PAYLOAD_SIZE; location++)
13561359
{
13571360
if (payloadCfg[location] == '\0')
13581361
break;
1359-
debug.write(payloadCfg[location]);
1362+
_debugSerial->write(payloadCfg[location]);
13601363
}
1361-
debug.println();
1364+
_debugSerial->println();
13621365
}
1366+
13631367
//Now we need to find "PROTVER=18.00" in the incoming byte stream
13641368
if (payloadCfg[0] == 'P' && payloadCfg[6] == 'R')
13651369
{

src/SparkFun_Ublox_Arduino_Library.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@
3737

3838
#include <Wire.h>
3939

40-
//Uncomment the following line to enable a variety of debug statements
41-
//This will increase the codeword and RAM footprint of the library
42-
//#define DEBUG
43-
44-
#ifdef DEBUG
45-
#define debug Serial //Point debug statements to print to Serial port
46-
#endif
47-
4840
//Platform specific configurations
4941

5042
//Define the size of the I2C buffer based on the platform the user has
@@ -270,6 +262,9 @@ class SFE_UBLOX_GPS
270262

271263
boolean getRELPOSNED(uint16_t maxWait = 1000); //Get Relative Positioning Information of the NED frame
272264

265+
void enableDebugging(Stream &debugPort = Serial); //Given a port to print to, enable debug messages
266+
void disableDebugging(void);
267+
273268
//Survey-in specific controls
274269
struct svinStructure
275270
{

0 commit comments

Comments
 (0)