Skip to content

Commit fd5dfee

Browse files
committed
Add template VALSET and VALGET methods
1 parent 418f478 commit fd5dfee

File tree

5 files changed

+450
-110
lines changed

5 files changed

+450
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
Configuring u-blox Module using new VALGET / VALSET / VALDEL methods
3+
4+
Please see u-blox_config_keys.h for the definitions of _all_ of the configuration keys
5+
6+
By: Nathan Seidle
7+
SparkFun Electronics
8+
Date: January 3rd, 2019
9+
License: MIT. See license file for more information.
10+
11+
u-blox deprecated many -CFG messages and replaced them with new
12+
VALGET, VALSET, VALDEL methods. This shows the basics of how to use
13+
these methods.
14+
15+
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
16+
17+
Feel like supporting open source hardware?
18+
Buy a board from SparkFun!
19+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
20+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
21+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
22+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
23+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
24+
25+
Hardware Connections:
26+
Plug a Qwiic cable into the GNSS and a BlackBoard
27+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
28+
Open the serial monitor at 115200 baud to see the output
29+
*/
30+
31+
#include <Wire.h> //Needed for I2C to GNSS
32+
33+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
34+
SFE_UBLOX_GNSS myGNSS;
35+
36+
void setup()
37+
{
38+
delay(1000);
39+
40+
Serial.begin(115200);
41+
Serial.println("SparkFun u-blox Example");
42+
43+
Wire.begin();
44+
45+
myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
46+
47+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
48+
{
49+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
50+
while (1);
51+
}
52+
53+
// New in v3: we can set multiple configuration items at the same time without necessarily knowing the data width
54+
55+
myGNSS.newCfgValset(VAL_LAYER_RAM); // Create a new VALSET construct
56+
if (!myGNSS.addCfgValset(UBLOX_CFG_I2C_ADDRESS, 0x42 << 1)) // The module stores the address in shifted format. We need to shift the address left by 1 bit.
57+
Serial.println(F("addCfgValset(UBLOX_CFG_I2C_ADDRESS, 0x42) failed!"));
58+
if (!myGNSS.addCfgValset(UBLOX_CFG_I2COUTPROT_NMEA, 1))
59+
Serial.println(F("addCfgValset(UBLOX_CFG_I2COUTPROT_NMEA, 1) failed!"));
60+
if (!myGNSS.addCfgValset(UBLOX_CFG_UART1_BAUDRATE, 38400))
61+
Serial.println(F("addCfgValset(UBLOX_CFG_UART1_BAUDRATE, 38400) failed!"));
62+
if (!myGNSS.sendCfgValset())
63+
Serial.println(F("VALSET failed!"));
64+
65+
// New in v3: we can request multiple vals at the same time using a custom packet and newCfgValget, addCfgValget and sendCfgValget
66+
67+
// Let's create our custom packet
68+
uint8_t customPayload[MAX_PAYLOAD_SIZE]; // This array holds the payload data bytes
69+
70+
// The next line creates and initialises the packet information which wraps around the payload
71+
ubxPacket customCfg = {0, 0, 0, 0, 0, customPayload, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};
72+
73+
myGNSS.newCfgValget(&customCfg, VAL_LAYER_RAM); // Create a new VALGET construct
74+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
75+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA); // Get the flag indicating is NMEA should be output on I2C
76+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_UART1_BAUDRATE); // Get the UART1 baud rate
77+
if (myGNSS.sendCfgValget(&customCfg)) // Send the VALGET
78+
{
79+
// New in v3: we can use a template method to extract the value for us
80+
81+
uint8_t i2cAddress; // We still need to know the type...
82+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_I2C_ADDRESS, &i2cAddress, sizeof(i2cAddress))) // Get the I2C address - using the key
83+
{
84+
Serial.print(F("I2C Address: 0x"));
85+
Serial.println(i2cAddress >> 1, HEX); //We have to shift by 1 to get the common '7-bit' I2C address format
86+
}
87+
else
88+
{
89+
Serial.println(F("extractConfigValueByKey failed!"));
90+
}
91+
92+
bool nmeaI2c; // We still need to know the type...
93+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA, &nmeaI2c, sizeof(nmeaI2c))) // Get the I2COUTPROT_NMEA flag - using the key
94+
{
95+
Serial.print(F("Output NMEA over I2C port: 0x"));
96+
Serial.println(nmeaI2c, HEX);
97+
}
98+
else
99+
{
100+
Serial.println(F("extractConfigValueByKey failed!"));
101+
}
102+
103+
uint32_t baud; // We still need to know the type...
104+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_UART1_BAUDRATE, &baud, sizeof(baud))) // Get the baud rate - using the key
105+
{
106+
Serial.print(F("UART1 Baud Rate: "));
107+
Serial.println(baud);
108+
}
109+
else
110+
{
111+
Serial.println(F("extractConfigValueByKey failed!"));
112+
}
113+
}
114+
else
115+
{
116+
Serial.println(F("VALGET failed!"));
117+
}
118+
}
119+
120+
void loop()
121+
{
122+
}

keywords.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,12 @@ getVal32 KEYWORD2
227227
getVal64 KEYWORD2
228228

229229
newCfgValget KEYWORD2
230-
addCfgValgetN KEYWORD2
231-
addCfgValget8 KEYWORD2
232-
addCfgValget16 KEYWORD2
233-
addCfgValget32 KEYWORD2
234-
addCfgValget64 KEYWORD2
230+
addCfgValget KEYWORD2
235231
sendCfgValget KEYWORD2
236232
getNumGetCfgKeys KEYWORD2
237233
getLenCfgValGetResponse KEYWORD2
234+
getCfgValueSizeBytes KEYWORD2
235+
extractConfigValueByKey KEYWORD2
238236

239237
setValN KEYWORD2
240238
setVal8 KEYWORD2

0 commit comments

Comments
 (0)