|
| 1 | +/* |
| 2 | + Configuring the GNSS to automatically send NAV SVIN reports over I2C and display them using a callback |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: April 4th, 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 the u-blox GNSS to send NAV SVIN reports automatically |
| 10 | + and access the data via a callback. No more polling! |
| 11 | +
|
| 12 | + Feel like supporting open source hardware? |
| 13 | + Buy a board from SparkFun! |
| 14 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 |
| 15 | +
|
| 16 | + Hardware Connections: |
| 17 | + Plug a Qwiic cable into the GPS and a BlackBoard |
| 18 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 19 | + Open the serial monitor at 115200 baud to see the output |
| 20 | +*/ |
| 21 | + |
| 22 | +#include <Wire.h> //Needed for I2C to GNSS |
| 23 | + |
| 24 | +#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS |
| 25 | +SFE_UBLOX_GNSS myGNSS; |
| 26 | + |
| 27 | +// Callback: newNAVSVIN will be called when new NAV SVIN data arrives |
| 28 | +// See u-blox_structs.h for the full definition of UBX_NAV_SVIN_data_t |
| 29 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVSVINcallbackPtr |
| 30 | +// / _____ This _must_ be UBX_NAV_SVIN_data_t |
| 31 | +// | / _____ You can use any name you like for the struct |
| 32 | +// | | / |
| 33 | +// | | | |
| 34 | +void newNAVSVIN(UBX_NAV_SVIN_data_t *ubxDataStruct) |
| 35 | +{ |
| 36 | + Serial.println(); |
| 37 | + |
| 38 | + Serial.print(F("Survey-in is ")); |
| 39 | + if (ubxDataStruct->active == 0) |
| 40 | + Serial.print(F("not ")); |
| 41 | + Serial.println(F("in progress")); |
| 42 | + |
| 43 | + Serial.print(F("Survey-in position is ")); |
| 44 | + if (ubxDataStruct->valid == 0) |
| 45 | + Serial.print(F("not ")); |
| 46 | + Serial.println(F("valid")); |
| 47 | + |
| 48 | + Serial.print(F("Survey-in observation time (s): ")); |
| 49 | + Serial.println(ubxDataStruct->dur); |
| 50 | + |
| 51 | + Serial.print(F("ECEF position (cm): ")); |
| 52 | + Serial.print(ubxDataStruct->meanX); |
| 53 | + Serial.print(F(" (")); |
| 54 | + if (ubxDataStruct->meanXHP >= 0) |
| 55 | + Serial.print(F("+")); |
| 56 | + Serial.print((float)ubxDataStruct->meanXHP * 0.01); // Convert 0.1mm to cm |
| 57 | + Serial.print(F("), ")); |
| 58 | + Serial.print(ubxDataStruct->meanY); |
| 59 | + Serial.print(F(" (")); |
| 60 | + if (ubxDataStruct->meanYHP >= 0) |
| 61 | + Serial.print(F("+")); |
| 62 | + Serial.print((float)ubxDataStruct->meanYHP * 0.01); // Convert 0.1mm to cm |
| 63 | + Serial.print(F("), ")); |
| 64 | + Serial.print(ubxDataStruct->meanZ); |
| 65 | + Serial.print(F(" (")); |
| 66 | + if (ubxDataStruct->meanZHP >= 0) |
| 67 | + Serial.print(F("+")); |
| 68 | + Serial.print((float)ubxDataStruct->meanZHP * 0.01); // Convert 0.1mm to cm |
| 69 | + Serial.println(F(")")); |
| 70 | + |
| 71 | + Serial.print(F("Mean position accuracy (cm): ")); |
| 72 | + Serial.println((float)ubxDataStruct->meanAcc * 0.01); // Convert 0.1mm to cm |
| 73 | +} |
| 74 | + |
| 75 | +void setup() |
| 76 | +{ |
| 77 | + Serial.begin(115200); |
| 78 | + while (!Serial); //Wait for user to open terminal |
| 79 | + Serial.println(F("u-blox Base Station example")); |
| 80 | + |
| 81 | + Wire.begin(); |
| 82 | + |
| 83 | + //myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial |
| 84 | + |
| 85 | + if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port |
| 86 | + { |
| 87 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing.")); |
| 88 | + while (1); |
| 89 | + } |
| 90 | + |
| 91 | + // Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate |
| 92 | + //myGNSS.factoryDefault(); delay(5000); |
| 93 | + |
| 94 | + myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 95 | + myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR |
| 96 | + |
| 97 | + // Set up the callback for NAV SVIN. This will enable SVIN messages at the navigation rate |
| 98 | + myGNSS.setAutoNAVSVINcallbackPtr(&newNAVSVIN); |
| 99 | + |
| 100 | + while (Serial.available()) Serial.read(); //Clear the serial buffer |
| 101 | + Serial.println(F("Press any key to begin Survey-In")); |
| 102 | +} |
| 103 | + |
| 104 | +void loop() |
| 105 | +{ |
| 106 | + myGNSS.checkUblox(); //See if new data is available. Process bytes as they come in. |
| 107 | + myGNSS.checkCallbacks(); //Process any waiting callbacks |
| 108 | + |
| 109 | + if (Serial.available()) // Check if user has pressed a key |
| 110 | + { |
| 111 | + bool success = myGNSS.enableSurveyMode(60, 5.000); //Enable Survey in, 60 seconds, 5.0m |
| 112 | + //bool success = myGNSS.enableSurveyModeFull(86400, 2.000); //Enable Survey in, 24 hours, 2.0m |
| 113 | + |
| 114 | + Serial.println(); |
| 115 | + |
| 116 | + if (success) |
| 117 | + { |
| 118 | + Serial.println(F("Survey-In started!")); |
| 119 | + } |
| 120 | + else |
| 121 | + { |
| 122 | + Serial.println(F("Survey start failed!")); |
| 123 | + } |
| 124 | + |
| 125 | + while (Serial.available()) Serial.read(); //Clear the serial buffer |
| 126 | + } |
| 127 | +} |
0 commit comments