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

Commit 5efc238

Browse files
committed
Add setVal function and example.
1 parent cccf8f8 commit 5efc238

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: January 9th, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
Ublox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the
10+
UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL
11+
commands instead. This example shows how to use this new command structure.
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+
Plug a Qwiic cable into the GPS and a RedBoard Qwiic or BlackBoard
21+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
22+
Open the serial monitor at 115200 baud to see the output
23+
*/
24+
25+
#include <Wire.h> //Needed for I2C to GPS
26+
27+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
28+
SFE_UBLOX_GPS myGPS;
29+
30+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
31+
32+
void setup()
33+
{
34+
Serial.begin(115200);
35+
while (!Serial); //Wait for user to open terminal
36+
Serial.println("Ublox getVal example");
37+
38+
Wire.begin();
39+
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
40+
41+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
42+
{
43+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
44+
while (1);
45+
}
46+
47+
myGPS.enableDebugging(); //Enable debug messages over Serial (default)
48+
//myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB
49+
50+
uint8_t currentI2Caddress = myGPS.getVal8(0x20510001);
51+
Serial.print("Current I2C address (should be 0x42): 0x");
52+
Serial.println(currentI2Caddress >> 1, HEX); //Ublox module returns a shifted 8-bit address. Make it 7-bit unshifted.
53+
54+
while(1);
55+
56+
}
57+
58+
void loop()
59+
{
60+
//Query module only every second. Doing it more often will just cause I2C traffic.
61+
//The module only responds when a new position is available
62+
if (millis() - lastTime > 1000)
63+
{
64+
lastTime = millis(); //Update the timer
65+
66+
long latitude = myGPS.getLatitude();
67+
Serial.print(F("Lat: "));
68+
Serial.print(latitude);
69+
70+
long longitude = myGPS.getLongitude();
71+
Serial.print(F(" Long: "));
72+
Serial.print(longitude);
73+
Serial.print(F(" (degrees * 10^-7)"));
74+
75+
long altitude = myGPS.getAltitude();
76+
Serial.print(F(" Alt: "));
77+
Serial.print(altitude);
78+
Serial.print(F(" (mm)"));
79+
80+
byte SIV = myGPS.getSIV();
81+
Serial.print(F(" SIV: "));
82+
Serial.print(SIV);
83+
84+
Serial.println();
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: January 9th, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
Ublox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the
10+
UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL
11+
commands instead. This example shows how to use this new command structure.
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+
Plug a Qwiic cable into the GPS and a RedBoard Qwiic or BlackBoard
21+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
22+
Open the serial monitor at 115200 baud to see the output
23+
*/
24+
25+
#include <Wire.h> //Needed for I2C to GPS
26+
27+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
28+
SFE_UBLOX_GPS myGPS;
29+
30+
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
31+
32+
void setup()
33+
{
34+
Serial.begin(115200);
35+
while (!Serial); //Wait for user to open terminal
36+
Serial.println("Ublox getVal example");
37+
38+
Wire.begin();
39+
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
40+
41+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
42+
{
43+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
44+
while (1);
45+
}
46+
47+
myGPS.enableDebugging(); //Enable debug messages over Serial (default)
48+
//myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB
49+
50+
bool setValueSuccess;
51+
52+
//These key values are hard coded. You can obtain them from the ZED-F9P interface description doc
53+
//or from u-center's Messages->CFG->VALSET window. Keys must be 32-bit.
54+
//setValueSuccess = myGPS.setVal(0x10930006, 0); //Enable high precision NMEA
55+
setValueSuccess = myGPS.setVal(0x30210001, 100); //Set measurement rate to 100ms (10Hz update rate)
56+
//setValueSuccess = myGPS.setVal(0x30210001, 1000); //Set measurement rate to 1000ms (1Hz update rate)
57+
58+
//Below is the original way we enabled the RTCM message on the I2C port. After that, we show how to do the same
59+
//but with setVal().
60+
//myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second
61+
//setValueSuccess = myGPS.setVal(0x209102bd, 1); //Set output rate of msg 1005 over the I2C port to once per second
62+
63+
if(setValueSuccess == true)
64+
{
65+
Serial.println("Value was successfully set");
66+
}
67+
else
68+
Serial.println("Value set failed");
69+
70+
}
71+
72+
void loop()
73+
{
74+
75+
}

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ setUSBOutput KEYWORD2
6262
setSPIOutput KEYWORD2
6363

6464
getVal8 KEYWORD2
65+
setVal KEYWORD2
6566

6667
getSurveyMode KEYWORD2
6768
setSurveyMode KEYWORD2

src/SparkFun_Ublox_Arduino_Library.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,42 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
876876
return (extractByte(8));
877877
}
878878

879+
//Given a key, set an 8-bit value
880+
//This function takes a full 32-bit key
881+
//Default layer is BBR
882+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
883+
uint8_t SFE_UBLOX_GPS::setVal(uint32_t key, uint16_t value, uint8_t layer, uint16_t maxWait)
884+
{
885+
packetCfg.cls = UBX_CLASS_CFG;
886+
packetCfg.id = UBX_CFG_VALSET;
887+
packetCfg.len = 4 + 4 + 2; //4 byte header, 4 byte key ID, 2 bytes of value
888+
packetCfg.startingSpot = 0;
889+
890+
//Clear packet payload
891+
for (uint8_t x = 0; x < packetCfg.len; x++)
892+
packetCfg.payload[x] = 0;
893+
894+
payloadCfg[0] = 0; //Message Version - set to 0
895+
payloadCfg[1] = layer; //By default we ask for the BBR layer
896+
897+
//Load key into outgoing payload
898+
payloadCfg[4] = key >> 8 * 0; //Key LSB
899+
payloadCfg[5] = key >> 8 * 1;
900+
payloadCfg[6] = key >> 8 * 2;
901+
payloadCfg[7] = key >> 8 * 3;
902+
903+
//Load user's value
904+
payloadCfg[8] = value >> 8 * 0; //Value LSB
905+
payloadCfg[9] = value >> 8 * 1;
906+
907+
//Send VALSET command with this key and value
908+
if (sendCommand(packetCfg, maxWait) == false)
909+
return (false); //If command send fails then bail
910+
911+
//All done
912+
return (true);
913+
}
914+
879915
//Get the current TimeMode3 settings - these contain survey in statuses
880916
boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
881917
{

src/SparkFun_Ublox_Arduino_Library.h

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class SFE_UBLOX_GPS
249249
//General configuration (used only on protocol v27 and higher - ie, ZED-F9P)
250250
uint8_t getVal8(uint16_t group, uint16_t id, uint8_t size, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
251251
uint8_t getVal8(uint32_t keyID, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
252+
uint8_t setVal(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
252253

253254
//Functions used for RTK and base station setup
254255
boolean getSurveyMode(uint16_t maxWait = 250); //Get the current TimeMode3 settings

0 commit comments

Comments
 (0)