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

Commit c7c8397

Browse files
committed
Added setCFG_MSG command and example
1 parent 9268475 commit c7c8397

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
#include <Wire.h> //Needed for I2C to GPS
3+
4+
#include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS
5+
SFE_UBLOX_GPS myGPS;
6+
7+
unsigned long lastGPSSend = 0;
8+
9+
void setup()
10+
{
11+
Serial.begin(9600); // Serial debug output over USB visible from Arduino IDE
12+
Serial1.begin(9600); // NMEA serial UART output port to SPP bluetooth device such as HC-06
13+
14+
Wire.begin();
15+
16+
if (myGPS.begin() == false)
17+
{
18+
Serial.println(F("Error initializing GPS"));
19+
while (1);
20+
}
21+
22+
myGPS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX);
23+
myGPS.setCFG_MSG(UBX_CLASS_NAV, UBX_NAV_PVT, 0); //Some of the other examples enable this message
24+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GLL, 0); //Several of these are on by default on virgin ublox board
25+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GSA, 0);
26+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GSV, 0);
27+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_RMC, 0);
28+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GGA, 1); //Only leaving GGA/VTG enabled at current navigation rate
29+
myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_VTG, 1);
30+
31+
myGPS.setNMEAOutputPort(Serial1);
32+
}
33+
34+
void loop()
35+
{
36+
if (millis() - lastGPSSend > 200){
37+
myGPS.checkUblox(); //See if new data is available, NMEA message will be auto-forwarded out Serial1
38+
lastGPSSend = millis();
39+
}
40+
}

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,20 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
16381638
return ok;
16391639
}
16401640

1641+
boolean SFE_UBLOX_GPS::setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait)
1642+
{
1643+
packetCfg.cls = UBX_CLASS_CFG;
1644+
packetCfg.id = UBX_CFG_MSG;
1645+
packetCfg.len = 3;
1646+
packetCfg.startingSpot = 0;
1647+
payloadCfg[0] = msgClass;
1648+
payloadCfg[1] = messageID;
1649+
payloadCfg[2] = rate;
1650+
1651+
bool ok = sendCommand(packetCfg, maxWait);
1652+
return ok;
1653+
}
1654+
16411655
//Given a spot in the payload array, extract four bytes and build a long
16421656
uint32_t SFE_UBLOX_GPS::extractLong(uint8_t spotToStart)
16431657
{

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const uint8_t UBX_CLASS_MGA = 0x13;
9494
const uint8_t UBX_CLASS_LOG = 0x21;
9595
const uint8_t UBX_CLASS_SEC = 0x27;
9696
const uint8_t UBX_CLASS_HNR = 0x28;
97+
const uint8_t UBX_CLASS_NMEA = 0xF0;
9798

9899
const uint8_t UBX_CFG_PRT = 0x00; //Used to configure port specifics
99100
const uint8_t UBX_CFG_RST = 0x04; //Used to reset device
@@ -113,6 +114,17 @@ const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in hig
113114
const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status
114115
const uint8_t UBX_NAV_RELPOSNED = 0x3C; //Relative Positioning Information in NED frame
115116

117+
const uint8_t UBX_NMEA_GGA = 0x00;
118+
const uint8_t UBX_NMEA_GLL = 0x01;
119+
const uint8_t UBX_NMEA_GNS = 0x0D;
120+
const uint8_t UBX_NMEA_GRS = 0x06;
121+
const uint8_t UBX_NMEA_GSA = 0x02;
122+
const uint8_t UBX_NMEA_GST = 0x07;
123+
const uint8_t UBX_NMEA_GSV = 0x03;
124+
const uint8_t UBX_NMEA_RMC = 0x04;
125+
const uint8_t UBX_NMEA_VTG = 0x05;
126+
const uint8_t UBX_NMEA_ZDA = 0x08;
127+
116128
const uint8_t UBX_MON_VER = 0x04; //Used for obtaining Protocol Version
117129
const uint8_t UBX_MON_TXBUF = 0x08; //Used for query tx buffer size/state
118130

@@ -235,6 +247,7 @@ class SFE_UBLOX_GPS
235247
boolean waitForResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = 250); //Poll the module until and ack is received
236248

237249
boolean assumeAutoPVT(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and PVT is send cyclically already
250+
boolean setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait = 250);
238251
boolean setAutoPVT(boolean enabled, uint16_t maxWait = 250); //Enable/disable automatic PVT reports at the navigation frequency
239252
boolean getPVT(uint16_t maxWait = 1000); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc. If autoPVT is disabled, performs an explicit poll and waits, if enabled does not block. Retruns true if new PVT is available.
240253
boolean setAutoPVT(boolean enabled, boolean implicitUpdate, uint16_t maxWait = 250); //Enable/disable automatic PVT reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update

0 commit comments

Comments
 (0)