|  | 
|  | 1 | +/* | 
|  | 2 | + Reading lat, long and UTC time via UBX binary commands - no more NMEA parsing! | 
|  | 3 | + By: Paul Clark and Nathan Seidle | 
|  | 4 | + Using the library modifications provided by @blazczak and @geeksville | 
|  | 5 | +  | 
|  | 6 | + SparkFun Electronics | 
|  | 7 | + Date: June 16th, 2020 | 
|  | 8 | + License: MIT. See license file for more information but you can | 
|  | 9 | + basically do whatever you want with this code. | 
|  | 10 | +
 | 
|  | 11 | + This example shows how to query a Ublox module for its lat/long/altitude. We also | 
|  | 12 | + turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic  | 
|  | 13 | + dramatically. | 
|  | 14 | +
 | 
|  | 15 | + Note: Long/lat are large numbers because they are * 10^7. To convert lat/long | 
|  | 16 | + to something google maps understands simply divide the numbers by 10,000,000. We  | 
|  | 17 | + do this so that we don't have to use floating point numbers. | 
|  | 18 | +
 | 
|  | 19 | + Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! | 
|  | 20 | +
 | 
|  | 21 | + Feel like supporting open source hardware? | 
|  | 22 | + Buy a board from SparkFun! | 
|  | 23 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 | 
|  | 24 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 | 
|  | 25 | + SAM-M8Q: https://www.sparkfun.com/products/15106 | 
|  | 26 | +
 | 
|  | 27 | + Hardware Connections: | 
|  | 28 | + Plug a Qwiic cable into the GPS and a BlackBoard | 
|  | 29 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) | 
|  | 30 | + Open the serial monitor at 115200 baud to see the output | 
|  | 31 | +*/ | 
|  | 32 | + | 
|  | 33 | +#include <Wire.h> //Needed for I2C to GPS | 
|  | 34 | + | 
|  | 35 | +#include "SparkFun_Ublox_Arduino_Library_Series_6_7.h" | 
|  | 36 | +SFE_UBLOX_GPS myGPS; | 
|  | 37 | + | 
|  | 38 | +long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. | 
|  | 39 | + | 
|  | 40 | +void setup() | 
|  | 41 | +{ | 
|  | 42 | + Serial.begin(115200); | 
|  | 43 | + while (!Serial); //Wait for user to open terminal | 
|  | 44 | + Serial.println("SparkFun Ublox Example"); | 
|  | 45 | + | 
|  | 46 | + Wire.begin(); | 
|  | 47 | + | 
|  | 48 | + //myGPS.enableDebugging(); // Uncomment this line to enable debug messages | 
|  | 49 | + | 
|  | 50 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port | 
|  | 51 | + { | 
|  | 52 | + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); | 
|  | 53 | + while (1); | 
|  | 54 | + } | 
|  | 55 | + | 
|  | 56 | + myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) | 
|  | 57 | + myGPS.saveConfiguration(); //Save the current settings to flash and BBR | 
|  | 58 | +} | 
|  | 59 | + | 
|  | 60 | +void loop() | 
|  | 61 | +{ | 
|  | 62 | + //Query module only every second. Doing it more often will just cause I2C traffic. | 
|  | 63 | + //The module only responds when a new position is available | 
|  | 64 | + if (millis() - lastTime > 1000) | 
|  | 65 | + { | 
|  | 66 | + lastTime = millis(); //Update the timer | 
|  | 67 | +  | 
|  | 68 | + long latitude = myGPS.getLatitude(); | 
|  | 69 | + Serial.print(F("Lat: ")); | 
|  | 70 | + Serial.print(latitude); | 
|  | 71 | + | 
|  | 72 | + long longitude = myGPS.getLongitude(); | 
|  | 73 | + Serial.print(F(" Long: ")); | 
|  | 74 | + Serial.print(longitude); | 
|  | 75 | + Serial.print(F(" (degrees * 10^-7)")); | 
|  | 76 | + | 
|  | 77 | + long altitude = myGPS.getAltitude(); | 
|  | 78 | + Serial.print(F(" Alt: ")); | 
|  | 79 | + Serial.print(altitude); | 
|  | 80 | + Serial.print(F(" (mm)")); | 
|  | 81 | + | 
|  | 82 | + Serial.print(F(" Time: ")); | 
|  | 83 | + | 
|  | 84 | + byte Hour = myGPS.getHour(); | 
|  | 85 | + if (Hour < 10) | 
|  | 86 | + { | 
|  | 87 | + Serial.print(F("0")); | 
|  | 88 | + } | 
|  | 89 | + Serial.print(Hour); | 
|  | 90 | + Serial.print(F(":")); | 
|  | 91 | + | 
|  | 92 | + byte Minute = myGPS.getMinute(); | 
|  | 93 | + if (Minute < 10) | 
|  | 94 | + { | 
|  | 95 | + Serial.print(F("0")); | 
|  | 96 | + } | 
|  | 97 | + Serial.print(Minute); | 
|  | 98 | + Serial.print(F(":")); | 
|  | 99 | + | 
|  | 100 | + byte Second = myGPS.getSecond(); | 
|  | 101 | + if (Second < 10) | 
|  | 102 | + { | 
|  | 103 | + Serial.print(F("0")); | 
|  | 104 | + } | 
|  | 105 | + Serial.print(Second); | 
|  | 106 | + | 
|  | 107 | + Serial.println(); | 
|  | 108 | + } | 
|  | 109 | +} | 
0 commit comments