|
| 1 | +/* |
| 2 | + Use the NEO-D9C QZSS-L6 receiver to provide corrections to a ZED-F9x via UART |
| 3 | + By: SparkFun Electronics / Paul Clark |
| 4 | + Based on original code by: u-blox AG / Michael Ammann |
| 5 | + 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. |
| 8 | +
|
| 9 | + 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). |
| 10 | +
|
| 11 | + We believe the NEO-D9C's I2C address should be 0x43 (like the NEO-D9S). But, reported by users in Japan, |
| 12 | + the initial NEO-D9C's use address 0x42 - which is the same as the ZED-F9P.... |
| 13 | +
|
| 14 | + As a work-around, this example expects the ZED-F9P to be connected via UART1 Serial (Teensy Serial1) to avoid a collision |
| 15 | + on the I2C bus. |
| 16 | +
|
| 17 | + (Yes, OK, it is straight-forward to change the NEO-D9C's I2C address. But, with this example, you do not need to do that.) |
| 18 | +
|
| 19 | + Also, again reported by users in Japan, the initial NEO-D9C's do not support UBX-CFG-PRT. |
| 20 | + The library uses UBX-CFG-PRT inside .begin (.isConnected) to check if the module is connected. |
| 21 | + This then fails with the initial NEO-D9C's. |
| 22 | + The work-around is to set the .begin assumeSuccess parameter to true. |
| 23 | + With newer NEO-D9C's this work-around may not be necessary. See line 272. |
| 24 | + |
| 25 | + Connections: e.g. for Teensy 4.0, Geosense D9CX1 NEO-D9C and SparkFun ZED-F9P: |
| 26 | +
|
| 27 | + Teensy 5V (Vin) -> ZED-F9P 5V -> D9CX1 V5V (JP1 Pin 2) |
| 28 | + Teensy GND -> ZED-F9P GND -> D9CX1 GND (JP1 Pin 1) |
| 29 | + Teensy SDA1 (17) -> D9CX1 SDA (JP1 Pin 5) |
| 30 | + Teensy SCL1 (16) -> D9CX1 SCL (JP1 Pin 6) |
| 31 | + Teensy Serial1 TX1 (1) -> ZED-F9P UART1 RX1 |
| 32 | + Teensy Serial1 RX1 (0) -> ZED-F9P UART1 TX1 |
| 33 | + D9CX1 UART1 TX1 (JP1 Pin 3) -> ZED-F9P UART2 RX2 |
| 34 | + D9CX1 UART1 RX1 (JP1 Pin 4) -> ZED-F9P UART2 TX2 |
| 35 | +
|
| 36 | + The Teensy communicates with the NEO-D9C (D9CX1) via I2C on address 0x42 |
| 37 | + The Teensy communicates with the ZED-F9P via UART (Serial1 on Teensy, UART1 on ZED) to avoid the I2C address collision |
| 38 | + The NEO-D9C corrections (UBX-RXM-QZSSL6) are sent from NEO UART1 to ZED UART2 |
| 39 | +
|
| 40 | + Feel like supporting open source hardware? |
| 41 | + Buy a board from SparkFun! |
| 42 | + ZED-F9P RTK2: https://www.sparkfun.com/products/16481 |
| 43 | + NEO-D9S L-Band Correction Data Receiver: https://www.sparkfun.com/products/19390 |
| 44 | +
|
| 45 | + Hardware Connections: |
| 46 | + Use Qwiic cables to connect the NEO-D9S and ZED-F9x GNSS to your board |
| 47 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 48 | + Open the serial monitor at 115200 baud to see the output |
| 49 | +*/ |
| 50 | + |
| 51 | +#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS |
| 52 | +SFE_UBLOX_GNSS myGNSS; // ZED-F9x |
| 53 | +SFE_UBLOX_GNSS myQZSS; // NEO-D9C |
| 54 | + |
| 55 | +#define OK(ok) (ok ? F(" -> OK") : F(" -> ERROR!")) // Convert uint8_t into OK/ERROR |
| 56 | + |
| 57 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 58 | + |
| 59 | +// Callback: printRXMQZSSL6 will be called when new QZSS-L6 data arrives |
| 60 | +// See u-blox_structs.h for the full definition of UBX_RXM_QZSSL6_message_data_t |
| 61 | +// _____ You can use any name you like for the callback. Use the same name when you call setRXMQZSSL6messageCallbackPtr |
| 62 | +// / _____ This _must_ be UBX_RXM_QZSSL6_message_data_t |
| 63 | +// | / _____ You can use any name you like for the struct |
| 64 | +// | | / |
| 65 | +// | | | |
| 66 | +void printRXMQZSSL6(UBX_RXM_QZSSL6_message_data_t *qzssL6Data) |
| 67 | +{ |
| 68 | + Serial.println(F("New QZSS-L6 data received:")); |
| 69 | + |
| 70 | + Serial.print(F("Message version: ")); |
| 71 | + Serial.println(qzssL6Data->payload[0]); |
| 72 | + |
| 73 | + Serial.print(F("Satellite Identifier: ")); |
| 74 | + Serial.println(qzssL6Data->payload[1]); |
| 75 | + |
| 76 | + Serial.print(F("Carrier / Noise: ")); |
| 77 | + double cno = (0.00390625 * ((double)qzssL6Data->payload[2])) + ((double)qzssL6Data->payload[3]); |
| 78 | + Serial.println(cno, 1); |
| 79 | + |
| 80 | + Serial.print(F("Bit Errors Corrected: ")); |
| 81 | + Serial.println(qzssL6Data->payload[9]); |
| 82 | + |
| 83 | + uint16_t chInfo = (((uint16_t)qzssL6Data->payload[11]) << 8) | qzssL6Data->payload[10]; |
| 84 | + uint16_t errStatus = ((chInfo >> 12) & 0x3); |
| 85 | + Serial.print(F("Receiver Channel: ")); |
| 86 | + Serial.println((chInfo >> 8) & 0x3); |
| 87 | + Serial.print(F("Message Name: L6")); |
| 88 | + Serial.println(((chInfo >> 10) & 0x1) == 0 ? F("D") : F("E")); |
| 89 | + Serial.print(F("Error Status: ")); |
| 90 | + if (errStatus == 1) |
| 91 | + Serial.println("error-free"); |
| 92 | + else if (errStatus == 2) |
| 93 | + Serial.println("erroneous"); |
| 94 | + else |
| 95 | + Serial.println("unknown"); |
| 96 | + Serial.print(F("Channel Name: ")); |
| 97 | + Serial.println(((chInfo >> 14) & 0x3) == 0 ? F("A") : F("B")); |
| 98 | + |
| 99 | + Serial.println(); |
| 100 | +} |
| 101 | + |
| 102 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 103 | + |
| 104 | +// Callback: printPVTdata will be called when new NAV PVT data arrives |
| 105 | +// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t |
| 106 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoPVTcallbackPtr |
| 107 | +// / _____ This _must_ be UBX_NAV_PVT_data_t |
| 108 | +// | / _____ You can use any name you like for the struct |
| 109 | +// | | / |
| 110 | +// | | | |
| 111 | +void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) |
| 112 | +{ |
| 113 | + double latitude = ubxDataStruct->lat; // Print the latitude |
| 114 | + Serial.print(F("Lat: ")); |
| 115 | + Serial.print(latitude / 10000000.0, 7); |
| 116 | + |
| 117 | + double longitude = ubxDataStruct->lon; // Print the longitude |
| 118 | + Serial.print(F(" Long: ")); |
| 119 | + Serial.print(longitude / 10000000.0, 7); |
| 120 | + |
| 121 | + double altitude = ubxDataStruct->hMSL; // Print the height above mean sea level |
| 122 | + Serial.print(F(" Height: ")); |
| 123 | + Serial.print(altitude / 1000.0, 3); |
| 124 | + |
| 125 | + uint8_t fixType = ubxDataStruct->fixType; // Print the fix type |
| 126 | + Serial.print(F(" Fix: ")); |
| 127 | + Serial.print(fixType); |
| 128 | + if (fixType == 0) |
| 129 | + Serial.print(F(" (None)")); |
| 130 | + else if (fixType == 1) |
| 131 | + Serial.print(F(" (Dead Reckoning)")); |
| 132 | + else if (fixType == 2) |
| 133 | + Serial.print(F(" (2D)")); |
| 134 | + else if (fixType == 3) |
| 135 | + Serial.print(F(" (3D)")); |
| 136 | + else if (fixType == 3) |
| 137 | + Serial.print(F(" (GNSS + Dead Reckoning)")); |
| 138 | + else if (fixType == 5) |
| 139 | + Serial.print(F(" (Time Only)")); |
| 140 | + else |
| 141 | + Serial.print(F(" (UNKNOWN)")); |
| 142 | + |
| 143 | + uint8_t carrSoln = ubxDataStruct->flags.bits.carrSoln; // Print the carrier solution |
| 144 | + Serial.print(F(" Carrier Solution: ")); |
| 145 | + Serial.print(carrSoln); |
| 146 | + if (carrSoln == 0) |
| 147 | + Serial.print(F(" (None)")); |
| 148 | + else if (carrSoln == 1) |
| 149 | + Serial.print(F(" (Floating)")); |
| 150 | + else if (carrSoln == 2) |
| 151 | + Serial.print(F(" (Fixed)")); |
| 152 | + else |
| 153 | + Serial.print(F(" (UNKNOWN)")); |
| 154 | + |
| 155 | + uint32_t hAcc = ubxDataStruct->hAcc; // Print the horizontal accuracy estimate |
| 156 | + Serial.print(F(" Horizontal Accuracy Estimate: ")); |
| 157 | + Serial.print(hAcc); |
| 158 | + Serial.print(F(" (mm)")); |
| 159 | + |
| 160 | + Serial.println(); |
| 161 | +} |
| 162 | + |
| 163 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 164 | + |
| 165 | +// Callback: printRXMCOR will be called when new RXM COR data arrives |
| 166 | +// See u-blox_structs.h for the full definition of UBX_RXM_COR_data_t |
| 167 | +// _____ You can use any name you like for the callback. Use the same name when you call setRXMCORcallbackPtr |
| 168 | +// / _____ This _must_ be UBX_RXM_COR_data_t |
| 169 | +// | / _____ You can use any name you like for the struct |
| 170 | +// | | / |
| 171 | +// | | | |
| 172 | +void printRXMCOR(UBX_RXM_COR_data_t *ubxDataStruct) |
| 173 | +{ |
| 174 | + Serial.print(F("UBX-RXM-COR: ebno: ")); |
| 175 | + Serial.print(ubxDataStruct->ebno); |
| 176 | + |
| 177 | + Serial.print(F(" protocol: ")); |
| 178 | + if (ubxDataStruct->statusInfo.bits.protocol == 1) |
| 179 | + Serial.print(F("RTCM3")); |
| 180 | + else if (ubxDataStruct->statusInfo.bits.protocol == 2) |
| 181 | + Serial.print(F("SPARTN")); |
| 182 | + else if (ubxDataStruct->statusInfo.bits.protocol == 29) |
| 183 | + Serial.print(F("PMP (SPARTN)")); |
| 184 | + else if (ubxDataStruct->statusInfo.bits.protocol == 30) |
| 185 | + Serial.print(F("QZSSL6")); |
| 186 | + else |
| 187 | + Serial.print(F("Unknown")); |
| 188 | + |
| 189 | + Serial.print(F(" errStatus: ")); |
| 190 | + if (ubxDataStruct->statusInfo.bits.errStatus == 1) |
| 191 | + Serial.print(F("Error-free")); |
| 192 | + else if (ubxDataStruct->statusInfo.bits.errStatus == 2) |
| 193 | + Serial.print(F("Erroneous")); |
| 194 | + else |
| 195 | + Serial.print(F("Unknown")); |
| 196 | + |
| 197 | + Serial.print(F(" msgUsed: ")); |
| 198 | + if (ubxDataStruct->statusInfo.bits.msgUsed == 1) |
| 199 | + Serial.print(F("Not used")); |
| 200 | + else if (ubxDataStruct->statusInfo.bits.msgUsed == 2) |
| 201 | + Serial.print(F("Used")); |
| 202 | + else |
| 203 | + Serial.print(F("Unknown")); |
| 204 | + |
| 205 | + Serial.print(F(" msgEncrypted: ")); |
| 206 | + if (ubxDataStruct->statusInfo.bits.msgEncrypted == 1) |
| 207 | + Serial.print(F("Not encrypted")); |
| 208 | + else if (ubxDataStruct->statusInfo.bits.msgEncrypted == 2) |
| 209 | + Serial.print(F("Encrypted")); |
| 210 | + else |
| 211 | + Serial.print(F("Unknown")); |
| 212 | + |
| 213 | + Serial.print(F(" msgDecrypted: ")); |
| 214 | + if (ubxDataStruct->statusInfo.bits.msgDecrypted == 1) |
| 215 | + Serial.print(F("Not decrypted")); |
| 216 | + else if (ubxDataStruct->statusInfo.bits.msgDecrypted == 2) |
| 217 | + Serial.print(F("Successfully decrypted")); |
| 218 | + else |
| 219 | + Serial.print(F("Unknown")); |
| 220 | + |
| 221 | + Serial.println(); |
| 222 | +} |
| 223 | + |
| 224 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 225 | + |
| 226 | +void setup() |
| 227 | +{ |
| 228 | + Serial.begin(115200); |
| 229 | + Serial.println(F("NEO-D9C Corrections")); |
| 230 | + |
| 231 | + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 232 | + // Begin and configure the ZED-F9x |
| 233 | + |
| 234 | + Serial1.begin(38400); // The ZED-F9P is connected via Serial1 to UART1 |
| 235 | + |
| 236 | + //myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 237 | + |
| 238 | + while (myGNSS.begin(Serial1) == false) //Connect to the u-blox module using Serial1 and UART1 |
| 239 | + { |
| 240 | + Serial.println(F("u-blox GNSS module not detected. Please check wiring.")); |
| 241 | + delay(2000); |
| 242 | + } |
| 243 | + Serial.println(F("u-blox GNSS module connected")); |
| 244 | + |
| 245 | + uint8_t ok = myGNSS.setUART1Output(COM_TYPE_UBX); //Turn off NMEA noise |
| 246 | + |
| 247 | + if (ok) ok = myGNSS.setPortInput(COM_PORT_UART2, COM_TYPE_UBX | COM_TYPE_RTCM3 | COM_TYPE_SPARTN); //Be sure SPARTN input is enabled on UART2 |
| 248 | + |
| 249 | + if (ok) ok = myGNSS.setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED); // Set the differential mode - ambiguities are fixed whenever possible |
| 250 | + |
| 251 | + if (ok) ok = myGNSS.setNavigationFrequency(1); //Set output in Hz. |
| 252 | + |
| 253 | + if (ok) ok = myGNSS.setVal8(UBLOX_CFG_MSGOUT_UBX_RXM_COR_UART1, 1); // Enable UBX-RXM-COR messages on UART2 |
| 254 | + |
| 255 | + //if (ok) ok = myGNSS.saveConfiguration(VAL_CFG_SUBSEC_IOPORT | VAL_CFG_SUBSEC_MSGCONF); //Optional: Save the ioPort and message settings to NVM |
| 256 | + |
| 257 | + Serial.print(F("GNSS: configuration ")); |
| 258 | + Serial.println(OK(ok)); |
| 259 | + |
| 260 | + myGNSS.setAutoPVTcallbackPtr(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata so we can watch the carrier solution go to fixed |
| 261 | + |
| 262 | + myGNSS.setRXMCORcallbackPtr(&printRXMCOR); // Print the contents of UBX-RXM-COR messages so we can check if the QZSS-L6 data is being decrypted successfully |
| 263 | + |
| 264 | + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 265 | + // Begin and configure the NEO-D9C QZSS-L6 receiver |
| 266 | + |
| 267 | + Wire.begin(); //Start I2C |
| 268 | + |
| 269 | + //myQZSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 270 | + |
| 271 | + // For the initial NEO-D9C's: connect using address 0x42; set the assumeSuccess parameter to true |
| 272 | + while (myQZSS.begin(Wire, 0x42, 1100, true) == false) |
| 273 | + // For newer NEO-D9C's: use address 0x43; leave assumeSuccess set to false (default) |
| 274 | + //while (myQZSS.begin(Wire, 0x43) == false) |
| 275 | + { |
| 276 | + Serial.println(F("u-blox NEO-D9C not detected at selected I2C address. Please check wiring and I2C address.")); |
| 277 | + delay(2000); |
| 278 | + } |
| 279 | + Serial.println(F("u-blox NEO-D9C connected")); |
| 280 | + |
| 281 | + ok = myQZSS.setVal(UBLOX_CFG_MSGOUT_UBX_RXM_QZSSL6_I2C, 1); // Output QZSS-L6 message on the I2C port |
| 282 | + |
| 283 | + Serial.print(F("QZSS-L6: I2C configuration ")); |
| 284 | + Serial.println(OK(ok)); |
| 285 | + |
| 286 | + if (ok) ok = myQZSS.setVal(UBLOX_CFG_UART1OUTPROT_UBX, 1); // Enable UBX output on UART1 |
| 287 | + if (ok) ok = myQZSS.setVal(UBLOX_CFG_MSGOUT_UBX_RXM_QZSSL6_UART1, 1); // Output QZSS-L6 message on UART1 |
| 288 | + if (ok) ok = myQZSS.setVal32(UBLOX_CFG_UART1_BAUDRATE, 38400); // Match UART1 baudrate with ZED |
| 289 | + |
| 290 | + Serial.print(F("QZSS-L6: UART1 configuration ")); |
| 291 | + Serial.println(OK(ok)); |
| 292 | + |
| 293 | + if (ok) ok = myQZSS.setVal(UBLOX_CFG_UART2OUTPROT_UBX, 1); // Enable UBX output on UART2 |
| 294 | + if (ok) ok = myQZSS.setVal(UBLOX_CFG_MSGOUT_UBX_RXM_QZSSL6_UART2, 1); // Output QZSS-L6 message on UART2 |
| 295 | + if (ok) ok = myQZSS.setVal32(UBLOX_CFG_UART2_BAUDRATE, 38400); // Match UART2 baudrate with ZED |
| 296 | + |
| 297 | + Serial.print(F("QZSS-L6: UART2 configuration ")); |
| 298 | + Serial.println(OK(ok)); |
| 299 | + |
| 300 | + myQZSS.setRXMQZSSL6messageCallbackPtr(&printRXMQZSSL6); // Call printRXMQZSSL6 when new QZSS-L6 data arrives |
| 301 | +} |
| 302 | + |
| 303 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 304 | + |
| 305 | +void loop() |
| 306 | +{ |
| 307 | + myGNSS.checkUblox(); // Check for the arrival of new GNSS data and process it. |
| 308 | + myGNSS.checkCallbacks(); // Check if any GNSS callbacks are waiting to be processed. |
| 309 | + |
| 310 | + myQZSS.checkUblox(); // Check for the arrival of new QZSS-L6 data and process it. |
| 311 | + myQZSS.checkCallbacks(); // Check if any LBand callbacks are waiting to be processed. |
| 312 | +} |
0 commit comments