|
| 1 | +/* |
| 2 | + Configuring the GNSS to produce multiple messages at different rates |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: April 1st, 2021 |
| 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 output multiple messages at different rates: |
| 10 | + PVT is output every second; |
| 11 | + POSECEF is output every five seconds; |
| 12 | + VELNED is output every ten seconds. |
| 13 | +
|
| 14 | + Feel like supporting open source hardware? |
| 15 | + 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 |
| 19 | +
|
| 20 | + Hardware Connections: |
| 21 | + Plug a Qwiic cable into the GNSS and a BlackBoard |
| 22 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 23 | + Open the serial monitor at 115200 baud to see the output |
| 24 | +*/ |
| 25 | + |
| 26 | +#include <Wire.h> //Needed for I2C to GNSS |
| 27 | + |
| 28 | +#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS |
| 29 | +SFE_UBLOX_GNSS myGNSS; |
| 30 | + |
| 31 | +void setup() |
| 32 | +{ |
| 33 | + Serial.begin(115200); |
| 34 | + while (!Serial); //Wait for user to open terminal |
| 35 | + Serial.println("SparkFun u-blox Example"); |
| 36 | + |
| 37 | + Wire.begin(); |
| 38 | + |
| 39 | + if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port |
| 40 | + { |
| 41 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing.")); |
| 42 | + while (1); |
| 43 | + } |
| 44 | + |
| 45 | + myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 46 | + myGNSS.setMeasurementRate(1000); //Produce a measurement every 1000ms |
| 47 | + myGNSS.setNavigationRate(1); //Produce a navigation solution every measurement |
| 48 | + |
| 49 | + myGNSS.setAutoPVTrate(1); //Tell the GNSS to send the PVT solution every measurement |
| 50 | + myGNSS.setAutoNAVPOSECEFrate(5); //Tell the GNSS to send each POSECEF solution every 5th measurement |
| 51 | + myGNSS.setAutoNAVVELNEDrate(10); //Tell the GNSS to send each VELNED solution every 10th measurement |
| 52 | + //myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR |
| 53 | +} |
| 54 | + |
| 55 | +void loop() |
| 56 | +{ |
| 57 | + // Calling getPVT returns true if there actually is a fresh navigation solution available. |
| 58 | + if (myGNSS.getPVT()) |
| 59 | + { |
| 60 | + long latitude = myGNSS.getLatitude(); |
| 61 | + Serial.print(F("Lat: ")); |
| 62 | + Serial.print(latitude); |
| 63 | + |
| 64 | + long longitude = myGNSS.getLongitude(); |
| 65 | + Serial.print(F(" Long: ")); |
| 66 | + Serial.print(longitude); |
| 67 | + Serial.print(F(" (degrees * 10^-7)")); |
| 68 | + |
| 69 | + long altitude = myGNSS.getAltitude(); |
| 70 | + Serial.print(F(" Alt: ")); |
| 71 | + Serial.print(altitude); |
| 72 | + Serial.println(F(" (mm)")); |
| 73 | + } |
| 74 | + |
| 75 | + // Calling getNAVPOSECEF returns true if there actually is a fresh position solution available. |
| 76 | + if (myGNSS.getNAVPOSECEF()) |
| 77 | + { |
| 78 | + Serial.print(F("ecefX: ")); |
| 79 | + Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefX / 100.0, 2); // convert ecefX to m |
| 80 | + |
| 81 | + Serial.print(F(" ecefY: ")); |
| 82 | + Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefY / 100.0, 2); // convert ecefY to m |
| 83 | + |
| 84 | + Serial.print(F(" ecefZ: ")); |
| 85 | + Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefZ / 100.0, 2); // convert ecefY to m |
| 86 | + Serial.println(F(" (m)")); |
| 87 | + |
| 88 | + myGNSS.flushNAVPOSECEF(); //Mark all the data as read/stale so we get fresh data next time |
| 89 | + } |
| 90 | + |
| 91 | + // Calling getNAVVELNED returns true if there actually is fresh velocity data available. |
| 92 | + if (myGNSS.getNAVVELNED()) |
| 93 | + { |
| 94 | + Serial.print(F("velN: ")); |
| 95 | + Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velN / 100.0, 2); // convert velN to m/s |
| 96 | + |
| 97 | + Serial.print(F(" velE: ")); |
| 98 | + Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velE / 100.0, 2); // convert velE to m/s |
| 99 | + |
| 100 | + Serial.print(F(" velD: ")); |
| 101 | + Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velD / 100.0, 2); // convert velD to m/s |
| 102 | + Serial.println(F(" (m/s)")); |
| 103 | + |
| 104 | + myGNSS.flushNAVVELNED(); //Mark all the data as read/stale so we get fresh data next time |
| 105 | + } |
| 106 | +} |
0 commit comments