|  | 
|  | 1 | +/* | 
|  | 2 | + Configuring the GPS to automatically send position reports over I2C | 
|  | 3 | + By: Nathan Seidle | 
|  | 4 | + SparkFun Electronics | 
|  | 5 | + Date: January 3rd, 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 getPVT. This eliminates the blocking in getPVT while the GPS | 
|  | 11 | + produces a fresh navigation solution at the expense of returning a slighly old solution. | 
|  | 12 | +
 | 
|  | 13 | + This can be used over serial or over I2C, this example shows the I2C use. With serial the GPS | 
|  | 14 | + simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in | 
|  | 15 | + size?) where it can be retrieved in the next I2C poll. | 
|  | 16 | +
 | 
|  | 17 | + Feel like supporting open source hardware? | 
|  | 18 | + Buy a board from SparkFun! | 
|  | 19 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 | 
|  | 20 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 | 
|  | 21 | + SAM-M8Q: https://www.sparkfun.com/products/15106 | 
|  | 22 | +
 | 
|  | 23 | + Hardware Connections: | 
|  | 24 | + Plug a Qwiic cable into the GPS and a BlackBoard | 
|  | 25 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) | 
|  | 26 | + Open the serial monitor at 115200 baud to see the output | 
|  | 27 | +*/ | 
|  | 28 | + | 
|  | 29 | +#include <Wire.h> //Needed for I2C to GPS | 
|  | 30 | + | 
|  | 31 | +#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS | 
|  | 32 | +SFE_UBLOX_GPS myGPS; | 
|  | 33 | + | 
|  | 34 | +void setup() | 
|  | 35 | +{ | 
|  | 36 | + Serial.begin(115200); | 
|  | 37 | + while (!Serial); //Wait for user to open terminal | 
|  | 38 | + Serial.println("SparkFun Ublox Example"); | 
|  | 39 | + | 
|  | 40 | + Wire.begin(); | 
|  | 41 | + | 
|  | 42 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port | 
|  | 43 | + { | 
|  | 44 | + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); | 
|  | 45 | + while (1); | 
|  | 46 | + } | 
|  | 47 | + | 
|  | 48 | + myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) | 
|  | 49 | + myGPS.setNavigationFrequency(2); //Produce two solutions per second | 
|  | 50 | + myGPS.setAutoPVT(true); //Tell the GPS to "send" each solution | 
|  | 51 | + myGPS.saveConfiguration(); //Save the current settings to flash and BBR | 
|  | 52 | +} | 
|  | 53 | + | 
|  | 54 | +void loop() | 
|  | 55 | +{ | 
|  | 56 | + // Calling getPVT returns true if there actually is a fresh navigation solution available. | 
|  | 57 | + if (myGPS.getPVT()) | 
|  | 58 | + { | 
|  | 59 | + Serial.println(); | 
|  | 60 | + long latitude = myGPS.getLatitude(); | 
|  | 61 | + Serial.print(F("Lat: ")); | 
|  | 62 | + Serial.print(latitude); | 
|  | 63 | + | 
|  | 64 | + long longitude = myGPS.getLongitude(); | 
|  | 65 | + Serial.print(F(" Long: ")); | 
|  | 66 | + Serial.print(longitude); | 
|  | 67 | + Serial.print(F(" (degrees * 10^-7)")); | 
|  | 68 | + | 
|  | 69 | + long altitude = myGPS.getAltitude(); | 
|  | 70 | + Serial.print(F(" Alt: ")); | 
|  | 71 | + Serial.print(altitude); | 
|  | 72 | + Serial.print(F(" (mm)")); | 
|  | 73 | + | 
|  | 74 | + byte SIV = myGPS.getSIV(); | 
|  | 75 | + Serial.print(F(" SIV: ")); | 
|  | 76 | + Serial.print(SIV); | 
|  | 77 | + | 
|  | 78 | + Serial.println(); | 
|  | 79 | + } else { | 
|  | 80 | + Serial.print("."); | 
|  | 81 | + delay(50); | 
|  | 82 | + } | 
|  | 83 | +} | 
0 commit comments