|
| 1 | +/* |
| 2 | + Configuring the GPS to automatically send position reports over I2C, with explicit data parsing calls |
| 3 | + By: Nathan Seidle Thorsten von Eicken and Felix Jirka |
| 4 | + SparkFun Electronics |
| 5 | + Date: July 1st, 2019 |
| 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 GPS the send navigation reports automatically |
| 10 | + and retrieving the latest one via checkUblox when available. |
| 11 | + This eliminates the implicit update in getPVT when accessing data fields twice. |
| 12 | + Also this reduces the memory overhead of a separate buffer while introducing a slight error by inconsistencies because of the unsynchronized updates (on a multi core system). |
| 13 | +
|
| 14 | + This can be used over serial or over I2C, this example shows the I2C use. With serial the GPS |
| 15 | + simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in |
| 16 | + size?) where it can be retrieved in the next I2C poll. |
| 17 | +
|
| 18 | + Feel like supporting open source hardware? |
| 19 | + Buy a board from SparkFun! |
| 20 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 |
| 21 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 |
| 22 | + SAM-M8Q: https://www.sparkfun.com/products/15106 |
| 23 | +
|
| 24 | + Hardware Connections: |
| 25 | + Plug a Qwiic cable into the GPS and a BlackBoard |
| 26 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 27 | + Open the serial monitor at 115200 baud to see the output |
| 28 | +*/ |
| 29 | + |
| 30 | +#include <Wire.h> //Needed for I2C to GPS |
| 31 | + |
| 32 | +#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS |
| 33 | +SFE_UBLOX_GPS myGPS; |
| 34 | + |
| 35 | +void setup() |
| 36 | +{ |
| 37 | + Serial.begin(115200); |
| 38 | + while (!Serial); //Wait for user to open terminal |
| 39 | + Serial.println("SparkFun Ublox Example"); |
| 40 | + |
| 41 | + Wire.begin(); |
| 42 | + |
| 43 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port |
| 44 | + { |
| 45 | + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); |
| 46 | + while (1); |
| 47 | + } |
| 48 | + |
| 49 | + myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 50 | + myGPS.setNavigationFrequency(2); //Produce two solutions per second |
| 51 | + myGPS.setAutoPVT(true, false); //Tell the GPS to "send" each solution and the lib not to update stale data implicitly |
| 52 | + myGPS.saveConfiguration(); //Save the current settings to flash and BBR |
| 53 | +} |
| 54 | + |
| 55 | +/* |
| 56 | + Calling getPVT would return false now (compare to Example 13 where it would return true), so we just use the data provided |
| 57 | + If you are using a threaded OS eg. FreeRTOS on an ESP32, the explicit mode of autoPVT allows you to use the data provided on both cores and inside multiple threads |
| 58 | + The data update in background creates an inconsistent state, but that should not cause issues for most applications as they usually won't change the GPS location significantly within a 2Hz - 5Hz update rate. |
| 59 | + Also you could oversample (10Hz - 20Hz) the data to smooth out such issues... |
| 60 | +*/ |
| 61 | +void loop() |
| 62 | +{ |
| 63 | + static uint16_t counter = 0; |
| 64 | + |
| 65 | + if (counter % 10 == 0) { |
| 66 | + // update your AHRS filter here for a ~100Hz update rate |
| 67 | + // GPS data will be quasi static but data from your IMU will be changing |
| 68 | + } |
| 69 | + // debug output each half second |
| 70 | + if (counter % 500 == 0) { |
| 71 | + Serial.println(); |
| 72 | + long latitude = myGPS.getLatitude(); |
| 73 | + Serial.print(F("Lat: ")); |
| 74 | + Serial.print(latitude); |
| 75 | + |
| 76 | + long longitude = myGPS.getLongitude(); |
| 77 | + Serial.print(F(" Long: ")); |
| 78 | + Serial.print(longitude); |
| 79 | + Serial.print(F(" (degrees * 10^-7)")); |
| 80 | + |
| 81 | + long altitude = myGPS.getAltitude(); |
| 82 | + Serial.print(F(" Alt: ")); |
| 83 | + Serial.print(altitude); |
| 84 | + Serial.print(F(" (mm)")); |
| 85 | + |
| 86 | + byte SIV = myGPS.getSIV(); |
| 87 | + Serial.print(F(" SIV: ")); |
| 88 | + Serial.print(SIV); |
| 89 | + |
| 90 | + Serial.println(); |
| 91 | + } |
| 92 | + // call checkUblox all 50ms to capture the gps data |
| 93 | + if (counter % 50 == 0) { |
| 94 | + myGPS.checkUblox(); |
| 95 | + } |
| 96 | + delay(1); |
| 97 | + counter++; |
| 98 | +} |
0 commit comments