Skip to content

Commit a3b52a5

Browse files
committed
Update VALSET and VALGET examples for the template methods
1 parent b58b98e commit a3b52a5

File tree

15 files changed

+367
-63
lines changed

15 files changed

+367
-63
lines changed

examples/Callbacks/CallbackExample1_NAV_PVT/CallbackExample1_NAV_PVT.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: December 30th, 2020
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send navigation reports automatically
109
and access the data via a callback. No more polling!
1110
1211
Feel like supporting open source hardware?
1312
Buy a board from SparkFun!
14-
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15-
NEO-M8P RTK: https://www.sparkfun.com/products/15005
16-
SAM-M8Q: https://www.sparkfun.com/products/15106
13+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
14+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
15+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
16+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
17+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
1718
1819
Hardware Connections:
1920
Plug a Qwiic cable into the GPS and a BlackBoard

examples/Callbacks/CallbackExample2_NAV_ODO/CallbackExample2_NAV_ODO.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: December 30th, 2020
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send odometer reports automatically
109
and display the data via a callback. No more polling!
1110
1211
Feel like supporting open source hardware?
1312
Buy a board from SparkFun!
14-
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15-
NEO-M8P RTK: https://www.sparkfun.com/products/15005
16-
SAM-M8Q: https://www.sparkfun.com/products/15106
13+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
14+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
15+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
16+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
17+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
1718
1819
Hardware Connections:
1920
Plug a Qwiic cable into the GPS and a BlackBoard

examples/Callbacks/CallbackExample3_TIM_TM2/CallbackExample3_TIM_TM2.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: December 30th, 2020
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send TIM TM2 reports automatically
109
and display the data via a callback. No more polling!

examples/Callbacks/CallbackExample4_RAWX/CallbackExample4_RAWX.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: March 11th, 2021
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send RXM RAWX reports automatically
109
and access the data via a callback. No more polling!

examples/Callbacks/CallbackExample5_NAV_SAT/CallbackExample5_NAV_SAT.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: December 1st, 2021
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send NAV SAT reports automatically
109
and access the data via a callback. No more polling!

examples/Callbacks/CallbackExample6_UseCallbackDataInLoop/CallbackExample6_UseCallbackDataInLoop.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
By: Paul Clark
44
SparkFun Electronics
55
Date: April 15th, 2022
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to access the callback data from the main loop.
109
The simple way to check if new data is available is to use a global flag: set it in the callback, check it and clear it in the main loop.
@@ -13,9 +12,11 @@
1312
1413
Feel like supporting open source hardware?
1514
Buy a board from SparkFun!
16-
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
17-
NEO-M8P RTK: https://www.sparkfun.com/products/15005
18-
SAM-M8Q: https://www.sparkfun.com/products/15106
15+
SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136
16+
SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481
17+
SparkFun MAX-M10S Breakout (GPS-18037) https://www.sparkfun.com/products/18037
18+
SparkFun ZED-F9K Breakout (GPS-18719) https://www.sparkfun.com/products/18719
19+
SparkFun ZED-F9R Breakout (GPS-16344) https://www.sparkfun.com/products/16344
1920
2021
Hardware Connections:
2122
Plug a Qwiic cable into the GPS and a BlackBoard

examples/NEO-D9S_and_NEO-D9C/Example5_QZSSL6_Corrections_with_NEO-D9C/Example5_QZSSL6_Corrections_with_NEO-D9C.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
By: SparkFun Electronics / Paul Clark
44
Based on original code by: u-blox AG / Michael Ammann
55
Date: September 23rd, 2022
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure a NEO-D9C QZSS-L6 receiver and have it send coorection data to a ZED-F9x via Serial (UART).
109

examples/VALGET_and_VALSET/Example1_GetVal/Example1_GetVal.ino

+24-8
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ void setup()
105105
// The next line creates and initialises the packet information which wraps around the payload
106106
ubxPacket customCfg = {0, 0, 0, 0, 0, customPayload, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};
107107

108-
myGNSS.newCfgValget(&customCfg, VAL_LAYER_RAM); // Create a new VALGET construct. Read the data from the RAM layer.
108+
myGNSS.newCfgValget(&customCfg, 9, VAL_LAYER_RAM); // Create a new VALGET construct. Read the data from the RAM layer.
109109

110-
myGNSS.addCfgValget8(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
110+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
111111

112112
if (myGNSS.sendCfgValget(&customCfg) == true) // Send the VALGET
113113
{
@@ -121,17 +121,33 @@ void setup()
121121

122122
// We can also use the "extract" helper functions to read the data - useful for 16, 32 and 64-bit values
123123
// The full list is:
124-
// uint64_t extractLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
125-
// uint32_t extractLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into long
126-
// int32_t extractSignedLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into signed long (avoiding any ambiguity caused by casting)
127-
// uint16_t extractInt(ubxPacket *msg, uint16_t spotToStart); // Combine two bytes from payload into int
124+
// uint64_t extractLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
125+
// uint64_t extractSignedLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into int64_t
126+
// uint32_t extractLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into long
127+
// int32_t extractSignedLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into signed long (avoiding any ambiguity caused by casting)
128+
// uint16_t extractInt(ubxPacket *msg, uint16_t spotToStart); // Combine two bytes from payload into int
128129
// int16_t extractSignedInt(ubxPacket *msg, uint16_t spotToStart);
129-
// uint8_t extractByte(ubxPacket *msg, uint16_t spotToStart); // Get byte from payload
130-
// int8_t extractSignedChar(ubxPacket *msg, uint16_t spotToStart); // Get signed 8-bit value from payload
130+
// uint8_t extractByte(ubxPacket *msg, uint16_t spotToStart); // Get byte from payload
131+
// int8_t extractSignedChar(ubxPacket *msg, uint16_t spotToStart); // Get signed 8-bit value from payload
132+
// float extractFloat(ubxPacket *msg, uint16_t spotToStart); // Get 32-bit float from payload
133+
// double extractDouble(ubxPacket *msg, uint16_t spotToStart); // Get 64-bit double from payload
131134

132135
Serial.print("6: Current I2C address (should be 0x42): 0x");
133136
currentI2Caddress = myGNSS.extractByte(&customCfg, 8);
134137
Serial.println(currentI2Caddress >> 1, HEX); //u-blox module returns a shifted 8-bit address. Make it 7-bit unshifted.
138+
139+
// New in v3: we can use a template method to extract the value for us
140+
141+
uint8_t i2cAddress; // We still need to know the type...
142+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_I2C_ADDRESS, &i2cAddress, sizeof(i2cAddress))) // Get the I2C address - using the key
143+
{
144+
Serial.print(F("7: Current I2C address (should be 0x42): 0x"));
145+
Serial.println(i2cAddress >> 1, HEX); //We have to shift by 1 to get the common '7-bit' I2C address format
146+
}
147+
else
148+
{
149+
Serial.println(F("extractConfigValueByKey failed!"));
150+
}
135151
}
136152
else
137153
{

examples/VALGET_and_VALSET/Example2_SetVal/Example2_SetVal.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void setup()
5757
//You can obtain them from the ZED-F9P interface description doc
5858
//or from u-center's Messages->CFG->VALSET window. Keys must be 32-bit.
5959

60-
setValueSuccess &= myGNSS.setVal8(UBLOX_CFG_NMEA_HIGHPREC, 0); //Enable high precision NMEA. UBLOX_CFG_NMEA_HIGHPREC is L (bool) but we use 8-bits (uint8_t)
60+
setValueSuccess &= myGNSS.setVal8(UBLOX_CFG_NMEA_HIGHPREC, 1); //Enable high precision NMEA. UBLOX_CFG_NMEA_HIGHPREC is L (bool) but we use 8-bits (uint8_t)
6161

6262
//setValueSuccess &= myGNSS.setVal16(UBLOX_CFG_RATE_MEAS, 100); //Set measurement rate to 100ms (10Hz update rate). UBLOX_CFG_RATE_MEAS is 16-bit U2 (uint16_t)
6363
setValueSuccess &= myGNSS.setVal16(UBLOX_CFG_RATE_MEAS, 1000); //Set measurement rate to 1000ms (1Hz update rate). UBLOX_CFG_RATE_MEAS is 16-bit U2 (uint16_t)

examples/VALGET_and_VALSET/Example4_multiSetVal/Example4_multiSetVal.ino

+29-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ void setup()
7272
myGNSS.autoSendCfgValsetAtSpaceRemaining(16); // Trigger an auto-send when packetCfg has less than 16 bytes are remaining
7373

7474
//Begin with newCfgValset
75-
setValueSuccess &= myGNSS.newCfgValset(); // Defaults to configuring the setting in Flash, RAM and BBR
76-
//setValueSuccess &= myGNSS.newCfgValset(VAL_LAYER_RAM); //Set this and the following settings in RAM only instead of Flash/RAM/BBR
75+
setValueSuccess &= myGNSS.newCfgValset(); // Defaults to configuring the setting in RAM and BBR
76+
//setValueSuccess &= myGNSS.newCfgValset(VAL_LAYER_RAM); //Set this and the following settings in RAM only
7777

7878
// Add KeyIDs and Values
7979
setValueSuccess &= myGNSS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1); //Set output rate of msg 1005 over the I2C port to once per measurement (value is 8-bit (U1))
@@ -92,6 +92,33 @@ void setup()
9292
}
9393
else
9494
Serial.println("Value set failed");
95+
96+
delay(1000);
97+
98+
// New in v3 : we can use the template method addCfgValset to deduce the data size automatically
99+
100+
//Begin with newCfgValset
101+
setValueSuccess = myGNSS.newCfgValset(); // Defaults to configuring the setting in RAM and BBR
102+
//setValueSuccess &= myGNSS.newCfgValset(VAL_LAYER_RAM); //Set this and the following settings in RAM only
103+
104+
// Add KeyIDs and Values
105+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1); //Set output rate of msg 1005 over the I2C port to once per measurement (value is 8-bit (U1))
106+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1077_I2C, 1); //Set output rate of msg 1077 over the I2C port to once per measurement (value is 8-bit (U1))
107+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1087_I2C, 1); //Set output rate of msg 1087 over the I2C port to once per measurement (value is 8-bit (U1))
108+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1127_I2C, 1); //Set output rate of msg 1127 over the I2C port to once per measurement (value is 8-bit (U1))
109+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1097_I2C, 1); //Set output rate of msg 1097 over the I2C port to once per measurement (value is 8-bit (U1))
110+
setValueSuccess &= myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 10); //Set output rate of msg 1230 over the I2C port to once every 10 measurements (value is 8-bit (U1))
111+
112+
// Send the packet using sendCfgValset
113+
setValueSuccess &= myGNSS.sendCfgValset();
114+
115+
if (setValueSuccess == true)
116+
{
117+
Serial.println("Values were successfully set");
118+
}
119+
else
120+
Serial.println("Value set failed");
121+
95122
}
96123

97124
void loop()

examples/VALGET_and_VALSET/Example5_multiGetVal/Example5_multiGetVal.ino

+36-9
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void setup()
9191
// sfe_ublox_packet_validity_e valid : Goes from NOT_DEFINED to VALID or NOT_VALID when checksum is checked
9292
// sfe_ublox_packet_validity_e classAndIDmatch : Goes from NOT_DEFINED to VALID or NOT_VALID when the Class and ID match the requestedClass and requestedID
9393

94-
myGNSS.newCfgValget(&customCfg, VAL_LAYER_RAM); // Create a new VALGET construct
95-
myGNSS.addCfgValget8(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
96-
myGNSS.addCfgValget8(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA); // Get the flag indicating is NMEA should be output on I2C
94+
myGNSS.newCfgValget(&customCfg, MAX_PAYLOAD_SIZE, VAL_LAYER_RAM); // Create a new VALGET construct
95+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
96+
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA); // Get the flag indicating is NMEA should be output on I2C
9797
if (myGNSS.sendCfgValget(&customCfg)) // Send the VALGET
9898
{
9999
Serial.print(F("2 : I2C Address: 0x"));
@@ -111,18 +111,45 @@ void setup()
111111

112112
// We can also use the "extract" helper functions to read the data - useful for 16, 32 and 64-bit values
113113
// The full list is:
114-
// uint64_t extractLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
115-
// uint32_t extractLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into long
116-
// int32_t extractSignedLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into signed long (avoiding any ambiguity caused by casting)
117-
// uint16_t extractInt(ubxPacket *msg, uint16_t spotToStart); // Combine two bytes from payload into int
114+
// uint64_t extractLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
115+
// uint64_t extractSignedLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into int64_t
116+
// uint32_t extractLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into long
117+
// int32_t extractSignedLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into signed long (avoiding any ambiguity caused by casting)
118+
// uint16_t extractInt(ubxPacket *msg, uint16_t spotToStart); // Combine two bytes from payload into int
118119
// int16_t extractSignedInt(ubxPacket *msg, uint16_t spotToStart);
119-
// uint8_t extractByte(ubxPacket *msg, uint16_t spotToStart); // Get byte from payload
120-
// int8_t extractSignedChar(ubxPacket *msg, uint16_t spotToStart); // Get signed 8-bit value from payload
120+
// uint8_t extractByte(ubxPacket *msg, uint16_t spotToStart); // Get byte from payload
121+
// int8_t extractSignedChar(ubxPacket *msg, uint16_t spotToStart); // Get signed 8-bit value from payload
122+
// float extractFloat(ubxPacket *msg, uint16_t spotToStart); // Get 32-bit float from payload
123+
// double extractDouble(ubxPacket *msg, uint16_t spotToStart); // Get 64-bit double from payload
121124

122125
Serial.print(F("3 : I2C Address: 0x"));
123126
Serial.println(myGNSS.extractByte(&customCfg, 8) >> 1, HEX); //We have to shift by 1 to get the common '7-bit' I2C address format
124127
Serial.print(F("3 : Output NMEA over I2C port: 0x"));
125128
Serial.println(myGNSS.extractByte(&customCfg, 13), HEX);
129+
130+
// New in v3: we can use a template method to extract the value for us
131+
132+
uint8_t i2cAddress; // We still need to know the type...
133+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_I2C_ADDRESS, &i2cAddress, sizeof(i2cAddress))) // Get the I2C address - using the key
134+
{
135+
Serial.print(F("4 : I2C Address: 0x"));
136+
Serial.println(i2cAddress >> 1, HEX); //We have to shift by 1 to get the common '7-bit' I2C address format
137+
}
138+
else
139+
{
140+
Serial.println(F("extractConfigValueByKey failed!"));
141+
}
142+
143+
bool nmeaI2c; // We still need to know the type...
144+
if (myGNSS.extractConfigValueByKey(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA, &nmeaI2c, sizeof(nmeaI2c))) // Get the I2COUTPROT_NMEA flag - using the key
145+
{
146+
Serial.print(F("4 : Output NMEA over I2C port: 0x"));
147+
Serial.println(nmeaI2c, HEX);
148+
}
149+
else
150+
{
151+
Serial.println(F("extractConfigValueByKey failed!"));
152+
}
126153
}
127154
else
128155
{

examples/VALGET_and_VALSET/Example6_multiSetVal_and_GetVal_Templates/Example6_multiSetVal_and_GetVal_Templates.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void setup()
4242

4343
Wire.begin();
4444

45-
myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
45+
//myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
4646

4747
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
4848
{
@@ -70,7 +70,7 @@ void setup()
7070
// The next line creates and initialises the packet information which wraps around the payload
7171
ubxPacket customCfg = {0, 0, 0, 0, 0, customPayload, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};
7272

73-
myGNSS.newCfgValget(&customCfg, VAL_LAYER_RAM); // Create a new VALGET construct
73+
myGNSS.newCfgValget(&customCfg, MAX_PAYLOAD_SIZE, VAL_LAYER_RAM); // Create a new VALGET construct
7474
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2C_ADDRESS); // Get the I2C address (see u-blox_config_keys.h for details)
7575
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_I2COUTPROT_NMEA); // Get the flag indicating is NMEA should be output on I2C
7676
myGNSS.addCfgValget(&customCfg, UBLOX_CFG_UART1_BAUDRATE); // Get the UART1 baud rate

0 commit comments

Comments
 (0)