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

Commit f27def0

Browse files
authored
Merge pull request #54 from grexjmo/master
Added setCFG_MSG command and example
2 parents bd8eff6 + dc08739 commit f27def0

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
@@ -1639,6 +1639,20 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
16391639
return ok;
16401640
}
16411641

1642+
boolean SFE_UBLOX_GPS::setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait)
1643+
{
1644+
packetCfg.cls = UBX_CLASS_CFG;
1645+
packetCfg.id = UBX_CFG_MSG;
1646+
packetCfg.len = 3;
1647+
packetCfg.startingSpot = 0;
1648+
payloadCfg[0] = msgClass;
1649+
payloadCfg[1] = messageID;
1650+
payloadCfg[2] = rate;
1651+
1652+
bool ok = sendCommand(packetCfg, maxWait);
1653+
return ok;
1654+
}
1655+
16421656
//Add a new geofence using UBX-CFG-GEOFENCE
16431657
boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t radius, byte confidence, byte pinPolarity, byte pin, uint16_t maxWait)
16441658
{

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
@@ -118,6 +119,17 @@ const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in hig
118119
const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status
119120
const uint8_t UBX_NAV_RELPOSNED = 0x3C; //Relative Positioning Information in NED frame
120121

122+
const uint8_t UBX_NMEA_GGA = 0x00;
123+
const uint8_t UBX_NMEA_GLL = 0x01;
124+
const uint8_t UBX_NMEA_GNS = 0x0D;
125+
const uint8_t UBX_NMEA_GRS = 0x06;
126+
const uint8_t UBX_NMEA_GSA = 0x02;
127+
const uint8_t UBX_NMEA_GST = 0x07;
128+
const uint8_t UBX_NMEA_GSV = 0x03;
129+
const uint8_t UBX_NMEA_RMC = 0x04;
130+
const uint8_t UBX_NMEA_VTG = 0x05;
131+
const uint8_t UBX_NMEA_ZDA = 0x08;
132+
121133
const uint8_t UBX_MON_VER = 0x04; //Used for obtaining Protocol Version
122134
const uint8_t UBX_MON_TXBUF = 0x08; //Used for query tx buffer size/state
123135

@@ -258,6 +270,7 @@ class SFE_UBLOX_GPS
258270
boolean waitForResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = 250); //Poll the module until and ack is received
259271

260272
boolean assumeAutoPVT(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and PVT is send cyclically already
273+
boolean setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait = 250);
261274
boolean setAutoPVT(boolean enabled, uint16_t maxWait = 250); //Enable/disable automatic PVT reports at the navigation frequency
262275
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.
263276
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)