|
| 1 | +/* |
| 2 | + Configuring the NEO-F9P GNSS to send RXM RAWX reports over I2C and display them using a callback |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: November 24th, 2023 |
| 6 | + License: MIT. See license file for more information. |
| 7 | +
|
| 8 | + This example shows how to configure the u-blox NEO-F9P GNSS to send RXM RAWX reports automatically |
| 9 | + and access the data via a callback. It also demonstrates how to mark the L5 signals as healthy. |
| 10 | +
|
| 11 | + Feel like supporting open source hardware? |
| 12 | + Buy a board from SparkFun! |
| 13 | + NEO-F9P: https://www.sparkfun.com/products/23288 |
| 14 | +
|
| 15 | + Hardware Connections: |
| 16 | + Plug a Qwiic cable into the GPS and a BlackBoard |
| 17 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 18 | + Open the serial monitor at 115200 baud to see the output |
| 19 | +*/ |
| 20 | + |
| 21 | +#include <Wire.h> //Needed for I2C to GPS |
| 22 | + |
| 23 | +#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3 |
| 24 | +SFE_UBLOX_GNSS myGNSS; |
| 25 | + |
| 26 | +// Callback: newRAWX will be called when new RXM RAWX data arrives |
| 27 | +// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t |
| 28 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMRAWXcallback |
| 29 | +// / _____ This _must_ be UBX_RXM_RAWX_data_t |
| 30 | +// | / _____ You can use any name you like for the struct |
| 31 | +// | | / |
| 32 | +// | | | |
| 33 | +void newRAWX(UBX_RXM_RAWX_data_t *ubxDataStruct) |
| 34 | +{ |
| 35 | + Serial.println(); |
| 36 | + |
| 37 | + Serial.print(F("New RAWX data received. It contains ")); |
| 38 | + Serial.print(ubxDataStruct->header.numMeas); // Print numMeas (Number of measurements / blocks) |
| 39 | + Serial.println(F(" data blocks:")); |
| 40 | + |
| 41 | + for (uint8_t block = 0; block < ubxDataStruct->header.numMeas; block++) // For each block |
| 42 | + { |
| 43 | + char SV[14 + 4 + 4 + 256 + 1]; // Allocate space for sigId plus svId plus cno plus bars plus NULL |
| 44 | + switch (ubxDataStruct->blocks[block].gnssId) |
| 45 | + { |
| 46 | + case 0: |
| 47 | + { |
| 48 | + switch (ubxDataStruct->blocks[block].sigId) |
| 49 | + { |
| 50 | + case 0: |
| 51 | + sprintf(SV, "GPS L1 C/A "); |
| 52 | + break; |
| 53 | + case 3: |
| 54 | + sprintf(SV, "GPS L2 CL "); |
| 55 | + break; |
| 56 | + case 4: |
| 57 | + sprintf(SV, "GPS L2 CM "); |
| 58 | + break; |
| 59 | + case 6: |
| 60 | + sprintf(SV, "GPS L5 I "); |
| 61 | + break; |
| 62 | + case 7: |
| 63 | + sprintf(SV, "GPS L5 Q "); |
| 64 | + break; |
| 65 | + default: |
| 66 | + sprintf(SV, "GPS Unknown "); |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + break; |
| 71 | + case 1: |
| 72 | + { |
| 73 | + switch (ubxDataStruct->blocks[block].sigId) |
| 74 | + { |
| 75 | + case 0: |
| 76 | + sprintf(SV, "SBAS L1 C/A "); |
| 77 | + break; |
| 78 | + default: |
| 79 | + sprintf(SV, "SBAS Unknown "); |
| 80 | + break; |
| 81 | + } |
| 82 | + } |
| 83 | + break; |
| 84 | + case 2: |
| 85 | + { |
| 86 | + switch (ubxDataStruct->blocks[block].sigId) |
| 87 | + { |
| 88 | + case 0: |
| 89 | + sprintf(SV, "Galileo E1 C "); |
| 90 | + break; |
| 91 | + case 1: |
| 92 | + sprintf(SV, "Galileo E1 B "); |
| 93 | + break; |
| 94 | + case 3: |
| 95 | + sprintf(SV, "Galileo E5 aI "); |
| 96 | + break; |
| 97 | + case 4: |
| 98 | + sprintf(SV, "Galileo E5 aQ "); |
| 99 | + break; |
| 100 | + case 5: |
| 101 | + sprintf(SV, "Galileo E5 bI "); |
| 102 | + break; |
| 103 | + case 6: |
| 104 | + sprintf(SV, "Galileo E5 bQ "); |
| 105 | + break; |
| 106 | + default: |
| 107 | + sprintf(SV, "GAL Unknown "); |
| 108 | + break; |
| 109 | + } |
| 110 | + } |
| 111 | + break; |
| 112 | + case 3: |
| 113 | + { |
| 114 | + switch (ubxDataStruct->blocks[block].sigId) |
| 115 | + { |
| 116 | + case 0: |
| 117 | + sprintf(SV, "BeiDou B1I D1 "); |
| 118 | + break; |
| 119 | + case 1: |
| 120 | + sprintf(SV, "BeiDou B1I D2 "); |
| 121 | + break; |
| 122 | + case 2: |
| 123 | + sprintf(SV, "BeiDou B2I D1 "); |
| 124 | + break; |
| 125 | + case 3: |
| 126 | + sprintf(SV, "BeiDou B2I D2 "); |
| 127 | + break; |
| 128 | + case 5: |
| 129 | + sprintf(SV, "BeiDou B1 Cp "); |
| 130 | + break; |
| 131 | + case 6: |
| 132 | + sprintf(SV, "BeiDou B2 Cd "); |
| 133 | + break; |
| 134 | + case 7: |
| 135 | + sprintf(SV, "BeiDou B2 ap "); |
| 136 | + break; |
| 137 | + case 8: |
| 138 | + sprintf(SV, "BeiDou B2 ad "); |
| 139 | + break; |
| 140 | + default: |
| 141 | + sprintf(SV, "BDS Unknown "); |
| 142 | + break; |
| 143 | + } |
| 144 | + } |
| 145 | + break; |
| 146 | + case 5: |
| 147 | + { |
| 148 | + switch (ubxDataStruct->blocks[block].sigId) |
| 149 | + { |
| 150 | + case 0: |
| 151 | + sprintf(SV, "QZSS L1 C/A "); |
| 152 | + break; |
| 153 | + case 1: |
| 154 | + sprintf(SV, "QZSS L1S "); |
| 155 | + break; |
| 156 | + case 4: |
| 157 | + sprintf(SV, "QZSS L2 CM "); |
| 158 | + break; |
| 159 | + case 5: |
| 160 | + sprintf(SV, "QZSS L2 CL "); |
| 161 | + break; |
| 162 | + case 8: |
| 163 | + sprintf(SV, "QZSS L5 I "); |
| 164 | + break; |
| 165 | + case 9: |
| 166 | + sprintf(SV, "QZSS L5 Q "); |
| 167 | + break; |
| 168 | + default: |
| 169 | + sprintf(SV, "QZSS Unknown "); |
| 170 | + break; |
| 171 | + } |
| 172 | + } |
| 173 | + break; |
| 174 | + case 6: |
| 175 | + { |
| 176 | + switch (ubxDataStruct->blocks[block].sigId) |
| 177 | + { |
| 178 | + case 0: |
| 179 | + sprintf(SV, "GLONASS L1 OF "); |
| 180 | + break; |
| 181 | + case 2: |
| 182 | + sprintf(SV, "GLONASS L2 OF "); |
| 183 | + break; |
| 184 | + default: |
| 185 | + sprintf(SV, "GLO Unknown "); |
| 186 | + break; |
| 187 | + } |
| 188 | + } |
| 189 | + break; |
| 190 | + case 7: |
| 191 | + { |
| 192 | + switch (ubxDataStruct->blocks[block].sigId) |
| 193 | + { |
| 194 | + case 0: |
| 195 | + sprintf(SV, "NavIC L5 A "); |
| 196 | + break; |
| 197 | + default: |
| 198 | + sprintf(SV, "NavIC Unknown "); |
| 199 | + break; |
| 200 | + } |
| 201 | + } |
| 202 | + break; |
| 203 | + default: |
| 204 | + sprintf(SV, "Unknown "); |
| 205 | + break; |
| 206 | + } |
| 207 | + |
| 208 | + if (ubxDataStruct->blocks[block].svId < 10) sprintf(&SV[14], "%d ", ubxDataStruct->blocks[block].svId); // Align the svId |
| 209 | + else if (ubxDataStruct->blocks[block].svId < 100) sprintf(&SV[14], "%d ", ubxDataStruct->blocks[block].svId); // Align the svId |
| 210 | + else sprintf(&SV[14], "%d ", ubxDataStruct->blocks[block].svId); // Align the svId |
| 211 | + |
| 212 | + if (ubxDataStruct->blocks[block].cno < 10) sprintf(&SV[18], " %d ", ubxDataStruct->blocks[block].cno); // Align the cno |
| 213 | + else if (ubxDataStruct->blocks[block].cno < 100) sprintf(&SV[18], " %d ", ubxDataStruct->blocks[block].cno); // Align the cno |
| 214 | + else sprintf(&SV[18], "%d ", ubxDataStruct->blocks[block].cno); // Align the cno |
| 215 | + |
| 216 | + // Print cno as a bar chart |
| 217 | + uint8_t cno; |
| 218 | + for (cno = 0; cno <= ubxDataStruct->blocks[block].cno; cno++) |
| 219 | + SV[22 + cno] = '='; |
| 220 | + SV[22 + cno] = 0; // NULL |
| 221 | + |
| 222 | + Serial.println(SV); |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +void setup() |
| 227 | +{ |
| 228 | + delay(1000); |
| 229 | + |
| 230 | + Serial.begin(115200); |
| 231 | + while (!Serial); //Wait for user to open terminal |
| 232 | + Serial.println("SparkFun u-blox Example"); |
| 233 | + |
| 234 | + Wire.begin(); |
| 235 | + |
| 236 | + //myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 237 | + |
| 238 | + if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port |
| 239 | + { |
| 240 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing.")); |
| 241 | + while (1); |
| 242 | + } |
| 243 | + |
| 244 | + myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 245 | + myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR |
| 246 | + |
| 247 | + myGNSS.setMeasurementRate(5000); //Produce one solution every five seconds (RAWX produces a _lot_ of data!) |
| 248 | + |
| 249 | + myGNSS.setVal8(UBLOX_CFG_SIGNAL_GPS_L5_ENA, 1); // Make sure the GPS L5 band is enabled (needed on the NEO-F9P) |
| 250 | + |
| 251 | + myGNSS.setGPSL5HealthOverride(true); // Mark L5 signals as healthy - store in RAM and BBR |
| 252 | + |
| 253 | + myGNSS.softwareResetGNSSOnly(); // Restart the GNSS to apply the L5 health override |
| 254 | + |
| 255 | + myGNSS.setAutoRXMRAWXcallbackPtr(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX |
| 256 | +} |
| 257 | + |
| 258 | +void loop() |
| 259 | +{ |
| 260 | + myGNSS.checkUblox(); // Check for the arrival of new data and process it. |
| 261 | + myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed. |
| 262 | + |
| 263 | + Serial.print("."); |
| 264 | + delay(200); |
| 265 | +} |
0 commit comments