├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── README.md ├── Theory.md ├── examples ├── Dead Reckoning │ ├── Example1_calibrateSensor │ │ └── Example1_calibrateSensor.ino │ ├── Example2_getIMUData │ │ └── Example2_getIMUData.ino │ ├── Example3_getSensorStatus │ │ └── Example3_getSensorStatus.ino │ ├── Example4_vehicleDynamics │ │ └── Example4_vehicleDynamics.ino │ ├── Example5_getHNRData │ │ └── Example5_getHNRData.ino │ └── Example6_getAutoHNRData │ │ └── Example6_getAutoHNRData.ino ├── Example10_AltitudeMSL │ └── Example10_AltitudeMSL.ino ├── Example11_ResetModule │ ├── Example1_FactoryDefaultviaI2C │ │ └── Example1_FactoryDefaultviaI2C.ino │ └── Example2_FactoryDefaultsviaSerial │ │ └── Example2_FactoryDefaultsviaSerial.ino ├── Example12_UseUart │ └── Example12_UseUart.ino ├── Example13_PVT │ ├── Example1_AutoPVT │ │ └── Example1_AutoPVT.ino │ ├── Example2_AutoPVT_ExplicitUpdate │ │ └── Example2_AutoPVT_ExplicitUpdate.ino │ └── Example3_AssumeAutoPVTviaUart │ │ └── Example3_AssumeAutoPVTviaUart.ino ├── Example14_DebugOutput │ └── Example14_DebugOutput.ino ├── Example15_GetDateTime │ └── Example15_GetDateTime.ino ├── Example16_Nanosecond_MaxOutput │ └── Example16_Nanosecond_MaxOutput.ino ├── Example16_PartialSecond_MaxOutput │ └── Example16_PartialSecond_MaxOutput.ino ├── Example17_Geofence │ └── Example17_Geofence.ino ├── Example18_PowerSaveMode │ └── Example18_PowerSaveMode.ino ├── Example19_DynamicModel │ └── Example19_DynamicModel.ino ├── Example1_BasicNMEARead │ └── Example1_BasicNMEARead.ino ├── Example20_SendCustomCommand │ └── Example20_SendCustomCommand.ino ├── Example21_ModuleInfo │ └── Example21_ModuleInfo.ino ├── Example22_PowerOff │ └── Example22_PowerOff.ino ├── Example2_NMEAParsing │ └── Example2_NMEAParsing.ino ├── Example3_GetPosition │ └── Example3_GetPosition.ino ├── Example4_FixType │ └── Example4_FixType.ino ├── Example5_SpeedHeadingPrecision │ └── Example5_SpeedHeadingPrecision.ino ├── Example6_EnableNMEASentences │ └── Example6_EnableNMEASentences.ino ├── Example7_OutputRate │ └── Example7_OutputRate.ino ├── Example8_GetProtocolVersion │ └── Example8_GetProtocolVersion.ino ├── Example9_ChangeI2CAddress │ └── Example9_ChangeI2CAddress.ino ├── NEO-M8P-2 │ ├── Example1_EnableRTCM │ │ └── Example1_EnableRTCM.ino │ ├── Example2_StartRTCMBase │ │ └── Example2_StartRTCMBase.ino │ └── Example3_BaseWithLCD │ │ └── Example3_BaseWithLCD.ino ├── Series_6_7 │ └── Example1_GetPositionAndTime_Series_6_7 │ │ ├── Example1_GetPositionAndTime_Series_6_7.ino │ │ ├── SparkFun_Ublox_Arduino_Library_Series_6_7.cpp │ │ └── SparkFun_Ublox_Arduino_Library_Series_6_7.h ├── ZED-F9P │ ├── Example10_GetHighPrecisionPositionAndAccuracy │ │ └── Example10_GetHighPrecisionPositionAndAccuracy.ino │ ├── Example11_GetHighPrecisionPositionUsingDouble │ │ └── Example11_GetHighPrecisionPositionUsingDouble.ino │ ├── Example12_setStaticPosition │ │ └── Example12_setStaticPosition.ino │ ├── Example13_autoHPPOSLLH │ │ └── Example13_autoHPPOSLLH.ino │ ├── Example14_NTRIPServer │ │ ├── Example14_NTRIPServer.ino │ │ └── secrets.h │ ├── Example1_GetPositionAccuracy │ │ └── Example1_GetPositionAccuracy.ino │ ├── Example2_ValConfigurationMethod │ │ └── Example2_ValConfigurationMethod.ino │ ├── Example3_StartRTCMBase │ │ └── Example3_StartRTCMBase.ino │ ├── Example4_BaseWithLCD │ │ └── Example4_BaseWithLCD.ino │ ├── Example5_RelativePositioningInformation │ │ └── Example5_RelativePositioningInformation.ino │ ├── Example6_GetVal │ │ └── Example6_GetVal.ino │ ├── Example7_SetVal │ │ └── Example7_SetVal.ino │ ├── Example8_GetSetPortSettings │ │ └── Example8_GetSetPortSettings.ino │ └── Example9_multiSetVal │ │ └── Example9_multiSetVal.ino └── Zephyr │ └── Example1_GetPositionAndTime_Zephyr │ ├── CMakeLists.txt │ ├── nrf52840dk_nrf52840.overlay │ ├── prj.conf │ └── src │ ├── SparkFun_Ublox_Zephyr_Interface.cpp │ ├── SparkFun_Ublox_Zephyr_Interface.h │ ├── SparkFun_Ublox_Zephyr_Library.cpp │ ├── SparkFun_Ublox_Zephyr_Library.h │ └── main.c ├── img └── Contributing.JPG ├── keywords.txt ├── library.properties └── src ├── SparkFun_Ublox_Arduino_Library.cpp ├── SparkFun_Ublox_Arduino_Library.h └── u-blox_config_keys.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Visual Studio Code files 2 | .vscode 3 | 4 | # Windows image file caches 5 | Thumbs.db 6 | ehthumbs.db 7 | 8 | # Folder config file 9 | Desktop.ini 10 | 11 | # Recycle Bin used on file shares 12 | $RECYCLE.BIN/ 13 | 14 | # Windows Installer files 15 | *.cab 16 | *.msi 17 | *.msm 18 | *.msp 19 | 20 | # Windows shortcuts 21 | *.lnk 22 | 23 | # ========================= 24 | # Operating System Files 25 | # ========================= 26 | 27 | # OSX 28 | # ========================= 29 | 30 | .DS_Store 31 | .AppleDouble 32 | .LSOverride 33 | 34 | # Thumbnails 35 | ._* 36 | 37 | # Files that might appear in the root of a volume 38 | .DocumentRevisions-V100 39 | .fseventsd 40 | .Spotlight-V100 41 | .TemporaryItems 42 | .Trashes 43 | .VolumeIcon.icns 44 | 45 | # Directories potentially created on remote AFP share 46 | .AppleDB 47 | .AppleDesktop 48 | Network Trash Folder 49 | Temporary Items 50 | .apdisk 51 | 52 | # VIM backup files 53 | *~ 54 | [._]*.un~ 55 | *.swp 56 | 57 | # Zephyr build files 58 | examples/Zephyr/*/build/* -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Thank you so *much* for offering to help out. We truly appreciate it. 4 | 5 | If you'd like to contribute, start by searching through the [issues](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/issues) and [pull requests](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/pulls) to see whether someone else has raised a similar idea or question. 6 | Please check the [closed issues](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/issues?q=is%3Aissue+is%3Aclosed) 7 | and [closed pull requests](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/pulls?q=is%3Apr+is%3Aclosed) too - you may find that your issue or feature has already been discussed. 8 | 9 | If you decide to add a feature to this library, please create a PR and follow these best practices: 10 | 11 | * Change as little as possible. Do not submit a PR that changes 100 lines of whitespace. Break up into multiple PRs if necessary. 12 | * If you've added a new feature document it with a simple example sketch. This serves both as a test of your PR and as a quick way for users to quickly learn how to use your new feature. 13 | * If you add new functions also add them to _keywords.txt_ so that they are properly highlighted in Arduino. [Read more](https://www.arduino.cc/en/Hacking/libraryTutorial). 14 | * **Important:** Please submit your PR using the [release_candidate branch](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/tree/release_candidate). That way, we can merge and test your PR quickly without changing the _master_ branch 15 | 16 | ![Contributing.JPG](./img/Contributing.JPG) 17 | 18 | ## Style guide 19 | 20 | Please read and follow the [Arduino API style guide](https://www.arduino.cc/en/Reference/APIStyleGuide). Also read and consider the [Arduino style guide](https://www.arduino.cc/en/Reference/StyleGuide). 21 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Subject of the issue 2 | Describe your issue here. If you reference a datasheet please specify which one and in which section (ie, the protocol manual, section 5.1.2). Additionally, screenshots are easy to paste into github. 3 | 4 | ### Your workbench 5 | * What development board or microcontroller are you using? 6 | * What version of hardware or breakout board are you using? 7 | * How is the breakout board wired to your microcontroller? 8 | * How is everything being powered? 9 | * Are there any additional details that may help us help you? 10 | 11 | ### Steps to reproduce 12 | Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue. 13 | 14 | ### Expected behavior 15 | Tell us what should happen 16 | 17 | ### Actual behavior 18 | Tell us what happens instead 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | SparkFun License Information 2 | ============================ 3 | 4 | SparkFun uses two different licenses for our files — one for hardware and one for code. 5 | 6 | Hardware 7 | --------- 8 | 9 | **SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).** 10 | 11 | Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode). 12 | 13 | You are free to: 14 | 15 | Share — copy and redistribute the material in any medium or format 16 | Adapt — remix, transform, and build upon the material 17 | for any purpose, even commercially. 18 | The licensor cannot revoke these freedoms as long as you follow the license terms. 19 | Under the following terms: 20 | 21 | Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 22 | ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. 23 | No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. 24 | Notices: 25 | 26 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation. 27 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material. 28 | 29 | 30 | Code 31 | -------- 32 | 33 | **SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).** 34 | 35 | The MIT License (MIT) 36 | 37 | Copyright (c) 2016 SparkFun Electronics 38 | 39 | Permission is hereby granted, free of charge, to any person obtaining a copy 40 | of this software and associated documentation files (the "Software"), to deal 41 | in the Software without restriction, including without limitation the rights 42 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 43 | copies of the Software, and to permit persons to whom the Software is 44 | furnished to do so, subject to the following conditions: 45 | 46 | The above copyright notice and this permission notice shall be included in all 47 | copies or substantial portions of the Software. 48 | 49 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 50 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 51 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 52 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 53 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 54 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | -------------------------------------------------------------------------------- /Theory.md: -------------------------------------------------------------------------------- 1 | How I2C (aka DDC) communication works with a u-blox module 2 | =========================================================== 3 | 4 | When the user calls one of the methods the library will poll the u-blox module for new data. 5 | 6 | * Wait for a minimum of 25 ms between polls (configured dynamically when update rate is set) 7 | * Write 0xFD to module 8 | * Read two bytes (0xFD and 0xFE) for bytes available 9 | * If 0x7F or 0xFF then no bytes are available 10 | * Otherwise, read number of bytes and process into NMEA, UBX, or RTCM frame. 11 | * If checksum is valid, flag frame as complete. 12 | 13 | This library was originally written to use the I2C interface but Serial has been implemented as well. 14 | 15 | How data is processed by this library 16 | =========================================================== 17 | 18 | A method will call **sendCommand()**. This will begin waiting for a response with either **waitForACKResponse()** or **waitForNoACKResponse()** depending on the command we have sent (CFG commands generate an ACK where others like PVT do not). 19 | 20 | Once **waitForACKResponse()** or **waitForNoACKResponse()** is called the library will start checking the u-blox module for new bytes. These bytes may be part of a NMEA sentence, an RTCM sentence, or a UBX packet. The library will file each byte into the appropriate container. Once a given sentence or packet is complete, the appropriate processUBX(), processNMEA() will be called. These functions deal with specific processing for each type. 21 | 22 | Note: When interfacing to a u-blox module over I2C **checkUbloxI2C()** will read all bytes currently sitting in the I2C buffer. This may pick up multiple UBX packets. For example, an ACK for a VALSET may be mixed in with an **AutoPVT** response. We cannot tell **checkUbloxI2C()** to stop once a given ACK is found because we run the risk of leaving unprocessed bytes in the I2C buffer and losing them. We don't have this issue with **checkUbloxSerial()**. 23 | 24 | **processUBX()** will check the CRC of the UBX packet. If validated, the packet will be marked as valid. Once a packet is marked as valid then **processUBXpacket()** is called to extract the contents. This is most commonly used to get the position, velocity, and time (PVT) out of the packet but is also used to check the nature of an ACK packet. 25 | 26 | Once a packet has been processed, **waitForACKResponse()/waitForNoACKResponse()** makes the appropriate decision what to do with it. If a packet satisfies the CLS/ID and characteristics of what **waitForACKResponse()/waitForNoACKResponse()** is waiting for, then it returns back to **sendCommand()**. If the packet didn't match or was invalid then **waitForACKResponse()/waitForNoACKResponse()** will continue to wait until the correct packet is received or we time out. **sendCommand()** then returns with a value from the **sfe_ublox_status_e** enum depending on the success of **waitForACKResponse()/waitForNoACKResponse()**. 27 | 28 | If we are getting / polling data from the module, **sendCommand()** will return **SFE_UBLOX_STATUS_DATA_RECEIVED** if the get was successful. 29 | 30 | If we are setting / writing data to the module, **sendCommand()** will return **SFE_UBLOX_STATUS_DATA_SENT** if the set was successful. 31 | 32 | We are proud that this library still compiles and runs on the original RedBoard (ATmega328P). We achieve that by being very careful about how much RAM we allocate to packet storage. We use only three buffers or containers to store the incoming data: 33 | - **packetBuf** (packetBuffer) - is small and is used to store only the head (and tail) of incoming UBX packets until we know they are. If the packet is _expected_ (i.e. it matches the Class and ID in the packet passed in **sendCommand()**) then the incoming bytes are diverted into **packetCfg** or **packetAck**. Unexpected packets are ignored. 34 | - **packetCfg** (packetConfiguration) - is used to store an _expected_ incoming UBX packet of up to 256 bytes. E.g. **getProtocolVersion()** returns about 220 bytes. Message data requested by a higher function is returned in packetCfg. 35 | - **packetAck** (packetAcknowledge) - is small and is used to store the ACK or NACK accompanying any _expected_ packetCfg. 36 | 37 | **AutoPVT**, **AutoHPPOSLLH** and **AutoDOP** packets can arrive at any time. They too _have_ to be stored and processed in **packetCfg**. This means there are circumstances where the library can get the data it is expecting from the module, but it is overwritten (e.g. by an **AutoPVT** packet) before **sendCommand()** is able to return. In this case, **sendCommand()** will return the error **SFE_UBLOX_STATUS_DATA_OVERWRITTEN**. We should simply call the library function again, but we will need to reset the packet contents first as they will indeed have been overwritten as the error implies. 38 | 39 | Need a command that is not currently "built-in" to the library? You can do that using a Custom Command. Check out [Example20_SendCustomCommand](https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/blob/master/examples/Example20_SendCustomCommand/Example20_SendCustomCommand.ino) for further details. Note: this will of course increase your RAM use. 40 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example1_calibrateSensor/Example1_calibrateSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Elias Santistevan 3 | SparkFun Electronics 4 | Date: May, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | Feel like supporting open source hardware? 9 | Buy a board from SparkFun! 10 | NEO-M8U: https://www.sparkfun.com/products/16329 11 | ZED-F9R: https://www.sparkfun.com/products/16344 12 | 13 | Hardware Connections: 14 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 15 | If you don't have a platform with a Qwiic connection use the 16 | SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 17 | Open the serial monitor at 115200 baud to see the output 18 | 19 | To take advantage of the internal IMU of either the Dead Reckoning GPS 20 | boards (ZED-F9R, NEO-M8U), you must first calibrate it. This includes securing the GPS module 21 | to your vehicle so that it is stable within 2 degrees and that the frame of 22 | reference of the board is consistent with the picture outlined in the 23 | Receiver-Description-Prot-Spec Datasheet under Automotive/Untethered Dead 24 | Reckoning. You may also check either the ZED-F9R or NEO-M8U Hookup Guide for 25 | more information. After the board is secure, you'll need to put the module 26 | through certain conditions for proper calibration: acceleration, turning, 27 | stopping for a few minutes, getting to a speed over 30km/h all under a clear sky 28 | with good GNSS signal. This example simply looks at the 29 | "fusionMode" status which indicates whether the SparkFun Dead Reckoning is 30 | not-calibrated - 0, or calibrated - 1. 31 | */ 32 | 33 | #include //Needed for I2C to GPS 34 | 35 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 36 | SFE_UBLOX_GPS myGPS; 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println(F("SparkFun Ublox Example")); 43 | 44 | Wire.begin(); 45 | 46 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 47 | { 48 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 49 | while (1); 50 | } 51 | 52 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 53 | } 54 | 55 | void loop() 56 | { 57 | 58 | if (myGPS.getEsfInfo()){ 59 | Serial.print(F("Fusion Mode: ")); 60 | Serial.println(myGPS.imuMeas.fusionMode); 61 | if (myGPS.imuMeas.fusionMode == 1) 62 | Serial.println(F("Sensor is calibrated!")); 63 | } 64 | 65 | delay(250); 66 | } 67 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example2_getIMUData/Example2_getIMUData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Elias Santistevan 3 | SparkFun Electronics 4 | Date: May, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | Feel like supporting open source hardware? 9 | Buy a board from SparkFun! 10 | NEO-M8U: https://www.sparkfun.com/products/16329 11 | ZED-F9R: https://www.sparkfun.com/products/16344 12 | 13 | Hardware Connections: 14 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 15 | If you don't have a platform with a Qwiic connection use the 16 | SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 17 | Open the serial monitor at 115200 baud to see the output 18 | 19 | After calibrating the module, also known as "Fusion Mode", you can get 20 | data directly from the IMU. This data is integrated directly into the GNSS 21 | output, but is provided by the module as well. 22 | 23 | */ 24 | 25 | #include //Needed for I2C to GPS 26 | 27 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | while (!Serial); //Wait for user to open terminal 34 | Serial.println(F("SparkFun Ublox Example")); 35 | 36 | Wire.begin(); 37 | 38 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 39 | { 40 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 41 | while (1); 42 | } 43 | 44 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 45 | 46 | if (myGPS.getEsfInfo()){ 47 | 48 | Serial.print(F("Fusion Mode: ")); 49 | Serial.println(myGPS.imuMeas.fusionMode); 50 | 51 | if (myGPS.imuMeas.fusionMode == 1){ 52 | Serial.println(F("Fusion Mode is Initialized!")); 53 | } 54 | else { 55 | Serial.println(F("Fusion Mode is either disabled or not initialized - Freezing!")); 56 | Serial.println(F("Please see Example 1 description at top for more information.")); 57 | } 58 | } 59 | } 60 | 61 | void loop() 62 | { 63 | 64 | if (myGPS.getEsfIns()) 65 | { 66 | Serial.print(F("X: ")); 67 | Serial.println(myGPS.imuMeas.xAngRate); 68 | Serial.print(F("Y: ")); 69 | Serial.println(myGPS.imuMeas.yAngRate); 70 | Serial.print(F("Z: ")); 71 | Serial.println(myGPS.imuMeas.zAngRate); 72 | Serial.print(F("X Acceleration: ")); 73 | Serial.println(myGPS.imuMeas.xAccel); 74 | Serial.print(F("Y Acceleration: ")); 75 | Serial.println(myGPS.imuMeas.yAccel); 76 | Serial.print(F("Z Acceleration: ")); 77 | Serial.println(myGPS.imuMeas.zAccel); 78 | // These values also have "validity checks" that can be provided by the 79 | // ublox library, add "Vald" to values: e.g. xAngRateVald or xAccelVald. 80 | } 81 | 82 | delay(250); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example3_getSensorStatus/Example3_getSensorStatus.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Elias Santistevan 3 | SparkFun Electronics 4 | Date: May, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | Feel like supporting open source hardware? 9 | Buy a board from SparkFun! 10 | NEO-M8U: https://www.sparkfun.com/products/16329 11 | ZED-F9R: https://www.sparkfun.com/products/16344 12 | 13 | Hardware Connections: 14 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 15 | If you don't have a platform with a Qwiic connection use the 16 | SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 17 | Open the serial monitor at 115200 baud to see the output 18 | 19 | After calibrating the module, also known as "Fusion Mode", you can get 20 | data directly from the IMU. This example code walks you through trouble 21 | shooting or identifying the different states of any individual 22 | "external" (which include internal) sensors you've hooked up (vehicle speed 23 | sensor) or the internal IMU used by the modules. You can see if the sensor is 24 | being used, if it's calibrated, ready, what data type it returns, the state 25 | of the measurement etc. 26 | 27 | */ 28 | 29 | #include //Needed for I2C to GPS 30 | 31 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 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(F("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 | 50 | // GetEsfInfo also gets the number of sensors used by the ublox module, this 51 | // includes (in the case of the ZED-F9R) wheel tick input from the vehicle 52 | // speed sensor attached to the module. 53 | if (myGPS.getEsfInfo()){ 54 | 55 | Serial.print(F("Fusion Mode: ")); 56 | Serial.println(myGPS.imuMeas.fusionMode); 57 | 58 | if (myGPS.imuMeas.fusionMode == 1){ 59 | Serial.println(F("Fusion Mode is Initialized!")); 60 | } 61 | else { 62 | Serial.println(F("Fusion Mode is either disabled or not initialized - Freezing!")); 63 | Serial.println(F("Please see Example 1 description at top for more information.")); 64 | } 65 | } 66 | } 67 | 68 | void loop() 69 | { 70 | 71 | for(int i=1; i<=myGPS.ubloxSen.numSens; i++){ 72 | myGPS.getSensState(i); // Give the sensor you want to check on. 73 | Serial.print(F("Sensor Data Type: ")); //See ublox receiver description 74 | //or our hookup guide for information on the 75 | //return value. 76 | Serial.println(myGPS.ubloxSen.senType); 77 | Serial.print(F("Being Used: ")); 78 | Serial.println(myGPS.ubloxSen.isUsed); 79 | Serial.print(F("Is Ready: ")); 80 | Serial.println(myGPS.ubloxSen.isReady); 81 | Serial.print(F("Calibration Status: ")); 82 | Serial.println(myGPS.ubloxSen.calibStatus); 83 | Serial.print(F("Time Status: ")); 84 | Serial.println(myGPS.ubloxSen.timeStatus); 85 | Serial.print(F("Bad Measure: ")); 86 | Serial.println(myGPS.ubloxSen.timeStatus); 87 | Serial.print(F("Bad Time Tag: ")); 88 | Serial.println(myGPS.ubloxSen.badTag); 89 | Serial.print(F("Missed Measure : ")); 90 | Serial.println(myGPS.ubloxSen.missMeas); 91 | Serial.print(F("Noisy Measure: ")); 92 | Serial.println(myGPS.ubloxSen.noisyMeas); 93 | } 94 | 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example4_vehicleDynamics/Example4_vehicleDynamics.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Elias Santistevan 3 | SparkFun Electronics 4 | Date: May, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | Feel like supporting open source hardware? 9 | Buy a board from SparkFun! 10 | NEO-M8U: https://www.sparkfun.com/products/16329 11 | ZED-F9R: https://www.sparkfun.com/products/16344 12 | 13 | Hardware Connections: 14 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 15 | If you don't have a platform with a Qwiic connection use the 16 | SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 17 | Open the serial monitor at 115200 baud to see the output 18 | 19 | After calibrating the module and securing it to your vehicle such that it's 20 | stable within 2 degrees, and the board is oriented correctly with regards to 21 | the vehicle's frame, you can now read the vehicle's "attitude". The attitude 22 | includes the vehicle's heading, pitch, and roll. You can also check the 23 | accuracy of those readings. 24 | 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | while (!Serial); //Wait for user to open terminal 36 | Serial.println(F("SparkFun Ublox Example")); 37 | 38 | Wire.begin(); 39 | 40 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 41 | { 42 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 43 | while (1); 44 | } 45 | 46 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 47 | 48 | if (myGPS.getEsfInfo()){ 49 | 50 | Serial.print(F("Fusion Mode: ")); 51 | Serial.println(myGPS.imuMeas.fusionMode); 52 | 53 | if (myGPS.imuMeas.fusionMode == 1){ 54 | Serial.println(F("Fusion Mode is Initialized!")); 55 | } 56 | else { 57 | Serial.println(F("Fusion Mode is either disabled or not initialized - Freezing!")); 58 | Serial.println(F("Please see Example 1 description at top for more information.")); 59 | } 60 | } 61 | } 62 | 63 | void loop() 64 | { 65 | myGPS.getVehAtt(); // Give the sensor you want to check on. 66 | Serial.print(F("Roll: ")); 67 | Serial.println(myGPS.vehAtt.roll); 68 | Serial.print(F("Pitch: ")); 69 | Serial.println(myGPS.vehAtt.pitch); 70 | Serial.print(F("Heading: ")); 71 | Serial.println(myGPS.vehAtt.heading); 72 | Serial.print(F("Roll Accuracy: ")); 73 | Serial.println(myGPS.vehAtt.accRoll); 74 | Serial.print(F("Pitch Accuracy: ")); 75 | Serial.println(myGPS.vehAtt.accPitch); 76 | Serial.print(F("Heading Accuracy: ")); 77 | Serial.println(myGPS.vehAtt.accHeading); 78 | 79 | delay(250); 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example5_getHNRData/Example5_getHNRData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Paul Clark 3 | SparkFun Electronics 4 | Date: December, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | This example configures the High Navigation Rate on the NEO-M8U and then 9 | polls and displays the attitude solution, vehicle dynamics information 10 | and high rate position, velocity and time. 11 | 12 | This example polls the high rate data. 13 | (The next example uses "autoHNR" to receive the HNR data automatically.) 14 | 15 | Please make sure your NEO-M8U is running UDR firmware >= 1.31. Please update using u-center if necessary: 16 | https://www.u-blox.com/en/product/neo-m8u-module#tab-documentation-resources 17 | 18 | Feel like supporting open source hardware? 19 | Buy a board from SparkFun! 20 | NEO-M8U: https://www.sparkfun.com/products/16329 21 | 22 | Hardware Connections: 23 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 24 | If you don't have a platform with a Qwiic connection use the 25 | 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 | 30 | #include //Needed for I2C to GPS 31 | 32 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 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(F("SparkFun u-blox Example")); 40 | 41 | Wire.begin(); 42 | 43 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages on Serial 44 | 45 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 46 | { 47 | Serial.println(F("Warning! u-blox GPS did not begin correctly.")); 48 | Serial.println(F("(This may be because the I2C port is busy with HNR messages.)")); 49 | } 50 | 51 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 52 | myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR 53 | 54 | if (myGPS.setHNRNavigationRate(10) == true) //Set the High Navigation Rate to 10Hz 55 | Serial.println(F("setHNRNavigationRate was successful")); 56 | else 57 | Serial.println(F("setHNRNavigationRate was NOT successful")); 58 | } 59 | 60 | void loop() 61 | { 62 | // Poll and print selected HNR data 63 | if (myGPS.getHNRAtt(125) == true) // Request HNR Att data using a 125ms timeout 64 | { 65 | Serial.print(F("Roll: ")); 66 | Serial.print(myGPS.hnrAtt.roll); 67 | Serial.print(F(" Pitch: ")); 68 | Serial.print(myGPS.hnrAtt.pitch); 69 | Serial.print(F(" Heading: ")); 70 | Serial.println(myGPS.hnrAtt.heading); 71 | } 72 | if (myGPS.getHNRDyn(125) == true) // Request HNR Dyn data using a 125ms timeout 73 | { 74 | Serial.print(F("xAccel: ")); 75 | Serial.print(myGPS.hnrVehDyn.xAccel); 76 | Serial.print(F(" yAccel: ")); 77 | Serial.print(myGPS.hnrVehDyn.yAccel); 78 | Serial.print(F(" zAccel: ")); 79 | Serial.println(myGPS.hnrVehDyn.zAccel); 80 | } 81 | if (myGPS.getHNRPVT(125) == true) // Request HNR PVT data using a 125ms timeout 82 | { 83 | Serial.print(F("ns: ")); 84 | Serial.print(myGPS.hnrPVT.nano); 85 | Serial.print(F(" Lat: ")); 86 | Serial.print(myGPS.hnrPVT.lat); 87 | Serial.print(F(" Lon: ")); 88 | Serial.println(myGPS.hnrPVT.lon); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /examples/Dead Reckoning/Example6_getAutoHNRData/Example6_getAutoHNRData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By: Paul Clark 3 | SparkFun Electronics 4 | Date: December, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | This example configures the High Navigation Rate on the NEO-M8U and then 9 | reads and displays the attitude solution, vehicle dynamics information 10 | and high rate position, velocity and time. 11 | 12 | This example uses "autoHNR" to receive the HNR data automatically. 13 | 14 | Please make sure your NEO-M8U is running UDR firmware >= 1.31. Please update using u-center if necessary: 15 | https://www.u-blox.com/en/product/neo-m8u-module#tab-documentation-resources 16 | 17 | Feel like supporting open source hardware? 18 | Buy a board from SparkFun! 19 | NEO-M8U: https://www.sparkfun.com/products/16329 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a Redboard Qwiic 23 | If you don't have a platform with a Qwiic connection use the 24 | SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 25 | Open the serial monitor at 115200 baud to see the output 26 | 27 | */ 28 | 29 | #include //Needed for I2C to GPS 30 | 31 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 32 | SFE_UBLOX_GPS myGPS; 33 | 34 | boolean usingAutoHNRAtt = false; 35 | boolean usingAutoHNRDyn = false; 36 | boolean usingAutoHNRPVT = false; 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println(F("SparkFun u-blox Example")); 43 | 44 | Wire.begin(); 45 | 46 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages on Serial 47 | 48 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 49 | { 50 | Serial.println(F("Warning! u-blox GPS did not begin correctly.")); 51 | Serial.println(F("(This may be because the I2C port is busy with HNR messages.)")); 52 | } 53 | 54 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 55 | myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR 56 | 57 | if (myGPS.setHNRNavigationRate(10) == true) //Set the High Navigation Rate to 10Hz 58 | Serial.println(F("setHNRNavigationRate was successful")); 59 | else 60 | Serial.println(F("setHNRNavigationRate was NOT successful")); 61 | 62 | usingAutoHNRAtt = myGPS.setAutoHNRAtt(true); //Attempt to enable auto HNR attitude messages 63 | usingAutoHNRDyn = myGPS.setAutoHNRDyn(true); //Attempt to enable auto HNR vehicle dynamics messages 64 | usingAutoHNRPVT = myGPS.setAutoHNRPVT(true); //Attempt to enable auto HNR PVT messages 65 | } 66 | 67 | void loop() 68 | { 69 | if (usingAutoHNRAtt && (myGPS.getHNRAtt() == true)) // If setAutoHNRAtt was successful and new data is available 70 | { 71 | Serial.print(F("Roll: ")); // Print selected data 72 | Serial.print(myGPS.hnrAtt.roll); 73 | Serial.print(F(" Pitch: ")); 74 | Serial.print(myGPS.hnrAtt.pitch); 75 | Serial.print(F(" Heading: ")); 76 | Serial.println(myGPS.hnrAtt.heading); 77 | } 78 | if (usingAutoHNRDyn && (myGPS.getHNRDyn() == true)) // If setAutoHNRDyn was successful and new data is available 79 | { 80 | Serial.print(F("xAccel: ")); // Print selected data 81 | Serial.print(myGPS.hnrVehDyn.xAccel); 82 | Serial.print(F(" yAccel: ")); 83 | Serial.print(myGPS.hnrVehDyn.yAccel); 84 | Serial.print(F(" zAccel: ")); 85 | Serial.println(myGPS.hnrVehDyn.zAccel); 86 | } 87 | if (usingAutoHNRPVT && (myGPS.getHNRPVT() == true)) // If setAutoHNRPVT was successful and new data is available 88 | { 89 | Serial.print(F("ns: ")); // Print selected data 90 | Serial.print(myGPS.hnrPVT.nano); 91 | Serial.print(F(" Lat: ")); 92 | Serial.print(myGPS.hnrPVT.lat); 93 | Serial.print(F(" Lon: ")); 94 | Serial.println(myGPS.hnrPVT.lon); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/Example10_AltitudeMSL/Example10_AltitudeMSL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading two altitudes - Mean Sea Level and Ellipsode 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 query a Ublox module for its lat/long/altitude. 10 | 11 | getAltitude() reports mm above ellipsode model of the globe. There are some 12 | instances where altitude above Mean Sea Level is better. This example shows how 13 | to use getAltitudeMSL(). The difference varies but is ~20m. 14 | Ellipsoid model: https://www.esri.com/news/arcuser/0703/geoid1of3.html 15 | Difference between Ellipsoid Model and Mean Sea Level: https://eos-gnss.com/elevation-for-beginners/ 16 | 17 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 18 | 19 | Feel like supporting open source hardware? 20 | Buy a board from SparkFun! 21 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 22 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 23 | SAM-M8Q: https://www.sparkfun.com/products/15106 24 | 25 | Hardware Connections: 26 | Plug a Qwiic cable into the GPS and a BlackBoard 27 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 28 | Open the serial monitor at 115200 baud to see the output 29 | */ 30 | 31 | #include //Needed for I2C to GPS 32 | 33 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 34 | SFE_UBLOX_GPS myGPS; 35 | 36 | long lastTime = 0; //Tracks the passing of 2000ms (2 seconds) 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println("SparkFun Ublox Example"); 43 | 44 | Wire.begin(); 45 | 46 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 47 | { 48 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 49 | while (1); 50 | } 51 | } 52 | 53 | void loop() 54 | { 55 | //Query module only every second. Doing it more often will just cause I2C traffic. 56 | //The module only responds when a new position is available 57 | if (millis() - lastTime > 1000) 58 | { 59 | lastTime = millis(); //Update the timer 60 | 61 | long latitude = myGPS.getLatitude(); 62 | Serial.print(F("Lat: ")); 63 | Serial.print(latitude); 64 | 65 | long longitude = myGPS.getLongitude(); 66 | Serial.print(F(" Long: ")); 67 | Serial.print(longitude); 68 | Serial.print(F(" (degrees * 10^-7)")); 69 | 70 | long altitude = myGPS.getAltitude(); 71 | Serial.print(F(" Alt: ")); 72 | Serial.print(altitude); 73 | Serial.print(F(" (mm)")); 74 | 75 | long altitudeMSL = myGPS.getAltitudeMSL(); 76 | Serial.print(F(" AltMSL: ")); 77 | Serial.print(altitudeMSL); 78 | Serial.print(F(" (mm)")); 79 | 80 | Serial.println(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /examples/Example11_ResetModule/Example1_FactoryDefaultviaI2C/Example1_FactoryDefaultviaI2C.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send command to reset module over I2C 3 | By: Nathan Seidle 4 | Date: January 29rd, 2019 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | This example shows how to reset the U-Blox module to factory defaults over I2C. 9 | 10 | Feel like supporting open source hardware? 11 | Buy a board from SparkFun! 12 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 13 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 14 | SAM-M8Q: https://www.sparkfun.com/products/15106 15 | 16 | Hardware Connections: 17 | Plug a Qwiic cable into the GNSS 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 //http://librarymanager/All#SparkFun_u-blox_GNSS 23 | SFE_UBLOX_GPS myGPS; 24 | 25 | void setup() 26 | { 27 | Serial.begin(115200); 28 | while (!Serial); //Wait for user to open terminal 29 | Serial.println("SparkFun Ublox Example"); 30 | 31 | Wire.begin(); 32 | 33 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 34 | { 35 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 36 | while (1); 37 | } 38 | 39 | while (Serial.available()) Serial.read(); //Trash any incoming chars 40 | Serial.println("Press a key to reset module to factory defaults"); 41 | while (Serial.available() == false) ; //Wait for user to send character 42 | 43 | myGPS.factoryReset(); //Reset everything: baud rate, I2C address, update rate, everything. 44 | 45 | if (myGPS.begin() == false) //Attempt to re-connect 46 | { 47 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 48 | while (1); 49 | } 50 | 51 | Serial.println("Unit has now been factory reset. Freezing..."); 52 | while(1); 53 | } 54 | 55 | void loop() 56 | { 57 | 58 | } 59 | -------------------------------------------------------------------------------- /examples/Example11_ResetModule/Example2_FactoryDefaultsviaSerial/Example2_FactoryDefaultsviaSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Test baud rate changes on serial, factory reset, and hard reset. 3 | By: Thorsten von Eicken 4 | Date: January 29rd, 2019 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | This example shows how to reset the U-Blox module to factory defaults over serial. 9 | 10 | Feel like supporting open source hardware? 11 | Buy a board from SparkFun! 12 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 13 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 14 | SAM-M8Q: https://www.sparkfun.com/products/15106 15 | 16 | Hardware Connections: 17 | Connect the U-Blox serial port to Serial1 18 | If you're using an Uno or don't have a 2nd serial port (Serial1), consider using software serial 19 | Open the serial monitor at 115200 baud to see the output 20 | */ 21 | 22 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 23 | SFE_UBLOX_GPS myGPS; 24 | 25 | int state = 0; // steps through auto-baud, reset, etc states 26 | 27 | void setup() 28 | { 29 | Serial.begin(115200); 30 | while (!Serial); //Wait for user to open terminal 31 | Serial.println("SparkFun Ublox Example"); 32 | } 33 | 34 | void loop() 35 | { 36 | Serial.print("===== STATE "); 37 | Serial.println(state); 38 | switch (state) { 39 | case 0: // auto-baud connection, then switch to 38400 and save config 40 | do { 41 | Serial.println("GPS: trying 38400 baud"); 42 | Serial1.begin(38400); 43 | if (myGPS.begin(Serial1)) break; 44 | 45 | delay(100); 46 | Serial.println("GPS: trying 9600 baud"); 47 | Serial1.begin(9600); 48 | if (myGPS.begin(Serial1)) { 49 | Serial.println("GPS: connected at 9600 baud, switching to 38400"); 50 | myGPS.setSerialRate(38400); 51 | delay(100); 52 | } else { 53 | delay(2000); //Wait a bit before trying again to limit the Serial output flood 54 | } 55 | } while(1); 56 | myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only 57 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 58 | Serial.println("GPS serial connected, saved config"); 59 | state++; 60 | break; 61 | case 1: // hardReset, expect to see GPS back at 38400 baud 62 | Serial.println("Issuing hardReset (cold start)"); 63 | myGPS.hardReset(); 64 | delay(1000); 65 | Serial1.begin(38400); 66 | if (myGPS.begin(Serial1)) { 67 | Serial.println("Success."); 68 | state++; 69 | } else { 70 | Serial.println("*** GPS did not respond at 38400 baud, starting over."); 71 | state = 0; 72 | } 73 | break; 74 | case 2: // factoryReset, expect to see GPS back at 9600 baud 75 | Serial.println("Issuing factoryReset"); 76 | myGPS.factoryReset(); 77 | delay(2000); // takes more than one second... a loop to resync would be best 78 | Serial1.begin(9600); 79 | if (myGPS.begin(Serial1)) { 80 | Serial.println("Success."); 81 | state++; 82 | } else { 83 | Serial.println("*** GPS did not come back at 9600 baud, starting over."); 84 | state = 0; 85 | } 86 | break; 87 | case 3: // print version info 88 | Serial.print("GPS protocol version: "); 89 | Serial.print(myGPS.getProtocolVersionHigh()); 90 | Serial.print('.'); 91 | Serial.print(myGPS.getProtocolVersionLow()); 92 | state = 0; 93 | } 94 | delay(1000); 95 | } 96 | -------------------------------------------------------------------------------- /examples/Example12_UseUart/Example12_UseUart.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading lat and long via UBX binary commands using UART @38400 baud - free from I2C 3 | By: Nathan Seidle, Adapted from Example3_GetPosition by Thorsten von Eicken 4 | SparkFun Electronics 5 | Date: January 28rd, 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 library and U-Blox for serial port use as well as 10 | switching the module from the default 9600 baud to 38400. 11 | 12 | Note: Long/lat are large numbers because they are * 10^7. To convert lat/long 13 | to something google maps understands simply divide the numbers by 10,000,000. We 14 | do this so that we don't have to use floating point numbers. 15 | 16 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 | Connect the U-Blox serial TX pin to Uno pin 10 26 | Connect the U-Blox serial RX pin to Uno pin 11 27 | Open the serial monitor at 115200 baud to see the output 28 | */ 29 | 30 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 31 | SFE_UBLOX_GPS myGPS; 32 | 33 | #include 34 | SoftwareSerial mySerial(10, 11); // RX, TX. Pin 10 on Uno goes to TX pin on GPS module. 35 | 36 | long lastTime = 0; //Simple local timer. Limits amount of I2C traffic to Ublox module. 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println("SparkFun Ublox Example"); 43 | 44 | //Assume that the U-Blox GPS is running at 9600 baud (the default) or at 38400 baud. 45 | //Loop until we're in sync and then ensure it's at 38400 baud. 46 | do { 47 | Serial.println("GPS: trying 38400 baud"); 48 | mySerial.begin(38400); 49 | if (myGPS.begin(mySerial) == true) break; 50 | 51 | delay(100); 52 | Serial.println("GPS: trying 9600 baud"); 53 | mySerial.begin(9600); 54 | if (myGPS.begin(mySerial) == true) { 55 | Serial.println("GPS: connected at 9600 baud, switching to 38400"); 56 | myGPS.setSerialRate(38400); 57 | delay(100); 58 | } else { 59 | //myGPS.factoryReset(); 60 | delay(2000); //Wait a bit before trying again to limit the Serial output 61 | } 62 | } while(1); 63 | Serial.println("GPS serial connected"); 64 | 65 | myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only 66 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 67 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 68 | } 69 | 70 | void loop() 71 | { 72 | //Query module only every second. Doing it more often will just cause I2C traffic. 73 | //The module only responds when a new position is available 74 | if (millis() - lastTime > 1000) 75 | { 76 | lastTime = millis(); //Update the timer 77 | 78 | long latitude = myGPS.getLatitude(); 79 | Serial.print(F("Lat: ")); 80 | Serial.print(latitude); 81 | 82 | long longitude = myGPS.getLongitude(); 83 | Serial.print(F(" Long: ")); 84 | Serial.print(longitude); 85 | Serial.print(F(" (degrees * 10^-7)")); 86 | 87 | long altitude = myGPS.getAltitude(); 88 | Serial.print(F(" Alt: ")); 89 | Serial.print(altitude); 90 | Serial.print(F(" (mm)")); 91 | 92 | byte SIV = myGPS.getSIV(); 93 | Serial.print(F(" SIV: ")); 94 | Serial.print(SIV); 95 | 96 | Serial.println(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /examples/Example13_PVT/Example1_AutoPVT/Example1_AutoPVT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Configuring the GPS to automatically send position reports over I2C 3 | By: Nathan Seidle and Thorsten von Eicken 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 //Needed for I2C to GPS 30 | 31 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 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 | // Start the reading only when valid LLH is available 58 | if (myGPS.getPVT() && (myGPS.getInvalidLlh() == false)) 59 | { 60 | Serial.println(); 61 | long latitude = myGPS.getLatitude(); 62 | Serial.print(F("Lat: ")); 63 | Serial.print(latitude); 64 | 65 | long longitude = myGPS.getLongitude(); 66 | Serial.print(F(" Long: ")); 67 | Serial.print(longitude); 68 | Serial.print(F(" (degrees * 10^-7)")); 69 | 70 | long altitude = myGPS.getAltitude(); 71 | Serial.print(F(" Alt: ")); 72 | Serial.print(altitude); 73 | Serial.print(F(" (mm)")); 74 | 75 | byte SIV = myGPS.getSIV(); 76 | Serial.print(F(" SIV: ")); 77 | Serial.print(SIV); 78 | 79 | int PDOP = myGPS.getPDOP(); 80 | Serial.print(F(" PDOP: ")); 81 | Serial.print(PDOP); 82 | Serial.print(F(" (10^-2)")); 83 | 84 | int nedNorthVel = myGPS.getNedNorthVel(); 85 | Serial.print(F(" VelN: ")); 86 | Serial.print(nedNorthVel); 87 | Serial.print(F(" (mm/s)")); 88 | 89 | int nedEastVel = myGPS.getNedEastVel(); 90 | Serial.print(F(" VelE: ")); 91 | Serial.print(nedEastVel); 92 | Serial.print(F(" (mm/s)")); 93 | 94 | int nedDownVel = myGPS.getNedDownVel(); 95 | Serial.print(F(" VelD: ")); 96 | Serial.print(nedDownVel); 97 | Serial.print(F(" (mm/s)")); 98 | 99 | int verticalAccEst = myGPS.getVerticalAccEst(); 100 | Serial.print(F(" VAccEst: ")); 101 | Serial.print(verticalAccEst); 102 | Serial.print(F(" (mm)")); 103 | 104 | int horizontalAccEst = myGPS.getHorizontalAccEst(); 105 | Serial.print(F(" HAccEst: ")); 106 | Serial.print(horizontalAccEst); 107 | Serial.print(F(" (mm)")); 108 | 109 | int speedAccEst = myGPS.getSpeedAccEst(); 110 | Serial.print(F(" SpeedAccEst: ")); 111 | Serial.print(speedAccEst); 112 | Serial.print(F(" (mm/s)")); 113 | 114 | int headAccEst = myGPS.getHeadingAccEst(); 115 | Serial.print(F(" HeadAccEst: ")); 116 | Serial.print(headAccEst); 117 | Serial.print(F(" (degrees * 10^-5)")); 118 | 119 | if (myGPS.getHeadVehValid() == true) { 120 | int headVeh = myGPS.getHeadVeh(); 121 | Serial.print(F(" HeadVeh: ")); 122 | Serial.print(headVeh); 123 | Serial.print(F(" (degrees * 10^-5)")); 124 | 125 | int magDec = myGPS.getMagDec(); 126 | Serial.print(F(" MagDec: ")); 127 | Serial.print(magDec); 128 | Serial.print(F(" (degrees * 10^-2)")); 129 | 130 | int magAcc = myGPS.getMagAcc(); 131 | Serial.print(F(" MagAcc: ")); 132 | Serial.print(magAcc); 133 | Serial.print(F(" (degrees * 10^-2)")); 134 | } 135 | 136 | Serial.println(); 137 | } else { 138 | Serial.print("."); 139 | delay(50); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /examples/Example13_PVT/Example2_AutoPVT_ExplicitUpdate/Example2_AutoPVT_ExplicitUpdate.ino: -------------------------------------------------------------------------------- 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 //Needed for I2C to GPS 31 | 32 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | void setup() 36 | { 37 | Serial.begin(115200); 38 | while (!Serial) 39 | ; //Wait for user to open terminal 40 | Serial.println("SparkFun Ublox Example"); 41 | 42 | Wire.begin(); 43 | 44 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 45 | { 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 47 | while (1) 48 | ; 49 | } 50 | 51 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 52 | myGPS.setNavigationFrequency(2); //Produce two solutions per second 53 | myGPS.setAutoPVT(true, false); //Tell the GPS to "send" each solution and the lib not to update stale data implicitly 54 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 55 | } 56 | 57 | /* 58 | Calling getPVT would return false now (compare to previous example where it would return true), so we just use the data provided 59 | 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 60 | 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. 61 | Also you could oversample (10Hz - 20Hz) the data to smooth out such issues... 62 | */ 63 | void loop() 64 | { 65 | static uint16_t counter = 0; 66 | 67 | if (counter % 10 == 0) 68 | { 69 | // update your AHRS filter here for a ~100Hz update rate 70 | // GPS data will be quasi static but data from your IMU will be changing 71 | } 72 | // debug output each half second 73 | if (counter % 500 == 0) 74 | { 75 | Serial.println(); 76 | long latitude = myGPS.getLatitude(); 77 | Serial.print(F("Lat: ")); 78 | Serial.print(latitude); 79 | 80 | long longitude = myGPS.getLongitude(); 81 | Serial.print(F(" Long: ")); 82 | Serial.print(longitude); 83 | Serial.print(F(" (degrees * 10^-7)")); 84 | 85 | long altitude = myGPS.getAltitude(); 86 | Serial.print(F(" Alt: ")); 87 | Serial.print(altitude); 88 | Serial.print(F(" (mm)")); 89 | 90 | byte SIV = myGPS.getSIV(); 91 | Serial.print(F(" SIV: ")); 92 | Serial.print(SIV); 93 | 94 | Serial.println(); 95 | } 96 | // call checkUblox all 50ms to capture the gps data 97 | if (counter % 50 == 0) 98 | { 99 | myGPS.checkUblox(); 100 | } 101 | delay(1); 102 | counter++; 103 | } 104 | -------------------------------------------------------------------------------- /examples/Example13_PVT/Example3_AssumeAutoPVTviaUart/Example3_AssumeAutoPVTviaUart.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading lat and long via UBX binary commands using an RX-only UART 3 | By: Nathan Seidle, Adapted from Example11 by Felix Jirka 4 | SparkFun Electronics 5 | Date: July 2nd, 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 library for serial port use with a single wire connection using the assumeAutoPVT method. 10 | Saving your pins for other stuff :-) 11 | 12 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 | Preconditions: 21 | U-Blox module is configured to send cyclical PVT message 22 | Hardware Connections: 23 | Connect the U-Blox serial TX pin to Rx of Serial2 (default: GPIO16) on your ESP32 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | while (!Serial); //Wait for user to open terminal 34 | Serial.println("SparkFun Ublox Example 17"); 35 | 36 | //Use any Serial port with at least a Rx Pin connected or a receive only version of SoftwareSerial here 37 | //Assume that the U-Blox GPS is running at 9600 baud (the default) 38 | Serial2.begin(9600); 39 | // no need to check return value as internal call to isConnected() will not succeed 40 | myGPS.begin(Serial2); 41 | 42 | // tell lib, we are expecting the module to send PVT messages by itself to our Rx pin 43 | // you can set second parameter to "false" if you want to control the parsing and eviction of the data (need to call checkUblox cyclically) 44 | myGPS.assumeAutoPVT(true, true); 45 | 46 | } 47 | 48 | void loop() 49 | { 50 | // if implicit updates are allowed, this will trigger parsing the incoming messages 51 | // and be true once a PVT message has been parsed 52 | // In case you want to use explicit updates, wrap this in a timer and call checkUblox as often as needed, not to overflow your UART buffers 53 | if (myGPS.getPVT()) 54 | { 55 | long latitude = myGPS.getLatitude(); 56 | Serial.print(F("Lat: ")); 57 | Serial.print(latitude); 58 | 59 | long longitude = myGPS.getLongitude(); 60 | Serial.print(F(" Long: ")); 61 | Serial.print(longitude); 62 | Serial.print(F(" (degrees * 10^-7)")); 63 | 64 | long altitude = myGPS.getAltitude(); 65 | Serial.print(F(" Alt: ")); 66 | Serial.print(altitude); 67 | Serial.print(F(" (mm)")); 68 | 69 | byte SIV = myGPS.getSIV(); 70 | Serial.print(F(" SIV: ")); 71 | Serial.print(SIV); 72 | 73 | Serial.println(); 74 | } 75 | else { 76 | Serial.println(F("Wait for GPS data")); 77 | delay(500); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /examples/Example14_DebugOutput/Example14_DebugOutput.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading lat and long via UBX binary commands using UART @38400 baud - free from I2C 3 | By: Nathan Seidle, Adapted from Example3_GetPosition by Thorsten von Eicken 4 | SparkFun Electronics 5 | Date: January 28rd, 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 debug output from the library. 10 | Debug shows various packet and status outputs. These prints can be directed 11 | towards Serial (as in Serial.print) or any other port (Serial1, SerialUSB, etc). 12 | 13 | Feel like supporting open source hardware? 14 | Buy a board from SparkFun! 15 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 16 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 17 | SAM-M8Q: https://www.sparkfun.com/products/15106 18 | 19 | Hardware Connections: 20 | Connect the U-Blox serial TX pin to Uno pin 10 21 | Connect the U-Blox serial RX pin to Uno pin 11 22 | Open the serial monitor at 115200 baud to see the output 23 | */ 24 | 25 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 26 | SFE_UBLOX_GPS myGPS; 27 | 28 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | while (!Serial); //Wait for user to open terminal 34 | Serial.println("SparkFun Ublox Example"); 35 | 36 | Wire.begin(); 37 | 38 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 39 | { 40 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 41 | while (1); 42 | } 43 | 44 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 45 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 46 | 47 | myGPS.enableDebugging(); //Enable debug messages over Serial (default) 48 | //myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB 49 | 50 | } 51 | 52 | void loop() 53 | { 54 | //Query module only every second. Doing it more often will just cause I2C traffic. 55 | //The module only responds when a new position is available 56 | if (millis() - lastTime > 1000) 57 | { 58 | lastTime = millis(); //Update the timer 59 | 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 | Serial.print(myGPS.getYear()); 80 | Serial.print("-"); 81 | Serial.print(myGPS.getMonth()); 82 | Serial.print("-"); 83 | Serial.print(myGPS.getDay()); 84 | Serial.print(" "); 85 | Serial.print(myGPS.getHour()); 86 | Serial.print(":"); 87 | Serial.print(myGPS.getMinute()); 88 | Serial.print(":"); 89 | Serial.println(myGPS.getSecond()); 90 | 91 | Serial.println(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/Example15_GetDateTime/Example15_GetDateTime.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Getting time and date using Ublox commands 3 | By: davidallenmann 4 | SparkFun Electronics 5 | Date: April 16th, 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 query a Ublox module for the current time and date. We also 10 | turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic 11 | dramatically. 12 | 13 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 33 | 34 | void setup() 35 | { 36 | Serial.begin(115200); 37 | while (!Serial) 38 | ; //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 | 50 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 51 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 52 | } 53 | 54 | void loop() 55 | { 56 | //Query module only every second. Doing it more often will just cause I2C traffic. 57 | //The module only responds when a new position is available 58 | if (millis() - lastTime > 1000) 59 | { 60 | lastTime = millis(); //Update the timer 61 | 62 | long latitude = myGPS.getLatitude(); 63 | Serial.print(F("Lat: ")); 64 | Serial.print(latitude); 65 | 66 | long longitude = myGPS.getLongitude(); 67 | Serial.print(F(" Long: ")); 68 | Serial.print(longitude); 69 | Serial.print(F(" (degrees * 10^-7)")); 70 | 71 | long altitude = myGPS.getAltitude(); 72 | Serial.print(F(" Alt: ")); 73 | Serial.print(altitude); 74 | Serial.print(F(" (mm)")); 75 | 76 | byte SIV = myGPS.getSIV(); 77 | Serial.print(F(" SIV: ")); 78 | Serial.print(SIV); 79 | 80 | Serial.println(); 81 | Serial.print(myGPS.getYear()); 82 | Serial.print("-"); 83 | Serial.print(myGPS.getMonth()); 84 | Serial.print("-"); 85 | Serial.print(myGPS.getDay()); 86 | Serial.print(" "); 87 | Serial.print(myGPS.getHour()); 88 | Serial.print(":"); 89 | Serial.print(myGPS.getMinute()); 90 | Serial.print(":"); 91 | Serial.print(myGPS.getSecond()); 92 | 93 | Serial.print(" Time is "); 94 | if (myGPS.getTimeValid() == false) 95 | { 96 | Serial.print("not "); 97 | } 98 | Serial.print("valid Date is "); 99 | if (myGPS.getDateValid() == false) 100 | { 101 | Serial.print("not "); 102 | } 103 | Serial.print("valid"); 104 | 105 | Serial.println(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/Example16_Nanosecond_MaxOutput/Example16_Nanosecond_MaxOutput.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Getting time and date using Ublox commands 3 | By: davidallenmann 4 | SparkFun Electronics 5 | Date: April 16th, 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 query a Ublox module for the current time and date. We also 10 | turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic 11 | dramatically. 12 | 13 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 33 | 34 | void setup() 35 | { 36 | Serial.begin(500000); //Increase serial speed to maximize 37 | while (!Serial) 38 | ; //Wait for user to open terminal 39 | Serial.println("SparkFun Ublox Example"); 40 | 41 | Wire.begin(); 42 | Wire.setClock(400000); 43 | 44 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 45 | { 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 47 | while (1) 48 | ; 49 | } 50 | 51 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 52 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 53 | 54 | //myGPS.enableDebugging(); //Enable debug messages over Serial (default) 55 | 56 | myGPS.setNavigationFrequency(10); //Set output to 10 times a second 57 | byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module 58 | Serial.print("Current update rate:"); 59 | Serial.println(rate); 60 | } 61 | 62 | void loop() 63 | { 64 | // Calling getPVT returns true if there actually is a fresh navigation solution available. 65 | if (myGPS.getPVT()) 66 | { 67 | lastTime = millis(); //Update the timer 68 | 69 | long latitude = myGPS.getLatitude(); 70 | Serial.print(F("Lat: ")); 71 | Serial.print(latitude); 72 | 73 | long longitude = myGPS.getLongitude(); 74 | Serial.print(F(" Long: ")); 75 | Serial.print(longitude); 76 | Serial.print(F(" (degrees * 10^-7)")); 77 | 78 | long altitude = myGPS.getAltitude(); 79 | Serial.print(F(" Alt: ")); 80 | Serial.print(altitude); 81 | Serial.print(F(" (mm)")); 82 | 83 | byte SIV = myGPS.getSIV(); 84 | Serial.print(F(" SIV: ")); 85 | Serial.print(SIV); 86 | 87 | Serial.print(" "); 88 | Serial.print(myGPS.getYear()); 89 | Serial.print("-"); 90 | Serial.print(myGPS.getMonth()); 91 | Serial.print("-"); 92 | Serial.print(myGPS.getDay()); 93 | Serial.print(" "); 94 | Serial.print(myGPS.getHour()); 95 | Serial.print(":"); 96 | Serial.print(myGPS.getMinute()); 97 | Serial.print(":"); 98 | Serial.print(myGPS.getSecond()); 99 | Serial.print("."); 100 | Serial.print(myGPS.getNanosecond()); 101 | 102 | myGPS.flushPVT(); 103 | 104 | Serial.println(); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /examples/Example16_PartialSecond_MaxOutput/Example16_PartialSecond_MaxOutput.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Getting time and date using Ublox commands 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: April 16th, 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 use the Millisecond and Nanosecond output as well as increase the 10 | I2C speed (100 to 400kHz), and serial output (115200 to 500kbps). 11 | 12 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 GPS 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 //Needed for I2C to GPS 27 | 28 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 29 | SFE_UBLOX_GPS myGPS; 30 | 31 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 32 | 33 | void setup() 34 | { 35 | Serial.begin(500000); //Increase serial speed to maximize 36 | while (!Serial) 37 | ; //Wait for user to open terminal 38 | Serial.println("SparkFun Ublox Example"); 39 | 40 | Wire.begin(); 41 | Wire.setClock(400000); 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 | 50 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 51 | 52 | //myGPS.enableDebugging(); //Enable debug messages over Serial (default) 53 | 54 | myGPS.setNavigationFrequency(10); //Set output to 10 times a second 55 | byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module 56 | Serial.print("Current update rate:"); 57 | Serial.println(rate); 58 | 59 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 60 | 61 | pinMode(2, OUTPUT); //For debug capture 62 | digitalWrite(2, HIGH); 63 | } 64 | 65 | void loop() 66 | { 67 | // Calling getPVT returns true if there actually is a fresh navigation solution available. 68 | if (myGPS.getPVT()) 69 | { 70 | lastTime = millis(); //Update the timer 71 | 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.print(" "); 91 | Serial.print(myGPS.getYear()); 92 | Serial.print("-"); 93 | Serial.print(myGPS.getMonth()); 94 | Serial.print("-"); 95 | Serial.print(myGPS.getDay()); 96 | Serial.print(" "); 97 | Serial.print(myGPS.getHour()); 98 | Serial.print(":"); 99 | Serial.print(myGPS.getMinute()); 100 | Serial.print(":"); 101 | Serial.print(myGPS.getSecond()); 102 | Serial.print("."); 103 | //Pretty print leading zeros 104 | int mseconds = myGPS.getMillisecond(); 105 | if (mseconds < 100) 106 | Serial.print("0"); 107 | if (mseconds < 10) 108 | Serial.print("0"); 109 | Serial.print(mseconds); 110 | 111 | Serial.print(" nanoSeconds: "); 112 | Serial.print(myGPS.getNanosecond()); 113 | 114 | Serial.println(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /examples/Example17_Geofence/Example17_Geofence.ino: -------------------------------------------------------------------------------- 1 | /* 2 | u-blox M8 geofence example 3 | 4 | Written by Paul Clark (PaulZC) 5 | 10th December 2019 6 | 7 | License: MIT. See license file for more information but you can 8 | basically do whatever you want with this code. 9 | 10 | This example demonstrates how to use the addGeofence and getGeofenceState functions 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 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 16 | SAM-M8Q: https://www.sparkfun.com/products/15210 17 | ZOE-M8Q: https://www.sparkfun.com/products/15193 18 | 19 | This example powers up the GPS and reads the fix. 20 | Once a valid 3D fix has been found, the code reads the latitude and longitude. 21 | The code then sets four geofences around that position with a radii of 5m, 10m, 15m and 20m with 95% confidence. 22 | The code then monitors the geofence status. 23 | The LED will be illuminated if you are inside the _combined_ geofence (i.e. within the 20m radius). 24 | 25 | This code has been tested on the ZOE-M8Q. 26 | */ 27 | 28 | #define LED LED_BUILTIN // Change this if your LED is on a different pin 29 | 30 | #include // Needed for I2C 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | void setup() 36 | { 37 | pinMode(LED, OUTPUT); 38 | 39 | // Set up the I2C pins 40 | Wire.begin(); 41 | 42 | // Start the console serial port 43 | Serial.begin(115200); 44 | while (!Serial); // Wait for the user to open the serial monitor 45 | delay(100); 46 | Serial.println(); 47 | Serial.println(); 48 | Serial.println(F("u-blox M8 geofence example")); 49 | Serial.println(); 50 | Serial.println(); 51 | 52 | delay(1000); // Let the GPS power up 53 | 54 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 55 | { 56 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 57 | while (1); 58 | } 59 | 60 | //myGPS.enableDebugging(); // Enable debug messages 61 | myGPS.setI2COutput(COM_TYPE_UBX); // Limit I2C output to UBX (disable the NMEA noise) 62 | 63 | Serial.println(F("Waiting for a 3D fix...")); 64 | 65 | byte fixType = 0; 66 | 67 | while (fixType < 3) 68 | { 69 | fixType = myGPS.getFixType(); // Get the fix type 70 | Serial.print(F("Fix: ")); // Print it 71 | Serial.print(fixType); 72 | if(fixType == 0) Serial.print(F(" = No fix")); 73 | else if(fixType == 1) Serial.print(F(" = Dead reckoning")); 74 | else if(fixType == 2) Serial.print(F(" = 2D")); 75 | else if(fixType == 3) Serial.print(F(" = 3D")); 76 | else if(fixType == 4) Serial.print(F(" = GNSS + Dead reckoning")); 77 | else if(fixType == 5) Serial.print(F(" = Time only")); 78 | Serial.println(); 79 | delay(1000); 80 | } 81 | 82 | Serial.println(F("3D fix found!")); 83 | 84 | long latitude = myGPS.getLatitude(); // Get the latitude in degrees * 10^-7 85 | Serial.print(F("Lat: ")); 86 | Serial.print(latitude); 87 | 88 | long longitude = myGPS.getLongitude(); // Get the longitude in degrees * 10^-7 89 | Serial.print(F(" Long: ")); 90 | Serial.println(longitude); 91 | 92 | uint32_t radius = 500; // Set the radius to 5m (radius is in m * 10^-2 i.e. cm) 93 | 94 | byte confidence = 2; // Set the confidence level: 0=none, 1=68%, 2=95%, 3=99.7%, 4=99.99% 95 | 96 | // Call clearGeofences() to clear all existing geofences. 97 | Serial.print(F("Clearing any existing geofences. clearGeofences returned: ")); 98 | Serial.println(myGPS.clearGeofences()); 99 | 100 | // It is possible to define up to four geofences. 101 | // Call addGeofence up to four times to define them. 102 | Serial.println(F("Setting the geofences:")); 103 | 104 | Serial.print(F("addGeofence for geofence 1 returned: ")); 105 | Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence)); 106 | 107 | radius = 1000; // 10m 108 | Serial.print(F("addGeofence for geofence 2 returned: ")); 109 | Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence)); 110 | 111 | radius = 1500; // 15m 112 | Serial.print(F("addGeofence for geofence 3 returned: ")); 113 | Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence)); 114 | 115 | radius = 2000; // 20m 116 | Serial.print(F("addGeofence for geofence 4 returned: ")); 117 | Serial.println(myGPS.addGeofence(latitude, longitude, radius, confidence)); 118 | } 119 | 120 | void loop() 121 | { 122 | geofenceState currentGeofenceState; // Create storage for the geofence state 123 | 124 | boolean result = myGPS.getGeofenceState(currentGeofenceState); 125 | 126 | Serial.print(F("getGeofenceState returned: ")); // Print the combined state 127 | Serial.print(result); // Get the geofence state 128 | 129 | if (!result) // If getGeofenceState did not return true 130 | { 131 | Serial.println(F(".")); // Tidy up 132 | return; // and go round the loop again 133 | } 134 | 135 | Serial.print(F(". status is: ")); // Print the status 136 | Serial.print(currentGeofenceState.status); 137 | 138 | Serial.print(F(". numFences is: ")); // Print the numFences 139 | Serial.print(currentGeofenceState.numFences); 140 | 141 | Serial.print(F(". combState is: ")); // Print the combined state 142 | Serial.print(currentGeofenceState.combState); 143 | 144 | if (currentGeofenceState.combState == 0) 145 | { 146 | Serial.print(F(" = Unknown")); 147 | digitalWrite(LED, LOW); 148 | } 149 | if (currentGeofenceState.combState == 1) 150 | { 151 | Serial.print(F(" = Inside")); 152 | digitalWrite(LED, HIGH); 153 | } 154 | else if (currentGeofenceState.combState == 2) 155 | { 156 | Serial.print(F(" = Outside")); 157 | digitalWrite(LED, LOW); 158 | } 159 | 160 | Serial.print(F(". The individual states are: ")); // Print the state of each geofence 161 | for(int i = 0; i < currentGeofenceState.numFences; i++) 162 | { 163 | if (i > 0) Serial.print(F(",")); 164 | Serial.print(currentGeofenceState.states[i]); 165 | } 166 | Serial.println(); 167 | 168 | delay(1000); 169 | } 170 | -------------------------------------------------------------------------------- /examples/Example18_PowerSaveMode/Example18_PowerSaveMode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Power Save Mode 3 | By: Paul Clark (PaulZC) 4 | Date: April 22nd, 2020 5 | 6 | Based extensively on Example3_GetPosition 7 | By: Nathan Seidle 8 | SparkFun Electronics 9 | Date: January 3rd, 2019 10 | License: MIT. See license file for more information but you can 11 | basically do whatever you want with this code. 12 | 13 | This example shows how to put the Ublox module into power save mode and then 14 | query its lat/long/altitude. We also turn off the NMEA output on the I2C port. 15 | This decreases the amount of I2C traffic dramatically. 16 | 17 | ** When it is able to ** the module will reduce its current draw. 18 | For the ZOE-M8Q with a passive antenna, you should see the current drop 19 | from (approx.) 25-28mA to (approx.) 9mA when power save mode kicks in. 20 | 21 | Note: this will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported 22 | 23 | Note: Long/lat are large numbers because they are * 10^7. To convert lat/long 24 | to something google maps understands simply divide the numbers by 10,000,000. We 25 | do this so that we don't have to use floating point numbers. 26 | 27 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 28 | 29 | Feel like supporting open source hardware? 30 | Buy a board from SparkFun! 31 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 32 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 33 | SAM-M8Q: https://www.sparkfun.com/products/15106 34 | 35 | Hardware Connections: 36 | Plug a Qwiic cable into the GPS and a BlackBoard 37 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 38 | Open the serial monitor at 115200 baud to see the output 39 | */ 40 | 41 | #include //Needed for I2C to GPS 42 | 43 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 44 | SFE_UBLOX_GPS myGPS; 45 | 46 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 47 | 48 | void setup() 49 | { 50 | Serial.begin(115200); 51 | while (!Serial) 52 | ; //Wait for user to open terminal 53 | Serial.println("SparkFun Ublox Example"); 54 | 55 | Wire.begin(); 56 | 57 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 58 | { 59 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 60 | while (1) 61 | ; 62 | } 63 | 64 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages 65 | 66 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 67 | //myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR 68 | 69 | Serial.println("Power save example."); 70 | Serial.println("1) Enable power saving"); 71 | Serial.println("2) Disable power saving"); 72 | } 73 | 74 | void loop() 75 | { 76 | if (Serial.available()) 77 | { 78 | byte incoming = Serial.read(); 79 | 80 | if (incoming == '1') 81 | { 82 | // Put the GNSS into power save mode 83 | // (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead) 84 | // This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported 85 | if (myGPS.powerSaveMode()) // Defaults to true 86 | Serial.println(F("Power Save Mode enabled.")); 87 | else 88 | Serial.println(F("***!!! Power Save Mode FAILED !!!***")); 89 | } 90 | else if (incoming == '2') 91 | { 92 | //Go to normal power mode (not power saving mode) 93 | if (myGPS.powerSaveMode(false)) 94 | Serial.println(F("Power Save Mode disabled.")); 95 | else 96 | Serial.println(F("***!!! Power Save Disable FAILED !!!***")); 97 | } 98 | 99 | // Read and print the new low power mode 100 | uint8_t lowPowerMode = myGPS.getPowerSaveMode(); 101 | if (lowPowerMode == 255) 102 | { 103 | Serial.println(F("***!!! getPowerSaveMode FAILED !!!***")); 104 | } 105 | else 106 | { 107 | Serial.print(F("The low power mode is: ")); 108 | Serial.print(lowPowerMode); 109 | if (lowPowerMode == 0) 110 | { 111 | Serial.println(F(" (Continuous)")); 112 | } 113 | else if (lowPowerMode == 1) 114 | { 115 | Serial.println(F(" (Power Save)")); 116 | } 117 | else if (lowPowerMode == 4) 118 | { 119 | Serial.println(F(" (Continuous)")); 120 | } 121 | else 122 | { 123 | Serial.println(F(" (Unknown!)")); 124 | } 125 | } 126 | } 127 | 128 | //Query module every 10 seconds so it is easier to monitor the current draw 129 | if (millis() - lastTime > 10000) 130 | { 131 | lastTime = millis(); //Update the timer 132 | 133 | byte fixType = myGPS.getFixType(); // Get the fix type 134 | Serial.print(F("Fix: ")); 135 | Serial.print(fixType); 136 | if (fixType == 0) 137 | Serial.print(F("(No fix)")); 138 | else if (fixType == 1) 139 | Serial.print(F("(Dead reckoning)")); 140 | else if (fixType == 2) 141 | Serial.print(F("(2D)")); 142 | else if (fixType == 3) 143 | Serial.print(F("(3D)")); 144 | else if (fixType == 4) 145 | Serial.print(F("(GNSS + Dead reckoning)")); 146 | 147 | long latitude = myGPS.getLatitude(); 148 | Serial.print(F(" Lat: ")); 149 | Serial.print(latitude); 150 | 151 | long longitude = myGPS.getLongitude(); 152 | Serial.print(F(" Long: ")); 153 | Serial.print(longitude); 154 | Serial.print(F(" (degrees * 10^-7)")); 155 | 156 | long altitude = myGPS.getAltitude(); 157 | Serial.print(F(" Alt: ")); 158 | Serial.print(altitude); 159 | Serial.print(F(" (mm)")); 160 | 161 | Serial.println(); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /examples/Example19_DynamicModel/Example19_DynamicModel.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Set Dynamic Model 3 | By: Paul Clark (PaulZC) 4 | Date: April 22nd, 2020 5 | 6 | Based extensively on Example3_GetPosition 7 | By: Nathan Seidle 8 | SparkFun Electronics 9 | Date: January 3rd, 2019 10 | License: MIT. See license file for more information but you can 11 | basically do whatever you want with this code. 12 | 13 | This example shows how to change the Ublox module's dynamic platform model and then 14 | query its lat/long/altitude. We also turn off the NMEA output on the I2C port. 15 | This decreases the amount of I2C traffic dramatically. 16 | 17 | Possible values for the dynamic model are: PORTABLE, STATIONARY, PEDESTRIAN, AUTOMOTIVE, 18 | SEA, AIRBORNE1g, AIRBORNE2g, AIRBORNE4g, WRIST, BIKE 19 | 20 | Note: Long/lat are large numbers because they are * 10^7. To convert lat/long 21 | to something google maps understands simply divide the numbers by 10,000,000. We 22 | do this so that we don't have to use floating point numbers. 23 | 24 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 25 | 26 | Feel like supporting open source hardware? 27 | Buy a board from SparkFun! 28 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 29 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 30 | SAM-M8Q: https://www.sparkfun.com/products/15106 31 | 32 | Hardware Connections: 33 | Plug a Qwiic cable into the GPS and a BlackBoard 34 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 35 | Open the serial monitor at 115200 baud to see the output 36 | */ 37 | 38 | #include //Needed for I2C to GPS 39 | 40 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 41 | SFE_UBLOX_GPS myGPS; 42 | 43 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 44 | 45 | void setup() 46 | { 47 | Serial.begin(115200); 48 | while (!Serial) 49 | ; //Wait for user to open terminal 50 | Serial.println(F("SparkFun Ublox Example")); 51 | 52 | Wire.begin(); 53 | 54 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages 55 | 56 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 57 | { 58 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 59 | while (1) 60 | ; 61 | } 62 | 63 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 64 | 65 | // If we are going to change the dynamic platform model, let's do it here. 66 | // Possible values are: 67 | // PORTABLE, STATIONARY, PEDESTRIAN, AUTOMOTIVE, SEA, AIRBORNE1g, AIRBORNE2g, AIRBORNE4g, WRIST, BIKE 68 | 69 | if (myGPS.setDynamicModel(DYN_MODEL_PORTABLE) == false) // Set the dynamic model to PORTABLE 70 | { 71 | Serial.println(F("***!!! Warning: setDynamicModel failed !!!***")); 72 | } 73 | else 74 | { 75 | Serial.println(F("Dynamic platform model changed successfully!")); 76 | } 77 | 78 | // Let's read the new dynamic model to see if it worked 79 | uint8_t newDynamicModel = myGPS.getDynamicModel(); 80 | if (newDynamicModel == 255) 81 | { 82 | Serial.println(F("***!!! Warning: getDynamicModel failed !!!***")); 83 | } 84 | else 85 | { 86 | Serial.print(F("The new dynamic model is: ")); 87 | Serial.println(newDynamicModel); 88 | } 89 | 90 | //myGPS.saveConfigSelective(VAL_CFG_SUBSEC_NAVCONF); //Uncomment this line to save only the NAV settings to flash and BBR 91 | } 92 | 93 | void loop() 94 | { 95 | //Query module only every second. Doing it more often will just cause I2C traffic. 96 | //The module only responds when a new position is available 97 | if (millis() - lastTime > 1000) 98 | { 99 | lastTime = millis(); //Update the timer 100 | 101 | long latitude = myGPS.getLatitude(); 102 | Serial.print(F("Lat: ")); 103 | Serial.print(latitude); 104 | 105 | long longitude = myGPS.getLongitude(); 106 | Serial.print(F(" Long: ")); 107 | Serial.print(longitude); 108 | Serial.print(F(" (degrees * 10^-7)")); 109 | 110 | long altitude = myGPS.getAltitude(); 111 | Serial.print(F(" Alt: ")); 112 | Serial.print(altitude); 113 | Serial.print(F(" (mm)")); 114 | 115 | Serial.println(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /examples/Example1_BasicNMEARead/Example1_BasicNMEARead.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read NMEA sentences over I2C using Ublox module SAM-M8Q, NEO-M8P, ZED-F9P, etc 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: August 22nd, 2018 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 reads the NMEA setences from the Ublox module over I2c and outputs 10 | them to the serial port 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 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 16 | SAM-M8Q: https://www.sparkfun.com/products/15106 17 | 18 | Hardware Connections: 19 | Plug a Qwiic cable into the GPS and a BlackBoard 20 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 21 | Open the serial monitor at 115200 baud to see the output 22 | */ 23 | 24 | #include //Needed for I2C to GPS 25 | 26 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 27 | SFE_UBLOX_GPS myGPS; 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | Serial.println("SparkFun Ublox Example"); 33 | 34 | Wire.begin(); 35 | 36 | if (myGPS.begin() == false) 37 | { 38 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 39 | while (1); 40 | } 41 | 42 | //This will pipe all NMEA sentences to the serial port so we can see them 43 | myGPS.setNMEAOutputPort(Serial); 44 | } 45 | 46 | void loop() 47 | { 48 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 49 | 50 | delay(250); //Don't pound too hard on the I2C bus 51 | } 52 | -------------------------------------------------------------------------------- /examples/Example20_SendCustomCommand/Example20_SendCustomCommand.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send Custom Command 3 | By: Paul Clark (PaulZC) 4 | Date: April 20th, 2020 5 | 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 you can create and send a custom UBX packet 10 | using the SparkFun u-blox library. 11 | 12 | Previously it was possible to create and send a custom packet 13 | through the library but it would always appear to timeout as 14 | some of the internal functions referred to the internal private 15 | struct packetCfg. 16 | The most recent version of the library allows sendCommand to 17 | use a custom packet as if it were packetCfg and so: 18 | - sendCommand will return a sfe_ublox_status_e enum as if 19 | it had been called from within the library 20 | - the custom packet will be updated with data returned by the module 21 | (previously this was not possible from outside the library) 22 | 23 | Feel like supporting open source hardware? 24 | Buy a board from SparkFun! 25 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 26 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 27 | SAM-M8Q: https://www.sparkfun.com/products/15106 28 | 29 | Hardware Connections: 30 | Plug a Qwiic cable into the GPS and a BlackBoard 31 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 32 | Open the serial monitor at 115200 baud to see the output 33 | */ 34 | 35 | #define NAV_RATE 20 // The new navigation rate in Hz (measurements per second) 36 | 37 | #include //Needed for I2C to GPS 38 | 39 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 40 | SFE_UBLOX_GPS myGPS; 41 | 42 | void setup() 43 | { 44 | Serial.begin(115200); // You may need to increase this for high navigation rates! 45 | while (!Serial) 46 | ; //Wait for user to open terminal 47 | Serial.println("SparkFun Ublox Example"); 48 | 49 | Wire.begin(); 50 | 51 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages 52 | 53 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 54 | { 55 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 56 | while (1) 57 | ; 58 | } 59 | 60 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 61 | 62 | // Let's configure the module's navigation rate as if we were using setNavigationFrequency 63 | 64 | // Let's create our custom packet 65 | uint8_t customPayload[MAX_PAYLOAD_SIZE]; // This array holds the payload data bytes 66 | // The next line creates and initialises the packet information which wraps around the payload 67 | ubxPacket customCfg = {0, 0, 0, 0, 0, customPayload, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED}; 68 | 69 | // The structure of ubxPacket is: 70 | // uint8_t cls : The message Class 71 | // uint8_t id : The message ID 72 | // uint16_t len : Length of the payload. Does not include cls, id, or checksum bytes 73 | // uint16_t counter : Keeps track of number of overall bytes received. Some responses are larger than 255 bytes. 74 | // uint16_t startingSpot : The counter value needed to go past before we begin recording into payload array 75 | // uint8_t *payload : The payload 76 | // uint8_t checksumA : Given to us by the module. Checked against the rolling calculated A/B checksums. 77 | // uint8_t checksumB 78 | // sfe_ublox_packet_validity_e valid : Goes from NOT_DEFINED to VALID or NOT_VALID when checksum is checked 79 | // sfe_ublox_packet_validity_e classAndIDmatch : Goes from NOT_DEFINED to VALID or NOT_VALID when the Class and ID match the requestedClass and requestedID 80 | 81 | // sendCommand will return: 82 | // SFE_UBLOX_STATUS_DATA_RECEIVED if the data we requested was read / polled successfully 83 | // SFE_UBLOX_STATUS_DATA_SENT if the data we sent was writted successfully (ACK'd) 84 | // Other values indicate errors. Please see the sfe_ublox_status_e enum for further details. 85 | 86 | // Referring to the u-blox M8 Receiver Description and Protocol Specification we see that 87 | // the navigation rate is configured using the UBX-CFG-RATE message. So let's load our 88 | // custom packet with the correct information so we can read (poll / get) the current settings. 89 | 90 | customCfg.cls = UBX_CLASS_CFG; // This is the message Class 91 | customCfg.id = UBX_CFG_RATE; // This is the message ID 92 | customCfg.len = 0; // Setting the len (length) to zero let's us poll the current settings 93 | customCfg.startingSpot = 0; // Always set the startingSpot to zero (unless you really know what you are doing) 94 | 95 | // We also need to tell sendCommand how long it should wait for a reply 96 | uint16_t maxWait = 250; // Wait for up to 250ms (Serial may need a lot longer e.g. 1100) 97 | 98 | // Now let's read the current navigation rate. The results will be loaded into customCfg. 99 | if (myGPS.sendCommand(&customCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK 100 | { 101 | Serial.println(F("sendCommand (poll / get) failed! Freezing...")); 102 | while (1) 103 | ; 104 | } 105 | 106 | // Referring to the message definition for UBX-CFG-RATE we see that the measurement rate 107 | // is stored in payload bytes 0 and 1 as a uint16_t in LSB-first (little endian) format 108 | 109 | uint16_t rate = (customPayload[1] << 8) | customPayload[0]; // Extract the current rate (ms) 110 | float f_rate = 1000.0 / ((float)rate); // Convert the navigation rate to Hz (measurements per second) 111 | 112 | // Print the current measurement rate 113 | Serial.print(F("The current measurement rate is: ")); 114 | Serial.println(f_rate, 1); 115 | 116 | // Let's change it 117 | rate = 1000 / NAV_RATE; // Load the new value into rate 118 | customPayload[0] = rate & 0xFF; // Store it in the payload 119 | customPayload[1] = rate >> 8; 120 | 121 | // Print the new measurement rate 122 | Serial.print(F("The new measurement rate will be: ")); 123 | Serial.println(NAV_RATE); 124 | 125 | // We don't need to update customCfg.len as it will have been set to 6 126 | // when sendCommand read the data 127 | 128 | // Now we write the custom packet back again to change the setting 129 | if (myGPS.sendCommand(&customCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) // This time we are only expecting an ACK 130 | { 131 | Serial.println(F("sendCommand (set) failed! Freezing.")); 132 | while (1) 133 | ; 134 | } 135 | else 136 | { 137 | Serial.println(F("Navigation rate updated. Here we go...")); 138 | } 139 | 140 | myGPS.setAutoPVT(true); // Enable AutoPVT. The module will generate measurements automatically without being polled. 141 | 142 | //myGPS.saveConfigSelective(VAL_CFG_SUBSEC_NAVCONF); //Uncomment this line to save only the NAV settings to flash and BBR 143 | } 144 | 145 | void loop() 146 | { 147 | //Query the module as fast as possible 148 | int32_t latitude = myGPS.getLatitude(); 149 | Serial.print(F("Lat: ")); 150 | Serial.print(latitude); 151 | 152 | int32_t longitude = myGPS.getLongitude(); 153 | Serial.print(F(" Lon: ")); 154 | Serial.print(longitude); 155 | Serial.print(F(" (degrees * 10^-7)")); 156 | 157 | int32_t altitude = myGPS.getAltitude(); 158 | Serial.print(F(" Alt: ")); 159 | Serial.print(altitude); 160 | Serial.println(F(" (mm)")); 161 | } 162 | -------------------------------------------------------------------------------- /examples/Example22_PowerOff/Example22_PowerOff.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Powering off a ublox GPS module 3 | By: bjorn 4 | unsurv.org 5 | Date: July 20th, 2020 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 you how to turn off the ublox module to lower the power consumption. 10 | There are two functions: one just specifies a duration in milliseconds the other also specifies a pin on the GPS device to wake it up with. 11 | By driving a voltage from LOW to HIGH or HIGH to LOW on the chosen module pin you wake the device back up. 12 | Note: Doing so on the INT0 pin when using the regular powerOff(durationInMs) function will wake the device anyway. (tested on SAM-M8Q) 13 | Note: While powered off, you should not query the device for data or it might wake up. This can be used to wake the device but is not recommended. 14 | Works best when also putting your microcontroller to sleep. 15 | 16 | Feel like supporting open source hardware? 17 | Buy a board from SparkFun! 18 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 19 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 20 | SAM-M8Q: https://www.sparkfun.com/products/15106 21 | 22 | Hardware Connections: 23 | Plug a Qwiic cable into the GPS and a BlackBoard. 24 | To force the device to wake up you need to connect to a pin (for example INT0) seperately on the module. 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 "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | 31 | // define a digital pin capable of driving HIGH and LOW 32 | #define WAKEUP_PIN 5 33 | 34 | // Possible GNSS interrupt pins for powerOffWithInterrupt are: 35 | // VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX = uartrx 36 | // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = extint0 (default) 37 | // VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = extint1 38 | // VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS = spics 39 | // These values can be or'd (|) together to enable interrupts on multiple pins 40 | 41 | void wakeUp() { 42 | 43 | Serial.print("-- waking up module via pin " + String(WAKEUP_PIN)); 44 | Serial.println(" on your microcontroller --"); 45 | 46 | digitalWrite(WAKEUP_PIN, LOW); 47 | delay(1000); 48 | digitalWrite(WAKEUP_PIN, HIGH); 49 | delay(1000); 50 | digitalWrite(WAKEUP_PIN, LOW); 51 | } 52 | 53 | 54 | void setup() { 55 | 56 | pinMode(WAKEUP_PIN, OUTPUT); 57 | digitalWrite(WAKEUP_PIN, LOW); 58 | 59 | Serial.begin(115200); 60 | while (!Serial); //Wait for user to open terminal 61 | Serial.println("SparkFun Ublox Example"); 62 | 63 | Wire.begin(); 64 | 65 | //myGPS.enableDebugging(); // Enable debug messages 66 | 67 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 68 | { 69 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 70 | while (1); 71 | } 72 | 73 | // Powering off for 20s, you should see the power consumption drop. 74 | Serial.println("-- Powering off module for 20s --"); 75 | 76 | myGPS.powerOff(20000); 77 | //myGPS.powerOffWithInterrupt(20000, VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0); 78 | 79 | delay(10000); 80 | 81 | // After 10 seconds wake the device via the specified pin on your microcontroller and module. 82 | wakeUp(); 83 | } 84 | 85 | void loop() { 86 | //Do nothing 87 | } 88 | -------------------------------------------------------------------------------- /examples/Example2_NMEAParsing/Example2_NMEAParsing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read NMEA sentences over I2C using Ublox module SAM-M8Q, NEO-M8P, etc 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: August 22nd, 2018 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 reads the NMEA characters over I2C and pipes them to MicroNMEA 10 | This example will output your current long/lat and satellites in view 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 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 16 | SAM-M8Q: https://www.sparkfun.com/products/15106 17 | 18 | For more MicroNMEA info see https://github.com/stevemarple/MicroNMEA 19 | 20 | Hardware Connections: 21 | Plug a Qwiic cable into the GPS 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 | Go outside! Wait ~25 seconds and you should see your lat/long 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | #include //http://librarymanager/All#MicroNMEA 33 | char nmeaBuffer[100]; 34 | MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); 35 | 36 | void setup() 37 | { 38 | Serial.begin(115200); 39 | Serial.println("SparkFun Ublox Example"); 40 | 41 | Wire.begin(); 42 | 43 | if (myGPS.begin() == false) 44 | { 45 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 46 | while (1); 47 | } 48 | } 49 | 50 | void loop() 51 | { 52 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 53 | 54 | if(nmea.isValid() == true) 55 | { 56 | long latitude_mdeg = nmea.getLatitude(); 57 | long longitude_mdeg = nmea.getLongitude(); 58 | 59 | Serial.print("Latitude (deg): "); 60 | Serial.println(latitude_mdeg / 1000000., 6); 61 | Serial.print("Longitude (deg): "); 62 | Serial.println(longitude_mdeg / 1000000., 6); 63 | } 64 | else 65 | { 66 | Serial.print("No Fix - "); 67 | Serial.print("Num. satellites: "); 68 | Serial.println(nmea.getNumSatellites()); 69 | } 70 | 71 | delay(250); //Don't pound too hard on the I2C bus 72 | } 73 | 74 | //This function gets called from the SparkFun Ublox Arduino Library 75 | //As each NMEA character comes in you can specify what to do with it 76 | //Useful for passing to other libraries like tinyGPS, MicroNMEA, or even 77 | //a buffer, radio, etc. 78 | void SFE_UBLOX_GPS::processNMEA(char incoming) 79 | { 80 | //Take the incoming char from the Ublox I2C port and pass it on to the MicroNMEA lib 81 | //for sentence cracking 82 | nmea.process(incoming); 83 | } 84 | -------------------------------------------------------------------------------- /examples/Example3_GetPosition/Example3_GetPosition.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading lat and long via UBX binary commands - no more NMEA parsing! 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 query a Ublox module for its lat/long/altitude. We also 10 | turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic 11 | dramatically. 12 | 13 | Note: Long/lat are large numbers because they are * 10^7. To convert lat/long 14 | to something google maps understands simply divide the numbers by 10,000,000. We 15 | do this so that we don't have to use floating point numbers. 16 | 17 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 18 | 19 | Feel like supporting open source hardware? 20 | Buy a board from SparkFun! 21 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 22 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 23 | SAM-M8Q: https://www.sparkfun.com/products/15106 24 | 25 | Hardware Connections: 26 | Plug a Qwiic cable into the GPS and a BlackBoard 27 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 28 | Open the serial monitor at 115200 baud to see the output 29 | */ 30 | 31 | #include //Needed for I2C to GPS 32 | 33 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 34 | SFE_UBLOX_GPS myGPS; 35 | 36 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println("SparkFun Ublox Example"); 43 | 44 | Wire.begin(); 45 | 46 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 47 | { 48 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 49 | while (1); 50 | } 51 | 52 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 53 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 54 | } 55 | 56 | void loop() 57 | { 58 | //Query module only every second. Doing it more often will just cause I2C traffic. 59 | //The module only responds when a new position is available 60 | if (millis() - lastTime > 1000) 61 | { 62 | lastTime = millis(); //Update the timer 63 | 64 | long latitude = myGPS.getLatitude(); 65 | Serial.print(F("Lat: ")); 66 | Serial.print(latitude); 67 | 68 | long longitude = myGPS.getLongitude(); 69 | Serial.print(F(" Long: ")); 70 | Serial.print(longitude); 71 | Serial.print(F(" (degrees * 10^-7)")); 72 | 73 | long altitude = myGPS.getAltitude(); 74 | Serial.print(F(" Alt: ")); 75 | Serial.print(altitude); 76 | Serial.print(F(" (mm)")); 77 | 78 | byte SIV = myGPS.getSIV(); 79 | Serial.print(F(" SIV: ")); 80 | Serial.print(SIV); 81 | 82 | Serial.println(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/Example4_FixType/Example4_FixType.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get fix type and RTK fix type if available 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 query a Ublox module for fix type and RTK fix type. 10 | The fix type is as follows: 11 | 0 = no fix 12 | 1 = dead reckoning (requires external sensors) 13 | 2 = 2D (not quite enough satellites in view) 14 | 3 = 3D (the standard fix) 15 | 4 = GNSS + dead reckoning (requires external sensors) 16 | 5 = Time fix only 17 | 18 | Additionally, if we are doing RTK, we can figure out if we have a floating 19 | RTK solution or if we have been able to resolve a fixec solution (better precision). 20 | 21 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 22 | 23 | Feel like supporting open source hardware? 24 | Buy a board from SparkFun! 25 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 26 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 27 | SAM-M8Q: https://www.sparkfun.com/products/15106 28 | 29 | Hardware Connections: 30 | Plug a Qwiic cable into the GPS and a BlackBoard 31 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 32 | Open the serial monitor at 115200 baud to see the output 33 | */ 34 | 35 | #include //Needed for I2C to GPS 36 | 37 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 38 | SFE_UBLOX_GPS myGPS; 39 | 40 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 41 | 42 | void setup() 43 | { 44 | Serial.begin(115200); 45 | while (!Serial); //Wait for user to open terminal 46 | Serial.println("SparkFun Ublox Example"); 47 | 48 | Wire.begin(); 49 | Wire.setClock(400000); //Optional. Increase I2C clock speed to 400kHz. 50 | 51 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 52 | { 53 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 54 | while (1); 55 | } 56 | } 57 | 58 | void loop() 59 | { 60 | //Query module only every second. Doing it more often will just cause I2C traffic. 61 | if (millis() - lastTime > 1000) 62 | { 63 | lastTime = millis(); //Update the timer 64 | 65 | long latitude = myGPS.getLatitude(); 66 | Serial.print(F("Lat: ")); 67 | Serial.print(latitude); 68 | 69 | long longitude = myGPS.getLongitude(); 70 | Serial.print(F(" Long: ")); 71 | Serial.print(longitude); 72 | 73 | long altitude = myGPS.getAltitude(); 74 | Serial.print(F(" Alt: ")); 75 | Serial.print(altitude); 76 | 77 | byte fixType = myGPS.getFixType(); 78 | Serial.print(F(" Fix: ")); 79 | if(fixType == 0) Serial.print(F("No fix")); 80 | else if(fixType == 1) Serial.print(F("Dead reckoning")); 81 | else if(fixType == 2) Serial.print(F("2D")); 82 | else if(fixType == 3) Serial.print(F("3D")); 83 | else if(fixType == 4) Serial.print(F("GNSS+Dead reckoning")); 84 | 85 | byte RTK = myGPS.getCarrierSolutionType(); 86 | Serial.print(" RTK: "); 87 | Serial.print(RTK); 88 | if (RTK == 1) Serial.print(F("High precision float fix!")); 89 | if (RTK == 2) Serial.print(F("High precision fix!")); 90 | 91 | Serial.println(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /examples/Example5_SpeedHeadingPrecision/Example5_SpeedHeadingPrecision.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get Speed/Heading and dilution of precision via UBX binary commands - no more NMEA parsing! 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 query a Ublox module for its lat/long/altitude. 10 | 11 | Note: Long/lat are large numbers because they are * 10^7. To convert lat/long 12 | to something google maps understands simply divide the numbers by 1,000,000. We 13 | do this so that we don't have to use floating point numbers. 14 | 15 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 //Needed for I2C to GPS 30 | 31 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 32 | SFE_UBLOX_GPS myGPS; 33 | 34 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 35 | 36 | void setup() 37 | { 38 | Serial.begin(115200); 39 | while (!Serial); //Wait for user to open terminal 40 | Serial.println("SparkFun Ublox Example"); 41 | 42 | Wire.begin(); 43 | 44 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 45 | { 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 47 | while (1); 48 | } 49 | } 50 | 51 | void loop() 52 | { 53 | //Query module only every second. Doing it more often will just cause I2C traffic. 54 | //The module only responds when a new position is available 55 | if (millis() - lastTime > 1000) 56 | { 57 | lastTime = millis(); //Update the timer 58 | 59 | long latitude = myGPS.getLatitude(); 60 | Serial.print(F("Lat: ")); 61 | Serial.print(latitude); 62 | 63 | long longitude = myGPS.getLongitude(); 64 | Serial.print(F(" Long: ")); 65 | Serial.print(longitude); 66 | 67 | long speed = myGPS.getGroundSpeed(); 68 | Serial.print(F(" Speed: ")); 69 | Serial.print(speed); 70 | Serial.print(F(" (mm/s)")); 71 | 72 | long heading = myGPS.getHeading(); 73 | Serial.print(F(" Heading: ")); 74 | Serial.print(heading); 75 | Serial.print(F(" (degrees * 10^-5)")); 76 | 77 | int pDOP = myGPS.getPDOP(); 78 | Serial.print(F(" pDOP: ")); 79 | Serial.print(pDOP / 100.0, 2); 80 | 81 | Serial.println(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /examples/Example6_EnableNMEASentences/Example6_EnableNMEASentences.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Turn on/off various NMEA sentences. 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 turn on/off the NMEA sentences being output 10 | over UART1. We use the I2C interface on the Ublox module for configuration 11 | but you won't see any output from this sketch. You'll need to hook up 12 | a Serial Basic or other USB to Serial device to UART1 on your Ublox module 13 | to see the output. 14 | 15 | This example turns off all sentences except for the GPGGA and GPVTG sentences. 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 RedBoard 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 | Hookup a Serial Basic (https://www.sparkfun.com/products/15096) to UART1 on the Ublox module. Open a terminal at 57600bps 28 | and see GPGGA and GPVTG sentences. 29 | */ 30 | #include //Needed for I2C to GPS 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | unsigned long lastGPSSend = 0; 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); // Serial debug output over USB visible from Arduino IDE 40 | Serial.println("Example showing how to enable/disable certain NMEA sentences"); 41 | 42 | Wire.begin(); 43 | 44 | if (myGPS.begin() == false) 45 | { 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 47 | while (1) 48 | ; 49 | } 50 | 51 | //Disable or enable various NMEA sentences over the UART1 interface 52 | myGPS.disableNMEAMessage(UBX_NMEA_GLL, COM_PORT_UART1); //Several of these are on by default on virgin ublox board so let's disable them 53 | myGPS.disableNMEAMessage(UBX_NMEA_GSA, COM_PORT_UART1); 54 | myGPS.disableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1); 55 | myGPS.disableNMEAMessage(UBX_NMEA_RMC, COM_PORT_UART1); 56 | myGPS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_UART1); //Only leaving GGA/VTG enabled at current navigation rate 57 | myGPS.enableNMEAMessage(UBX_NMEA_VTG, COM_PORT_UART1); 58 | 59 | //Here's the advanced configure method 60 | //Some of the other examples in this library enable the PVT message so let's disable it 61 | myGPS.configureMessage(UBX_CLASS_NAV, UBX_NAV_PVT, COM_PORT_UART1, 0); //Message Class, ID, and port we want to configure, sendRate of 0 (disable). 62 | 63 | myGPS.setUART1Output(COM_TYPE_NMEA); //Turn off UBX and RTCM sentences on the UART1 interface 64 | 65 | myGPS.setSerialRate(57600); //Set UART1 to 57600bps. 66 | 67 | myGPS.saveConfiguration(); //Save these settings to NVM 68 | 69 | Serial.println(F("Messages configured. NMEA now being output over the UART1 port on the Ublox module at 57600bps.")); 70 | } 71 | 72 | void loop() 73 | { 74 | if (millis() - lastGPSSend > 200) 75 | { 76 | myGPS.checkUblox(); //See if new data is available, but we don't want to get NMEA here. Go check UART1. 77 | lastGPSSend = millis(); 78 | } 79 | } -------------------------------------------------------------------------------- /examples/Example7_OutputRate/Example7_OutputRate.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Set update rate to 10Hz 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 increase the output of the module from 1Hz to 4Hz. 10 | The max output rate various from model to model. RTFM! But you cannot do harm 11 | to the module. 12 | 13 | We also disable NMEA output on the I2C bus and use only UBX. This dramatically 14 | decreases the amount of data that needs to be transmitted. 15 | 16 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 //Needed for I2C to GPS 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 36 | long startTime = 0; //Used to calc the actual update rate. 37 | long updateCount = 0; //Used to calc the actual update rate. 38 | 39 | void setup() 40 | { 41 | Serial.begin(115200); 42 | while (!Serial); //Wait for user to open terminal 43 | Serial.println("SparkFun Ublox Example"); 44 | 45 | Wire.begin(); 46 | Wire.setClock(400000); 47 | 48 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 49 | { 50 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 51 | while (1); 52 | } 53 | 54 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 55 | myGPS.setNavigationFrequency(10); //Set output to 10 times a second 56 | 57 | byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module 58 | Serial.print("Current update rate:"); 59 | Serial.println(rate); 60 | 61 | startTime = millis(); 62 | } 63 | 64 | void loop() 65 | { 66 | //Query module only every second. Doing it more often will just cause I2C traffic. 67 | //The module only responds when a new position is available. This is defined 68 | //by the update freq. 69 | if (millis() - lastTime > 25) 70 | { 71 | lastTime = millis(); //Update the timer 72 | 73 | long latitude = myGPS.getLatitude(); 74 | Serial.print(F("Lat: ")); 75 | Serial.print(latitude); 76 | 77 | long longitude = myGPS.getLongitude(); 78 | Serial.print(F(" Long: ")); 79 | Serial.print(longitude); 80 | 81 | updateCount++; 82 | 83 | //Calculate the actual update rate based on the sketch start time and the 84 | //number of updates we've received. 85 | Serial.print(F(" Rate: ")); 86 | Serial.print( updateCount / ((millis() - startTime) / 1000.0), 2); 87 | Serial.print(F("Hz")); 88 | 89 | Serial.println(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /examples/Example8_GetProtocolVersion/Example8_GetProtocolVersion.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reading the protocol version of a Ublox module 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 query a Ublox module for its protocol version. 10 | 11 | Various modules have various protocol version. We've seen v18 up to v27. Depending 12 | on the protocol version there are different commands available. This is a handy 13 | way to predict which commands will or won't work. 14 | 15 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 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 //Needed for I2C to GPS 30 | 31 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 32 | SFE_UBLOX_GPS myGPS; 33 | 34 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 35 | 36 | void setup() 37 | { 38 | Serial.begin(115200); 39 | while (!Serial); //Wait for user to open terminal 40 | Serial.println("SparkFun Ublox Example"); 41 | 42 | Wire.begin(); 43 | 44 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 45 | { 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 47 | while (1); 48 | } 49 | 50 | Serial.print(F("Version: ")); 51 | byte versionHigh = myGPS.getProtocolVersionHigh(); 52 | Serial.print(versionHigh); 53 | Serial.print("."); 54 | byte versionLow = myGPS.getProtocolVersionLow(); 55 | Serial.print(versionLow); 56 | } 57 | 58 | void loop() 59 | { 60 | //Do nothing 61 | } 62 | -------------------------------------------------------------------------------- /examples/Example9_ChangeI2CAddress/Example9_ChangeI2CAddress.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Change the I2C address of a Ublox module using 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 change the I2C address of a Ublox module 10 | 11 | Feel like supporting open source hardware? 12 | Buy a board from SparkFun! 13 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 14 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 15 | SAM-M8Q: https://www.sparkfun.com/products/15106 16 | 17 | Hardware Connections: 18 | Plug a Qwiic cable into the GPS and a BlackBoard 19 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 20 | Open the serial monitor at 115200 baud to see the output 21 | */ 22 | 23 | #include //Needed for I2C to GPS 24 | 25 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 26 | SFE_UBLOX_GPS myGPS; 27 | 28 | long lastTime = 0; //Tracks the passing of 2000ms (2 seconds) 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | while (!Serial); //Wait for user to open terminal 34 | Serial.println("SparkFun Ublox Example"); 35 | 36 | Wire.begin(); 37 | 38 | byte oldAddress = 0x42; //The default address for Ublox modules is 0x42 39 | byte newAddress = 0x3F; //Address you want to change to. Valid is 0x08 to 0x77. 40 | 41 | while (Serial.available()) Serial.read(); //Trash any incoming chars 42 | Serial.print("Press a key to change address to 0x"); 43 | Serial.println(newAddress, HEX); 44 | while (Serial.available() == false) ; //Wait for user to send character 45 | 46 | if (myGPS.begin(Wire, oldAddress) == true) //Connect to the Ublox module using Wire port and the old address 47 | { 48 | Serial.print("GPS found at address 0x"); 49 | Serial.println(oldAddress, HEX); 50 | 51 | myGPS.setI2CAddress(newAddress); //Change I2C address of this device 52 | //Device's I2C address is stored to memory and loaded on each power-on 53 | 54 | if (myGPS.begin(Wire, newAddress) == true) 55 | { 56 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 57 | 58 | Serial.print("Address successfully changed to 0x"); 59 | Serial.println(newAddress, HEX); 60 | Serial.print("Now load another example sketch using .begin(Wire, 0x"); 61 | Serial.print(newAddress, HEX); 62 | Serial.println(") to use this GPS module"); 63 | Serial.println("Freezing..."); 64 | while (1); 65 | } 66 | } 67 | 68 | //Something went wrong, begin looking for the I2C device 69 | Serial.println("Address change failed. Beginning an I2C scan."); 70 | 71 | Wire.begin(); 72 | } 73 | 74 | void loop() { 75 | 76 | byte address; 77 | int nDevices; 78 | 79 | Serial.println("Scanning..."); 80 | 81 | nDevices = 0; 82 | for (address = 1; address < 127; address++ ) 83 | { 84 | Wire.beginTransmission(address); 85 | byte error = Wire.endTransmission(); 86 | 87 | if (error == 0) 88 | { 89 | Serial.print("I2C device found at address 0x"); 90 | if (address < 16) 91 | Serial.print("0"); 92 | Serial.print(address, HEX); 93 | Serial.println(" !"); 94 | 95 | nDevices++; 96 | } 97 | else if (error == 4) 98 | { 99 | Serial.print("Unknown error at address 0x"); 100 | if (address < 16) 101 | Serial.print("0"); 102 | Serial.println(address, HEX); 103 | } 104 | } 105 | 106 | if (nDevices == 0) 107 | Serial.println("No I2C devices found\n"); 108 | else 109 | Serial.println("done\n"); 110 | 111 | delay(5000); // wait 5 seconds for next scan 112 | } 113 | -------------------------------------------------------------------------------- /examples/NEO-M8P-2/Example1_EnableRTCM/Example1_EnableRTCM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox NEO-M8P module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: September 7th, 2018 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 sends the command to enable the four RTCM messages needed for RTK. This 10 | is the first part of a larger tutorial and example to setup an RTK base station. 11 | These commands are only accepted by the NEO-M8P module. 12 | 13 | Feel like supporting open source hardware? 14 | Buy a board from SparkFun! 15 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 16 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 17 | SAM-M8Q: https://www.sparkfun.com/products/15106 18 | 19 | Hardware Connections: 20 | Plug a Qwiic cable into the GPS and a BlackBoard 21 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 22 | Open the serial monitor at 115200 baud to see the output 23 | */ 24 | 25 | #include //Needed for I2C to GPS 26 | 27 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | while(!Serial); //Wait for user to open terminal 34 | Serial.println("Ublox RTCM Enable Example"); 35 | 36 | Wire.begin(); 37 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 38 | 39 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 40 | { 41 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 42 | while (1); 43 | } 44 | 45 | while(Serial.available()) Serial.read(); //Clear any latent chars in serial buffer 46 | Serial.println("Press any key to send commands to enable RTCM 3.x"); 47 | while(Serial.available() == 0) ; //Wait for user to press a key 48 | 49 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 50 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 51 | 52 | boolean response = true; 53 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 54 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, COM_PORT_I2C, 1); 55 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, COM_PORT_I2C, 1); 56 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds 57 | 58 | if (response == true) 59 | { 60 | Serial.println("RTCM messages enabled"); 61 | } 62 | else 63 | { 64 | Serial.println("RTCM failed to enable. Are you sure you have an NEO-M8P?"); 65 | while(1); //Freeze 66 | } 67 | 68 | //RTCM is now enabled but we haven't done a 'survey-in' 69 | //See example 4 for the full Base RTK setup 70 | } 71 | 72 | void loop() 73 | { 74 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 75 | 76 | delay(250); //Don't pound too hard on the I2C bus 77 | } 78 | -------------------------------------------------------------------------------- /examples/NEO-M8P-2/Example2_StartRTCMBase/Example2_StartRTCMBase.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox NEO-M8P-2 module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: September 7th, 2018 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 does all steps to configure and enable a NEO-M8P-2 as a base station: 10 | Begin Survey-In 11 | Once we've achieved 2m accuracy and 300s have passed, survey is complete 12 | Enable four RTCM messages 13 | Begin outputting RTCM bytes 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | while (!Serial); //Wait for user to open terminal 36 | Serial.println("Ublox NEO-M8P-2 base station example"); 37 | 38 | Wire.begin(); 39 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 40 | 41 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 42 | { 43 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 44 | while (1); 45 | } 46 | 47 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 48 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 49 | 50 | while (Serial.available()) Serial.read(); //Clear any latent chars in serial buffer 51 | Serial.println("Press any key to send commands to begin Survey-In"); 52 | while (Serial.available() == 0) ; //Wait for user to press a key 53 | 54 | boolean response; 55 | 56 | //Check if Survey is in Progress before initiating one 57 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time) 58 | if (response == false) 59 | { 60 | Serial.println("Failed to get Survey In status"); 61 | while (1); //Freeze 62 | } 63 | 64 | if (myGPS.svin.active == true) 65 | { 66 | Serial.print("Survey already in progress."); 67 | } 68 | else 69 | { 70 | //Start survey 71 | response = myGPS.enableSurveyMode(300, 2.000); //Enable Survey in, 300 seconds, 2.0m 72 | if (response == false) 73 | { 74 | Serial.println("Survey start failed"); 75 | while (1); 76 | } 77 | Serial.println("Survey started. This will run until 300s has passed and less than 2m accuracy is achieved."); 78 | } 79 | 80 | while(Serial.available()) Serial.read(); //Clear buffer 81 | 82 | //Begin waiting for survey to complete 83 | while (myGPS.svin.valid == false) 84 | { 85 | if(Serial.available()) 86 | { 87 | byte incoming = Serial.read(); 88 | if(incoming == 'x') 89 | { 90 | //Stop survey mode 91 | response = myGPS.disableSurveyMode(); //Disable survey 92 | Serial.println("Survey stopped"); 93 | break; 94 | } 95 | } 96 | 97 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time) 98 | if (response == true) 99 | { 100 | Serial.print("Press x to end survey - "); 101 | Serial.print("Time elapsed: "); 102 | Serial.print((String)myGPS.svin.observationTime); 103 | 104 | Serial.print(" Accuracy: "); 105 | Serial.print((String)myGPS.svin.meanAccuracy); 106 | Serial.println(); 107 | } 108 | else 109 | { 110 | Serial.println("SVIN request failed"); 111 | } 112 | 113 | delay(1000); 114 | } 115 | Serial.println("Survey valid!"); 116 | 117 | response = true; 118 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 119 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, COM_PORT_I2C, 1); 120 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, COM_PORT_I2C, 1); 121 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds 122 | 123 | if (response == true) 124 | { 125 | Serial.println("RTCM messages enabled"); 126 | } 127 | else 128 | { 129 | Serial.println("RTCM failed to enable. Are you sure you have an NEO-M8P?"); 130 | while (1); //Freeze 131 | } 132 | 133 | Serial.println("Base survey complete! RTCM now broadcasting."); 134 | } 135 | 136 | void loop() 137 | { 138 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 139 | 140 | delay(250); //Don't pound too hard on the I2C bus 141 | } 142 | 143 | //This function gets called from the SparkFun Ublox Arduino Library. 144 | //As each RTCM byte comes in you can specify what to do with it 145 | //Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc. 146 | void SFE_UBLOX_GPS::processRTCM(uint8_t incoming) 147 | { 148 | //Let's just pretty-print the HEX values for now 149 | if (myGPS.rtcmFrameCounter % 16 == 0) Serial.println(); 150 | Serial.print(" "); 151 | if (incoming < 0x10) Serial.print("0"); 152 | Serial.print(incoming, HEX); 153 | } 154 | -------------------------------------------------------------------------------- /examples/NEO-M8P-2/Example3_BaseWithLCD/Example3_BaseWithLCD.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox NEO-M8P-2 module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: September 7th, 2018 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 does all steps to configure and enable a NEO-M8P-2 as a base station: 10 | Begin Survey-In 11 | Once we've achieved 2m accuracy and 300s have passed, survey is complete 12 | Enable four RTCM messages 13 | Begin outputting RTCM bytes 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | Plug a SerLCD onto the Qwiic bus 24 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 25 | Watch the output on the LCD or open the serial monitor at 115200 baud to see the output 26 | */ 27 | 28 | #define STAT_LED 13 29 | 30 | #include //Needed for I2C to GPS 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 36 | SerLCD lcd; // Initialize the library with default I2C address 0x72 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial); //Wait for user to open terminal 42 | Serial.println("Ublox GPS I2C Test"); 43 | 44 | Wire.begin(); 45 | 46 | pinMode(STAT_LED, OUTPUT); 47 | digitalWrite(STAT_LED, LOW); 48 | 49 | lcd.begin(Wire); //Set up the LCD for Serial communication at 9600bps 50 | lcd.setBacklight(0x4B0082); //indigo, a kind of dark purplish blue 51 | lcd.clear(); 52 | lcd.print(F("LCD Ready")); 53 | 54 | myGPS.begin(Wire); 55 | if (myGPS.isConnected() == false) 56 | { 57 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 58 | lcd.setCursor(0, 1); 59 | lcd.print(F("No GPS detected")); 60 | while (1); 61 | } 62 | 63 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 64 | 65 | lcd.setCursor(0, 1); 66 | lcd.print("GPS Detected"); 67 | 68 | //Check if Survey is in Progress before initiating one 69 | boolean response; 70 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time) 71 | if (response == false) 72 | { 73 | Serial.println(F("Failed to get Survey In status")); 74 | while (1); //Freeze 75 | } 76 | 77 | if (myGPS.svin.active == true) 78 | { 79 | Serial.print(F("Survey already in progress.")); 80 | lcd.setCursor(0, 2); 81 | lcd.print(F("Survey already going")); 82 | } 83 | else 84 | { 85 | //Start survey 86 | response = myGPS.enableSurveyMode(300, 2.000); //Enable Survey in, 300 seconds, 2.0m 87 | if (response == false) 88 | { 89 | Serial.println(F("Survey start failed")); 90 | lcd.setCursor(0, 3); 91 | lcd.print(F("Survey start failed")); 92 | while (1); 93 | } 94 | Serial.println(F("Survey started. This will run until 300s has passed and less than 2m accuracy is achieved.")); 95 | } 96 | 97 | while (Serial.available()) Serial.read(); //Clear buffer 98 | 99 | lcd.clear(); 100 | lcd.print(F("Survey in progress")); 101 | 102 | //Begin waiting for survey to complete 103 | while (myGPS.svin.valid == false) 104 | { 105 | if (Serial.available()) 106 | { 107 | byte incoming = Serial.read(); 108 | if (incoming == 'x') 109 | { 110 | //Stop survey mode 111 | response = myGPS.disableSurveyMode(); //Disable survey 112 | Serial.println(F("Survey stopped")); 113 | break; 114 | } 115 | } 116 | 117 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time) 118 | if (response == true) 119 | { 120 | Serial.print(F("Press x to end survey - ")); 121 | Serial.print(F("Time elapsed: ")); 122 | Serial.print((String)myGPS.svin.observationTime); 123 | 124 | lcd.setCursor(0, 1); 125 | lcd.print(F("Elapsed: ")); 126 | lcd.print((String)myGPS.svin.observationTime); 127 | 128 | Serial.print(F(" Accuracy: ")); 129 | Serial.print((String)myGPS.svin.meanAccuracy); 130 | Serial.println(); 131 | 132 | lcd.setCursor(0, 2); 133 | lcd.print(F("Accuracy: ")); 134 | lcd.print((String)myGPS.svin.meanAccuracy); 135 | } 136 | else 137 | { 138 | Serial.println(F("SVIN request failed")); 139 | } 140 | 141 | delay(1000); 142 | } 143 | Serial.println(F("Survey valid!")); 144 | 145 | response = true; 146 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, UBX_RTCM_I2C_PORT, 1); //Enable message 1005 to output through I2C port, message every second 147 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, UBX_RTCM_I2C_PORT, 1); 148 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, UBX_RTCM_I2C_PORT, 1); 149 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, UBX_RTCM_I2C_PORT, 10); //Enable message every 10 seconds 150 | 151 | if (response == true) 152 | { 153 | Serial.println(F("RTCM messages enabled")); 154 | } 155 | else 156 | { 157 | Serial.println(F("RTCM failed to enable. Are you sure you have an NEO-M8P?")); 158 | while (1); //Freeze 159 | } 160 | 161 | Serial.println(F("Base survey complete! RTCM now broadcasting.")); 162 | lcd.clear(); 163 | lcd.print(F("Transmitting RTCM")); 164 | } 165 | 166 | void loop() 167 | { 168 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 169 | 170 | //Do anything you want. Call checkUblox() every second. NEO-M8P-2 has TX buffer of 4k bytes. 171 | 172 | delay(250); //Don't pound too hard on the I2C bus 173 | } 174 | 175 | //This function gets called from the SparkFun Ublox Arduino Library. 176 | //As each RTCM byte comes in you can specify what to do with it 177 | //Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc. 178 | void SFE_UBLOX_GPS::processRTCM(uint8_t incoming) 179 | { 180 | //Let's just pretty-print the HEX values for now 181 | if (myGPS.rtcmFrameCounter % 16 == 0) Serial.println(); 182 | Serial.print(" "); 183 | if (incoming < 0x10) Serial.print("0"); 184 | Serial.print(incoming, HEX); 185 | } 186 | -------------------------------------------------------------------------------- /examples/Series_6_7/Example1_GetPositionAndTime_Series_6_7/Example1_GetPositionAndTime_Series_6_7.ino: -------------------------------------------------------------------------------- 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 //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 | } 110 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example10_GetHighPrecisionPositionAndAccuracy/Example10_GetHighPrecisionPositionAndAccuracy.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get the high precision geodetic solution for latitude and longitude 3 | By: Nathan Seidle 4 | Modified by: Steven Rowland and Paul Clark 5 | SparkFun Electronics 6 | Date: April 17th, 2020 7 | License: MIT. See license file for more information but you can 8 | basically do whatever you want with this code. 9 | 10 | This example shows how to inspect the accuracy of the high-precision 11 | positional solution. Please see below for information about the units. 12 | 13 | Feel like supporting open source hardware? 14 | Buy a board from SparkFun! 15 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 16 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 17 | 18 | Hardware Connections: 19 | Plug a Qwiic cable into the GPS and a BlackBoard 20 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 21 | Open the serial monitor at 115200 baud to see the output 22 | */ 23 | 24 | #include //Needed for I2C to GPS 25 | 26 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 27 | SFE_UBLOX_GPS myGPS; 28 | 29 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | while (!Serial); //Wait for user to open terminal 35 | 36 | Wire.begin(); 37 | 38 | //myGPS.enableDebugging(Serial); 39 | 40 | if (myGPS.begin(Wire) == false) //Connect to the Ublox module using Wire port 41 | { 42 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 43 | while (1); 44 | } 45 | 46 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 47 | myGPS.setNavigationFrequency(20); //Set output to 20 times a second 48 | 49 | byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module 50 | Serial.print("Current update rate: "); 51 | Serial.println(rate); 52 | 53 | //myGPS.saveConfiguration(); //Save the current settings to flash and BBR 54 | } 55 | 56 | void loop() 57 | { 58 | //Query module only every second. Doing it more often will just cause I2C traffic. 59 | //The module only responds when a new position is available 60 | if (millis() - lastTime > 1000) 61 | { 62 | lastTime = millis(); //Update the timer 63 | 64 | // getHighResLatitude: returns the latitude from HPPOSLLH as an int32_t in degrees * 10^-7 65 | // getHighResLatitudeHp: returns the high resolution component of latitude from HPPOSLLH as an int8_t in degrees * 10^-9 66 | // getHighResLongitude: returns the longitude from HPPOSLLH as an int32_t in degrees * 10^-7 67 | // getHighResLongitudeHp: returns the high resolution component of longitude from HPPOSLLH as an int8_t in degrees * 10^-9 68 | // getElipsoid: returns the height above ellipsoid as an int32_t in mm 69 | // getElipsoidHp: returns the high resolution component of the height above ellipsoid as an int8_t in mm * 10^-1 70 | // getMeanSeaLevel: returns the height above mean sea level as an int32_t in mm 71 | // getMeanSeaLevelHp: returns the high resolution component of the height above mean sea level as an int8_t in mm * 10^-1 72 | // getHorizontalAccuracy: returns the horizontal accuracy estimate from HPPOSLLH as an uint32_t in mm * 10^-1 73 | 74 | // If you want to use the high precision latitude and longitude with the full 9 decimal places 75 | // you will need to use a 64-bit double - which is not supported on all platforms 76 | 77 | // To allow this example to run on standard platforms, we cheat by converting lat and lon to integer and fractional degrees 78 | 79 | // The high resolution altitudes can be converted into standard 32-bit float 80 | 81 | // First, let's collect the position data 82 | int32_t latitude = myGPS.getHighResLatitude(); 83 | int8_t latitudeHp = myGPS.getHighResLatitudeHp(); 84 | int32_t longitude = myGPS.getHighResLongitude(); 85 | int8_t longitudeHp = myGPS.getHighResLongitudeHp(); 86 | int32_t ellipsoid = myGPS.getElipsoid(); 87 | int8_t ellipsoidHp = myGPS.getElipsoidHp(); 88 | int32_t msl = myGPS.getMeanSeaLevel(); 89 | int8_t mslHp = myGPS.getMeanSeaLevelHp(); 90 | uint32_t accuracy = myGPS.getHorizontalAccuracy(); 91 | 92 | // Defines storage for the lat and lon units integer and fractional parts 93 | int32_t lat_int; // Integer part of the latitude in degrees 94 | int32_t lat_frac; // Fractional part of the latitude 95 | int32_t lon_int; // Integer part of the longitude in degrees 96 | int32_t lon_frac; // Fractional part of the longitude 97 | 98 | // Calculate the latitude and longitude integer and fractional parts 99 | lat_int = latitude / 10000000; // Convert latitude from degrees * 10^-7 to Degrees 100 | lat_frac = latitude - (lat_int * 10000000); // Calculate the fractional part of the latitude 101 | lat_frac = (lat_frac * 100) + latitudeHp; // Now add the high resolution component 102 | if (lat_frac < 0) // If the fractional part is negative, remove the minus sign 103 | { 104 | lat_frac = 0 - lat_frac; 105 | } 106 | lon_int = longitude / 10000000; // Convert latitude from degrees * 10^-7 to Degrees 107 | lon_frac = longitude - (lon_int * 10000000); // Calculate the fractional part of the longitude 108 | lon_frac = (lon_frac * 100) + longitudeHp; // Now add the high resolution component 109 | if (lon_frac < 0) // If the fractional part is negative, remove the minus sign 110 | { 111 | lon_frac = 0 - lon_frac; 112 | } 113 | 114 | // Print the lat and lon 115 | Serial.print("Lat (deg): "); 116 | Serial.print(lat_int); // Print the integer part of the latitude 117 | Serial.print("."); 118 | Serial.print(lat_frac); // Print the fractional part of the latitude 119 | Serial.print(", Lon (deg): "); 120 | Serial.print(lon_int); // Print the integer part of the latitude 121 | Serial.print("."); 122 | Serial.println(lon_frac); // Print the fractional part of the latitude 123 | 124 | // Now define float storage for the heights and accuracy 125 | float f_ellipsoid; 126 | float f_msl; 127 | float f_accuracy; 128 | 129 | // Calculate the height above ellipsoid in mm * 10^-1 130 | f_ellipsoid = (ellipsoid * 10) + ellipsoidHp; 131 | // Now convert to m 132 | f_ellipsoid = f_ellipsoid / 10000.0; // Convert from mm * 10^-1 to m 133 | 134 | // Calculate the height above mean sea level in mm * 10^-1 135 | f_msl = (msl * 10) + mslHp; 136 | // Now convert to m 137 | f_msl = f_msl / 10000.0; // Convert from mm * 10^-1 to m 138 | 139 | // Convert the horizontal accuracy (mm * 10^-1) to a float 140 | f_accuracy = accuracy; 141 | // Now convert to m 142 | f_accuracy = f_accuracy / 10000.0; // Convert from mm * 10^-1 to m 143 | 144 | // Finally, do the printing 145 | Serial.print("Ellipsoid (m): "); 146 | Serial.print(f_ellipsoid, 4); // Print the ellipsoid with 4 decimal places 147 | 148 | Serial.print(", Mean Sea Level(m): "); 149 | Serial.print(f_msl, 4); // Print the mean sea level with 4 decimal places 150 | 151 | Serial.print(", Accuracy (m): "); 152 | Serial.println(f_accuracy, 4); // Print the accuracy with 4 decimal places 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example11_GetHighPrecisionPositionUsingDouble/Example11_GetHighPrecisionPositionUsingDouble.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get the high precision geodetic solution for latitude and longitude using double 3 | By: Nathan Seidle 4 | Modified by: Paul Clark (PaulZC) 5 | SparkFun Electronics 6 | Date: April 17th, 2020 7 | License: MIT. See license file for more information but you can 8 | basically do whatever you want with this code. 9 | 10 | This example shows how to inspect the accuracy of the high-precision 11 | positional solution. Please see below for information about the units. 12 | 13 | ** This example will only work correctly on platforms which support 64-bit double ** 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | 20 | Hardware Connections: 21 | Plug a Qwiic cable into the GPS and (e.g.) a Redboard Artemis https://www.sparkfun.com/products/15444 22 | or an Artemis Thing Plus https://www.sparkfun.com/products/15574 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include // Needed for I2C to GPS 28 | 29 | #define myWire Wire // This will work on the Redboard Artemis and the Artemis Thing Plus using Qwiic 30 | //#define myWire Wire1 // Uncomment this line if you are using the extra SCL1/SDA1 pins (D17 and D16) on the Thing Plus 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); 40 | while (!Serial); //Wait for user to open terminal 41 | 42 | myWire.begin(); 43 | 44 | //myGPS.enableDebugging(Serial); // Uncomment this line to enable debug messages 45 | 46 | if (myGPS.begin(myWire) == false) //Connect to the Ublox module using Wire port 47 | { 48 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 49 | while (1) 50 | ; 51 | } 52 | 53 | // Check that this platform supports 64-bit (8 byte) double 54 | if (sizeof(double) < 8) 55 | { 56 | Serial.println(F("Warning! Your platform does not support 64-bit double.")); 57 | Serial.println(F("The latitude and longitude will be inaccurate.")); 58 | } 59 | 60 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 61 | 62 | //myGPS.setNavigationFrequency(20); //Set output to 20 times a second 63 | 64 | byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module 65 | Serial.print("Current update rate: "); 66 | Serial.println(rate); 67 | 68 | //myGPS.saveConfiguration(); //Save the current settings to flash and BBR 69 | } 70 | 71 | void loop() 72 | { 73 | //Query module only every second. 74 | //The module only responds when a new position is available. 75 | if (millis() - lastTime > 1000) 76 | { 77 | lastTime = millis(); //Update the timer 78 | 79 | // getHighResLatitude: returns the latitude from HPPOSLLH as an int32_t in degrees * 10^-7 80 | // getHighResLatitudeHp: returns the high resolution component of latitude from HPPOSLLH as an int8_t in degrees * 10^-9 81 | // getHighResLongitude: returns the longitude from HPPOSLLH as an int32_t in degrees * 10^-7 82 | // getHighResLongitudeHp: returns the high resolution component of longitude from HPPOSLLH as an int8_t in degrees * 10^-9 83 | // getElipsoid: returns the height above ellipsoid as an int32_t in mm 84 | // getElipsoidHp: returns the high resolution component of the height above ellipsoid as an int8_t in mm * 10^-1 85 | // getMeanSeaLevel: returns the height above mean sea level as an int32_t in mm 86 | // getMeanSeaLevelHp: returns the high resolution component of the height above mean sea level as an int8_t in mm * 10^-1 87 | // getHorizontalAccuracy: returns the horizontal accuracy estimate from HPPOSLLH as an uint32_t in mm * 10^-1 88 | 89 | // First, let's collect the position data 90 | int32_t latitude = myGPS.getHighResLatitude(); 91 | int8_t latitudeHp = myGPS.getHighResLatitudeHp(); 92 | int32_t longitude = myGPS.getHighResLongitude(); 93 | int8_t longitudeHp = myGPS.getHighResLongitudeHp(); 94 | int32_t ellipsoid = myGPS.getElipsoid(); 95 | int8_t ellipsoidHp = myGPS.getElipsoidHp(); 96 | int32_t msl = myGPS.getMeanSeaLevel(); 97 | int8_t mslHp = myGPS.getMeanSeaLevelHp(); 98 | uint32_t accuracy = myGPS.getHorizontalAccuracy(); 99 | 100 | // Defines storage for the lat and lon as double 101 | double d_lat; // latitude 102 | double d_lon; // longitude 103 | 104 | // Assemble the high precision latitude and longitude 105 | d_lat = ((double)latitude) / 10000000.0; // Convert latitude from degrees * 10^-7 to degrees 106 | d_lat += ((double)latitudeHp) / 1000000000.0; // Now add the high resolution component (degrees * 10^-9 ) 107 | d_lon = ((double)longitude) / 10000000.0; // Convert longitude from degrees * 10^-7 to degrees 108 | d_lon += ((double)longitudeHp) / 1000000000.0; // Now add the high resolution component (degrees * 10^-9 ) 109 | 110 | // Print the lat and lon 111 | Serial.print("Lat (deg): "); 112 | Serial.print(d_lat, 9); 113 | Serial.print(", Lon (deg): "); 114 | Serial.print(d_lon, 9); 115 | 116 | // Now define float storage for the heights and accuracy 117 | float f_ellipsoid; 118 | float f_msl; 119 | float f_accuracy; 120 | 121 | // Calculate the height above ellipsoid in mm * 10^-1 122 | f_ellipsoid = (ellipsoid * 10) + ellipsoidHp; 123 | // Now convert to m 124 | f_ellipsoid = f_ellipsoid / 10000.0; // Convert from mm * 10^-1 to m 125 | 126 | // Calculate the height above mean sea level in mm * 10^-1 127 | f_msl = (msl * 10) + mslHp; 128 | // Now convert to m 129 | f_msl = f_msl / 10000.0; // Convert from mm * 10^-1 to m 130 | 131 | // Convert the horizontal accuracy (mm * 10^-1) to a float 132 | f_accuracy = accuracy; 133 | // Now convert to m 134 | f_accuracy = f_accuracy / 10000.0; // Convert from mm * 10^-1 to m 135 | 136 | // Finally, do the printing 137 | Serial.print(", Ellipsoid (m): "); 138 | Serial.print(f_ellipsoid, 4); // Print the ellipsoid with 4 decimal places 139 | 140 | Serial.print(", Mean Sea Level (m): "); 141 | Serial.print(f_msl, 4); // Print the mean sea level with 4 decimal places 142 | 143 | Serial.print(", Accuracy (m): "); 144 | Serial.println(f_accuracy, 4); // Print the accuracy with 4 decimal places 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example12_setStaticPosition/Example12_setStaticPosition.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Set the static position of the receiver. 3 | By: SparkFun Electronics / Nathan Seidle 4 | Date: September 26th, 2020 5 | License: MIT. See license file for more information but you can 6 | basically do whatever you want with this code. 7 | 8 | This example shows how to set the static position of a receiver 9 | using an Earth-Centered, Earth-Fixed (ECEF) location. This is the 10 | output from a long (24 hour+) survey-in. Setting the static position 11 | immediately causes the receiver to begin outputting RTCM data (if 12 | enabled), perfect for setting up your own RTCM NTRIP caster or CORS. 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 | 19 | Hardware Connections: 20 | Plug a Qwiic cable into the GPS and a BlackBoard 21 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 22 | Open the serial monitor at 115200 baud to see the output 23 | */ 24 | 25 | #include //Needed for I2C to GPS 26 | 27 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); // You may need to increase this for high navigation rates! 33 | while (!Serial) 34 | ; //Wait for user to open terminal 35 | Serial.println(F("SparkFun u-blox Example")); 36 | 37 | Wire.begin(); 38 | 39 | //myGPS.enableDebugging(); // Uncomment this line to enable debug messages 40 | 41 | if (myGPS.begin() == false) //Connect to the u-blox module using Wire port 42 | { 43 | Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); 44 | while (1) 45 | ; 46 | } 47 | 48 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 49 | 50 | //-1280208.308,-4716803.847,4086665.811 is SparkFun HQ so... 51 | 52 | //Units are cm so 1234 = 12.34m 53 | //myGPS.setStaticPosition(-128020831, -471680385, 408666581); 54 | 55 | //Units are cm with a high precision extension so -1234.5678 should be called: (-123456, -78) 56 | myGPS.setStaticPosition(-128020830, -80, -471680384, -70, 408666581, 10); //With high precision 0.1mm parts 57 | 58 | //We can also set via lat/long 59 | //40.09029751,-105.18507900,1560.238 60 | //myGPS.setStaticPosition(400902975, -1051850790, 156024, true); //True at end enables lat/long input 61 | //myGPS.setStaticPosition(400902975, 10, -1051850790, 0, 156023, 80, true); 62 | 63 | //Now let's use getVals to read back the data 64 | //long ecefX = myGPS.getVal32(0x40030003); 65 | //Serial.print("ecefX: "); 66 | //Serial.println(ecefX); 67 | 68 | Serial.println(F("Done!")); 69 | } 70 | 71 | void loop() 72 | { 73 | } 74 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example13_autoHPPOSLLH/Example13_autoHPPOSLLH.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Configuring the GPS to automatically send HPPOSLLH position reports over I2C 3 | By: Paul Clark 4 | Date: October 27th 2020 5 | 6 | Based on an earlier example: 7 | By: Nathan Seidle and Thorsten von Eicken 8 | SparkFun Electronics 9 | Date: January 3rd, 2019 10 | License: MIT. See license file for more information but you can 11 | basically do whatever you want with this code. 12 | 13 | This example shows how to configure the U-Blox GPS the send navigation reports automatically 14 | and retrieving the latest one via getHPPOSLLH. This eliminates the blocking in getHPPOSLLH while the GPS 15 | produces a fresh navigation solution at the expense of returning a slighly old solution. 16 | 17 | This can be used over serial or over I2C, this example shows the I2C use. With serial the GPS 18 | simply outputs the UBX_NAV_HPPOSLLH packet. With I2C it queues it into its internal I2C buffer (4KB in 19 | size?) where it can be retrieved in the next I2C poll. 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 | 26 | Hardware Connections: 27 | Plug a Qwiic cable into the GPS and a BlackBoard 28 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 29 | Open the serial monitor at 115200 baud to see the output 30 | */ 31 | 32 | #include //Needed for I2C to GPS 33 | 34 | #include //http://librarymanager/All#SparkFun_u-blox_GNSS 35 | SFE_UBLOX_GPS myGPS; 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); 40 | while (!Serial); //Wait for user to open terminal 41 | Serial.println("SparkFun Ublox Example"); 42 | 43 | Wire.begin(); 44 | 45 | //myGPS.enableDebugging(); // Uncomment this line to enable lots of helpful debug messages 46 | //myGPS.enableDebugging(Serial, true); // Uncomment this line to enable the minimum of helpful debug messages 47 | 48 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 49 | { 50 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 51 | while (1); 52 | } 53 | 54 | // Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate 55 | //myGPS.factoryDefault(); delay(5000); 56 | 57 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 58 | myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR 59 | 60 | myGPS.setNavigationFrequency(1); //Produce one solution per second 61 | 62 | 63 | // The acid test: all four of these combinations should work seamlessly :-) 64 | 65 | //myGPS.setAutoPVT(false); // Library will poll each reading 66 | //myGPS.setAutoHPPOSLLH(false); // Library will poll each reading 67 | 68 | //myGPS.setAutoPVT(true); // Tell the GPS to "send" each solution automatically 69 | //myGPS.setAutoHPPOSLLH(false); // Library will poll each reading 70 | 71 | //myGPS.setAutoPVT(false); // Library will poll each reading 72 | //myGPS.setAutoHPPOSLLH(true); // Tell the GPS to "send" each hi res solution automatically 73 | 74 | myGPS.setAutoPVT(true); // Tell the GPS to "send" each solution automatically 75 | myGPS.setAutoHPPOSLLH(true); // Tell the GPS to "send" each hi res solution automatically 76 | } 77 | 78 | void loop() 79 | { 80 | // Calling getHPPOSLLH returns true if there actually is a fresh navigation solution available. 81 | // Calling getPVT returns true if there actually is a fresh navigation solution available. 82 | if ((myGPS.getHPPOSLLH()) || (myGPS.getPVT())) 83 | { 84 | Serial.println(); 85 | 86 | long highResLatitude = myGPS.getHighResLatitude(); 87 | Serial.print(F("Hi Res Lat: ")); 88 | Serial.print(highResLatitude); 89 | 90 | int highResLatitudeHp = myGPS.getHighResLatitudeHp(); 91 | Serial.print(F(" ")); 92 | Serial.print(highResLatitudeHp); 93 | 94 | long highResLongitude = myGPS.getHighResLongitude(); 95 | Serial.print(F(" Hi Res Long: ")); 96 | Serial.print(highResLongitude); 97 | 98 | int highResLongitudeHp = myGPS.getHighResLongitudeHp(); 99 | Serial.print(F(" ")); 100 | Serial.print(highResLongitudeHp); 101 | 102 | unsigned long horizAccuracy = myGPS.getHorizontalAccuracy(); 103 | Serial.print(F(" Horiz accuracy: ")); 104 | Serial.print(horizAccuracy); 105 | 106 | long latitude = myGPS.getLatitude(); 107 | Serial.print(F(" Lat: ")); 108 | Serial.print(latitude); 109 | 110 | long longitude = myGPS.getLongitude(); 111 | Serial.print(F(" Long: ")); 112 | Serial.println(longitude); 113 | } 114 | else 115 | { 116 | Serial.print("."); 117 | delay(50); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example14_NTRIPServer/secrets.h: -------------------------------------------------------------------------------- 1 | //Your WiFi credentials 2 | const char* ssid = "TRex"; 3 | const char* password = "hasBigTeeth"; 4 | 5 | //Your RTK2GO mount point credentials 6 | const char* mntpnt_pw = "WR5wRo4H"; 7 | const char* mntpnt = "bldr_dwntwn2"; 8 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example1_GetPositionAccuracy/Example1_GetPositionAccuracy.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get the high position accuracy of the RTK enhanced position 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 inspect the accuracy of the high-precision 10 | positional solution. 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 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 16 | SAM-M8Q: https://www.sparkfun.com/products/15106 17 | 18 | Hardware Connections: 19 | Plug a Qwiic cable into the GPS and a BlackBoard 20 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 21 | Open the serial monitor at 115200 baud to see the output 22 | */ 23 | 24 | #include //Needed for I2C to GPS 25 | 26 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 27 | SFE_UBLOX_GPS myGPS; 28 | 29 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | while (!Serial); //Wait for user to open terminal 35 | Serial.println("SparkFun Ublox Example"); 36 | 37 | Wire.begin(); 38 | 39 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 40 | { 41 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 42 | while (1); 43 | } 44 | 45 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 46 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 47 | } 48 | 49 | void loop() 50 | { 51 | //Query module only every second. Doing it more often will just cause I2C traffic. 52 | //The module only responds when a new position is available 53 | if (millis() - lastTime > 1000) 54 | { 55 | lastTime = millis(); //Update the timer 56 | 57 | long latitude = myGPS.getLatitude(); 58 | Serial.print(F("Lat: ")); 59 | Serial.print(latitude); 60 | 61 | long longitude = myGPS.getLongitude(); 62 | Serial.print(F(" Long: ")); 63 | Serial.print(longitude); 64 | Serial.print(F(" (degrees * 10^-7)")); 65 | 66 | long altitude = myGPS.getAltitude(); 67 | Serial.print(F(" Alt: ")); 68 | Serial.print(altitude); 69 | Serial.print(F(" (mm)")); 70 | 71 | long accuracy = myGPS.getPositionAccuracy(); 72 | Serial.print(F(" 3D Positional Accuracy: ")); 73 | Serial.print(accuracy); 74 | Serial.println(F("mm")); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example2_ValConfigurationMethod/Example2_ValConfigurationMethod.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Configuring Ublox Module using new VALGET / VALSET / VALDEL methods 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 | Ublox depricated many -CFG messages and replaced them with new 10 | VALGET, VALSET, VALDEL methods. This shows the basics of how to use 11 | these methods. 12 | 13 | Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 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 | byte response; 49 | response = myGPS.getVal8(VAL_GROUP_I2C, VAL_ID_I2C_ADDRESS, VAL_GROUP_I2C_SIZE, VAL_LAYER_RAM); 50 | Serial.print(F("I2C Address: 0x")); 51 | Serial.println(response >> 1, HEX); //We have to shift by 1 to get the common '7-bit' I2C address format 52 | 53 | response = myGPS.getVal8(VAL_GROUP_I2COUTPROT, VAL_ID_I2COUTPROT_NMEA, VAL_GROUP_I2COUTPROT_SIZE, VAL_LAYER_RAM); 54 | Serial.print(F("Output NMEA over I2C port: 0x")); 55 | Serial.print(response, HEX); 56 | } 57 | 58 | void loop() 59 | { 60 | } 61 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example3_StartRTCMBase/Example3_StartRTCMBase.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: January 9th, 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 does all steps to configure and enable a ZED-F9P as a base station: 10 | Begin Survey-In 11 | Once we've achieved 2m accuracy and 300s have passed, survey is complete 12 | Enable six RTCM messages 13 | Begin outputting RTCM bytes 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 24 | Open the serial monitor at 115200 baud to see the output 25 | */ 26 | 27 | #include //Needed for I2C to GPS 28 | 29 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 30 | SFE_UBLOX_GPS myGPS; 31 | 32 | //#define USE_SERIAL1 // Uncomment this line to push the RTCM data to Serial1 33 | 34 | void setup() 35 | { 36 | Serial.begin(115200); 37 | while (!Serial); //Wait for user to open terminal 38 | Serial.println("Ublox Base station example"); 39 | 40 | #ifdef USE_SERIAL1 41 | // If our board supports it, we can output the RTCM data on Serial1 42 | Serial1.begin(115200); 43 | #endif 44 | 45 | Wire.begin(); 46 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 47 | 48 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 49 | { 50 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 51 | while (1); 52 | } 53 | 54 | // Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate 55 | //myGPS.factoryDefault(); delay(5000); 56 | 57 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) 58 | myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR 59 | 60 | while (Serial.available()) Serial.read(); //Clear any latent chars in serial buffer 61 | Serial.println("Press any key to send commands to begin Survey-In"); 62 | while (Serial.available() == 0) ; //Wait for user to press a key 63 | 64 | boolean response = true; 65 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 66 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1074, COM_PORT_I2C, 1); 67 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1084, COM_PORT_I2C, 1); 68 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1094, COM_PORT_I2C, 1); 69 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1124, COM_PORT_I2C, 1); 70 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds 71 | 72 | //Use COM_PORT_UART1 for the above six messages to direct RTCM messages out UART1 73 | //COM_PORT_UART2, COM_PORT_USB, COM_PORT_SPI are also available 74 | //For example: response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_UART1, 10); 75 | 76 | if (response == true) 77 | { 78 | Serial.println("RTCM messages enabled"); 79 | } 80 | else 81 | { 82 | Serial.println("RTCM failed to enable. Are you sure you have an ZED-F9P?"); 83 | while (1); //Freeze 84 | } 85 | 86 | //Check if Survey is in Progress before initiating one 87 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time) 88 | if (response == false) 89 | { 90 | Serial.println("Failed to get Survey In status"); 91 | while (1); //Freeze 92 | } 93 | 94 | if (myGPS.svin.active == true) 95 | { 96 | Serial.print("Survey already in progress."); 97 | } 98 | else 99 | { 100 | //Start survey 101 | //The ZED-F9P is slightly different than the NEO-M8P. See the Integration manual 3.5.8 for more info. 102 | //response = myGPS.enableSurveyMode(300, 2.000); //Enable Survey in on NEO-M8P, 300 seconds, 2.0m 103 | response = myGPS.enableSurveyMode(60, 5.000); //Enable Survey in, 60 seconds, 5.0m 104 | if (response == false) 105 | { 106 | Serial.println("Survey start failed"); 107 | while (1); 108 | } 109 | Serial.println("Survey started. This will run until 60s has passed and less than 5m accuracy is achieved."); 110 | } 111 | 112 | while(Serial.available()) Serial.read(); //Clear buffer 113 | 114 | //Begin waiting for survey to complete 115 | while (myGPS.svin.valid == false) 116 | { 117 | if(Serial.available()) 118 | { 119 | byte incoming = Serial.read(); 120 | if(incoming == 'x') 121 | { 122 | //Stop survey mode 123 | response = myGPS.disableSurveyMode(); //Disable survey 124 | Serial.println("Survey stopped"); 125 | break; 126 | } 127 | } 128 | 129 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time) 130 | if (response == true) 131 | { 132 | Serial.print("Press x to end survey - "); 133 | Serial.print("Time elapsed: "); 134 | Serial.print((String)myGPS.svin.observationTime); 135 | 136 | Serial.print(" Accuracy: "); 137 | Serial.print((String)myGPS.svin.meanAccuracy); 138 | Serial.println(); 139 | } 140 | else 141 | { 142 | Serial.println("SVIN request failed"); 143 | } 144 | 145 | delay(1000); 146 | } 147 | Serial.println("Survey valid!"); 148 | 149 | Serial.println("Base survey complete! RTCM now broadcasting."); 150 | 151 | myGPS.setI2COutput(COM_TYPE_UBX | COM_TYPE_RTCM3); //Set the I2C port to output UBX and RTCM sentences (not really an option, turns on NMEA as well) 152 | } 153 | 154 | void loop() 155 | { 156 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 157 | 158 | delay(250); //Don't pound too hard on the I2C bus 159 | } 160 | 161 | //This function gets called from the SparkFun Ublox Arduino Library. 162 | //As each RTCM byte comes in you can specify what to do with it 163 | //Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc. 164 | void SFE_UBLOX_GPS::processRTCM(uint8_t incoming) 165 | { 166 | #ifdef USE_SERIAL1 167 | //Push the RTCM data to Serial1 168 | Serial1.write(incoming); 169 | #endif 170 | 171 | //Pretty-print the HEX values to Serial 172 | if (myGPS.rtcmFrameCounter % 16 == 0) Serial.println(); 173 | Serial.print(" "); 174 | if (incoming < 0x10) Serial.print("0"); 175 | Serial.print(incoming, HEX); 176 | } 177 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example4_BaseWithLCD/Example4_BaseWithLCD.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: January 9th, 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 does all steps to configure and enable a ZED-F9P as a base station: 10 | Begin Survey-In 11 | Once we've achieved 2m accuracy and 300s have passed, survey is complete 12 | Enable six RTCM messages 13 | Begin outputting RTCM bytes 14 | 15 | Feel like supporting open source hardware? 16 | Buy a board from SparkFun! 17 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 18 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 19 | SAM-M8Q: https://www.sparkfun.com/products/15106 20 | 21 | Hardware Connections: 22 | Plug a Qwiic cable into the GPS and a BlackBoard 23 | Plug a SerLCD onto the Qwiic bus 24 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 25 | Watch the output on the LCD or open the serial monitor at 115200 baud to see the output 26 | */ 27 | 28 | #define STAT_LED 13 29 | 30 | #include //Needed for I2C to GPS 31 | 32 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 33 | SFE_UBLOX_GPS myGPS; 34 | 35 | #include //http://librarymanager/All#SparkFun_SerLCD 36 | SerLCD lcd; // Initialize the library with default I2C address 0x72 37 | 38 | void setup() 39 | { 40 | Serial.begin(115200); 41 | while (!Serial) 42 | ; //Wait for user to open terminal 43 | Serial.println("Ublox GPS I2C Test"); 44 | 45 | Wire.begin(); 46 | 47 | pinMode(STAT_LED, OUTPUT); 48 | digitalWrite(STAT_LED, LOW); 49 | 50 | lcd.begin(Wire); //Set up the LCD for Serial communication at 9600bps 51 | lcd.setBacklight(0x4B0082); //indigo, a kind of dark purplish blue 52 | lcd.clear(); 53 | lcd.print(F("LCD Ready")); 54 | 55 | myGPS.begin(Wire); 56 | if (myGPS.isConnected() == false) 57 | { 58 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 59 | lcd.setCursor(0, 1); 60 | lcd.print(F("No GPS detected")); 61 | while (1) 62 | ; 63 | } 64 | 65 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 66 | 67 | lcd.setCursor(0, 1); 68 | lcd.print("GPS Detected"); 69 | 70 | //myGPS.setI2COutput(COM_TYPE_RTCM3); //Set the I2C port to output RTCM3 sentences (turn off NMEA noise) 71 | myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX sentences (turn off NMEA noise) 72 | myGPS.saveConfiguration(); //Save the current settings to flash and BBR 73 | 74 | boolean response = true; 75 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 76 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1074, COM_PORT_I2C, 1); 77 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1084, COM_PORT_I2C, 1); 78 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1094, COM_PORT_I2C, 1); 79 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1124, COM_PORT_I2C, 1); 80 | response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds 81 | if (response == true) 82 | { 83 | Serial.println(F("RTCM messages enabled")); 84 | } 85 | else 86 | { 87 | Serial.println(F("RTCM failed to enable. Are you sure you have an ZED-F9P? Freezing.")); 88 | while (1) 89 | ; //Freeze 90 | } 91 | 92 | //Check if Survey is in Progress before initiating one 93 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time) 94 | if (response == false) 95 | { 96 | Serial.println(F("Failed to get Survey In status. Freezing.")); 97 | while (1) 98 | ; //Freeze 99 | } 100 | 101 | if (myGPS.svin.active == true) 102 | { 103 | Serial.print(F("Survey already in progress.")); 104 | lcd.setCursor(0, 2); 105 | lcd.print(F("Survey already going")); 106 | } 107 | else 108 | { 109 | //Start survey 110 | response = myGPS.enableSurveyMode(60, 5.000); //Enable Survey in, 60 seconds, 5.0m 111 | if (response == false) 112 | { 113 | Serial.println(F("Survey start failed")); 114 | lcd.setCursor(0, 3); 115 | lcd.print(F("Survey start failed. Freezing.")); 116 | while (1) 117 | ; 118 | } 119 | Serial.println(F("Survey started. This will run until 60s has passed and less than 5m accuracy is achieved.")); 120 | } 121 | 122 | while (Serial.available()) 123 | Serial.read(); //Clear buffer 124 | 125 | lcd.clear(); 126 | lcd.print(F("Survey in progress")); 127 | 128 | //Begin waiting for survey to complete 129 | while (myGPS.svin.valid == false) 130 | { 131 | if (Serial.available()) 132 | { 133 | byte incoming = Serial.read(); 134 | if (incoming == 'x') 135 | { 136 | //Stop survey mode 137 | response = myGPS.disableSurveyMode(); //Disable survey 138 | Serial.println(F("Survey stopped")); 139 | break; 140 | } 141 | } 142 | 143 | response = myGPS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time) 144 | if (response == true) 145 | { 146 | Serial.print(F("Press x to end survey - ")); 147 | Serial.print(F("Time elapsed: ")); 148 | Serial.print((String)myGPS.svin.observationTime); 149 | 150 | lcd.setCursor(0, 1); 151 | lcd.print(F("Elapsed: ")); 152 | lcd.print((String)myGPS.svin.observationTime); 153 | 154 | Serial.print(F(" Accuracy: ")); 155 | Serial.print((String)myGPS.svin.meanAccuracy); 156 | Serial.println(); 157 | 158 | lcd.setCursor(0, 2); 159 | lcd.print(F("Accuracy: ")); 160 | lcd.print((String)myGPS.svin.meanAccuracy); 161 | } 162 | else 163 | { 164 | Serial.println(F("SVIN request failed")); 165 | } 166 | 167 | delay(1000); 168 | } 169 | Serial.println(F("Survey valid!")); 170 | 171 | Serial.println(F("Base survey complete! RTCM now broadcasting.")); 172 | lcd.clear(); 173 | lcd.print(F("Transmitting RTCM")); 174 | 175 | myGPS.setI2COutput(COM_TYPE_UBX | COM_TYPE_RTCM3); //Set the I2C port to output UBX and RTCM sentences (not really an option, turns on NMEA as well) 176 | 177 | } 178 | 179 | void loop() 180 | { 181 | myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. 182 | 183 | //Do anything you want. Call checkUblox() every second. ZED-F9P has TX buffer of 4k bytes. 184 | 185 | delay(250); //Don't pound too hard on the I2C bus 186 | } 187 | 188 | //This function gets called from the SparkFun Ublox Arduino Library. 189 | //As each RTCM byte comes in you can specify what to do with it 190 | //Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc. 191 | void SFE_UBLOX_GPS::processRTCM(uint8_t incoming) 192 | { 193 | //Let's just pretty-print the HEX values for now 194 | if (myGPS.rtcmFrameCounter % 16 == 0) 195 | Serial.println(); 196 | Serial.print(" "); 197 | if (incoming < 0x10) 198 | Serial.print("0"); 199 | Serial.print(incoming, HEX); 200 | } 201 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example5_RelativePositioningInformation/Example5_RelativePositioningInformation.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on Ublox ZED-F9P module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: January 9th, 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 query the module for RELPOS information in the NED frame. 10 | It assumes you already have RTCM correction data being fed to the receiver. 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 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 16 | SAM-M8Q: https://www.sparkfun.com/products/15106 17 | 18 | Hardware Connections: 19 | Plug a Qwiic cable into the GPS and a RedBoard Qwiic or BlackBoard 20 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 21 | Open the serial monitor at 115200 baud to see the output 22 | */ 23 | 24 | #include //Needed for I2C to GPS 25 | 26 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 27 | SFE_UBLOX_GPS myGPS; 28 | 29 | //#define USE_SERIAL1 // Uncomment this line to push the RTCM data from Serial1 to the module via I2C 30 | 31 | size_t numBytes = 0; // Record the number os bytes received from Serial1 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | while (!Serial); //Wait for user to open terminal 37 | Serial.println("Ublox Base station example"); 38 | 39 | #ifdef USE_SERIAL1 40 | // If our board supports it, we can receive the RTCM data on Serial1 41 | Serial1.begin(115200); 42 | #endif 43 | 44 | Wire.begin(); 45 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 46 | 47 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 48 | { 49 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); 50 | while (1); 51 | } 52 | 53 | // Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate 54 | //myGPS.factoryDefault(); delay(5000); 55 | 56 | #ifdef USE_SERIAL1 57 | Serial.print(F("Enabling UBX and RTCM input on I2C. Result: ")); 58 | Serial.print(myGPS.setPortInput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_RTCM3)); //Enable UBX and RTCM input on I2C 59 | myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR 60 | #endif 61 | } 62 | 63 | void loop() 64 | { 65 | if (myGPS.getRELPOSNED() == true) 66 | { 67 | Serial.print("relPosN: "); 68 | Serial.println(myGPS.relPosInfo.relPosN, 4); 69 | Serial.print("relPosE: "); 70 | Serial.println(myGPS.relPosInfo.relPosE, 4); 71 | Serial.print("relPosD: "); 72 | Serial.println(myGPS.relPosInfo.relPosD, 4); 73 | 74 | Serial.print("relPosLength: "); 75 | Serial.println(myGPS.relPosInfo.relPosLength); 76 | Serial.print("relPosHeading: "); 77 | Serial.println(myGPS.relPosInfo.relPosHeading); 78 | 79 | Serial.print("relPosHPN: "); 80 | Serial.println(myGPS.relPosInfo.relPosHPN); 81 | Serial.print("relPosHPE: "); 82 | Serial.println(myGPS.relPosInfo.relPosHPE); 83 | Serial.print("relPosHPD: "); 84 | Serial.println(myGPS.relPosInfo.relPosHPD); 85 | Serial.print("relPosHPLength: "); 86 | Serial.println(myGPS.relPosInfo.relPosHPLength); 87 | 88 | Serial.print("accN: "); 89 | Serial.println(myGPS.relPosInfo.accN, 4); 90 | Serial.print("accE: "); 91 | Serial.println(myGPS.relPosInfo.accE, 4); 92 | Serial.print("accD: "); 93 | Serial.println(myGPS.relPosInfo.accD, 4); 94 | 95 | Serial.print("gnssFixOk: "); 96 | if (myGPS.relPosInfo.gnssFixOk == true) 97 | Serial.println("x"); 98 | else 99 | Serial.println(""); 100 | 101 | Serial.print("diffSolution: "); 102 | if (myGPS.relPosInfo.diffSoln == true) 103 | Serial.println("x"); 104 | else 105 | Serial.println(""); 106 | 107 | Serial.print("relPosValid: "); 108 | if (myGPS.relPosInfo.relPosValid == true) 109 | Serial.println("x"); 110 | else 111 | Serial.println(""); 112 | 113 | Serial.print("carrier Solution Type: "); 114 | if (myGPS.relPosInfo.carrSoln == 0) 115 | Serial.println("None"); 116 | else if (myGPS.relPosInfo.carrSoln == 1) 117 | Serial.println("Float"); 118 | else if (myGPS.relPosInfo.carrSoln == 2) 119 | Serial.println("Fixed"); 120 | 121 | Serial.print("isMoving: "); 122 | if (myGPS.relPosInfo.isMoving == true) 123 | Serial.println("x"); 124 | else 125 | Serial.println(""); 126 | 127 | Serial.print("refPosMiss: "); 128 | if (myGPS.relPosInfo.refPosMiss == true) 129 | Serial.println("x"); 130 | else 131 | Serial.println(""); 132 | 133 | Serial.print("refObsMiss: "); 134 | if (myGPS.relPosInfo.refObsMiss == true) 135 | Serial.println("x"); 136 | else 137 | Serial.println(""); 138 | } 139 | else 140 | Serial.println("RELPOS request failed"); 141 | 142 | for (int i = 0; i < 500; i++) 143 | { 144 | #ifdef USE_SERIAL1 145 | uint8_t store[256]; 146 | while ((Serial1.available()) && (numBytes < 256)) // Check if data has been received 147 | { 148 | store[numBytes++] = Serial1.read(); // Read a byte from Serial1 and store it 149 | } 150 | if (numBytes > 0) // Check if data was received 151 | { 152 | //Serial.print("Pushing "); 153 | //Serial.print(numBytes); 154 | //Serial.println(" bytes via I2C"); 155 | myGPS.pushRawData(((uint8_t *)&store), numBytes); // Push the RTCM data via I2C 156 | numBytes = 0; // Reset numBytes 157 | } 158 | #endif 159 | delay(10); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example6_GetVal/Example6_GetVal.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Get a device's I2C address using advanced getVal method 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: January 9th, 2019 6 | License: MIT. See license file for more information but you can 7 | basically do whatever you want with this code. 8 | 9 | u-blox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the 10 | UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL 11 | commands instead. This example shows how to use this new command structure. 12 | 13 | Feel like supporting open source hardware? 14 | Buy a board from SparkFun! 15 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 16 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 17 | SAM-M8Q: https://www.sparkfun.com/products/15106 18 | 19 | Hardware Connections: 20 | Plug a Qwiic cable into the GPS and a RedBoard Qwiic or BlackBoard 21 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 22 | Open the serial monitor at 115200 baud to see the output 23 | */ 24 | 25 | #include //Needed for I2C to GPS 26 | 27 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | while (!Serial) 36 | ; //Wait for user to open terminal 37 | Serial.println("u-blox getVal example"); 38 | 39 | Wire.begin(); 40 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 41 | 42 | if (myGPS.begin() == false) //Connect to the Ublox module using Wire port 43 | { 44 | Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); 45 | while (1) 46 | ; 47 | } 48 | 49 | myGPS.enableDebugging(); //Enable debug messages over Serial (default) 50 | //myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB 51 | 52 | uint8_t currentI2Caddress = myGPS.getVal8(UBLOX_CFG_I2C_ADDRESS); 53 | Serial.print("Current I2C address (should be 0x42): 0x"); 54 | Serial.println(currentI2Caddress >> 1, HEX); //Ublox module returns a shifted 8-bit address. Make it 7-bit unshifted. 55 | 56 | while (1) 57 | ; 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 | byte SIV = myGPS.getSIV(); 83 | Serial.print(F(" SIV: ")); 84 | Serial.print(SIV); 85 | 86 | Serial.println(); 87 | } 88 | } -------------------------------------------------------------------------------- /examples/ZED-F9P/Example7_SetVal/Example7_SetVal.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on u-blox ZED-F9P module 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: January 9th, 2019 6 | License: MIT. See license file for more information but you can 7 | basically do whatever you want with this code. 8 | 9 | u-blox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the 10 | UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL 11 | commands instead. This example shows how to use this new command structure. 12 | 13 | Feel like supporting open source hardware? 14 | Buy a board from SparkFun! 15 | ZED-F9P RTK2: https://www.sparkfun.com/products/15136 16 | NEO-M8P RTK: https://www.sparkfun.com/products/15005 17 | SAM-M8Q: https://www.sparkfun.com/products/15106 18 | 19 | Hardware Connections: 20 | Plug a Qwiic cable into the GPS and a RedBoard Qwiic or BlackBoard 21 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 22 | Open the serial monitor at 115200 baud to see the output 23 | */ 24 | 25 | #include //Needed for I2C to GPS 26 | 27 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 28 | SFE_UBLOX_GPS myGPS; 29 | 30 | long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module. 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | while (!Serial) 36 | ; //Wait for user to open terminal 37 | Serial.println("u-blox getVal example"); 38 | 39 | Wire.begin(); 40 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 41 | 42 | if (myGPS.begin() == false) //Connect to the u-blox module using Wire port 43 | { 44 | Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); 45 | while (1) 46 | ; 47 | } 48 | 49 | myGPS.enableDebugging(); //Enable debug messages over Serial (default) 50 | //myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB 51 | 52 | bool setValueSuccess; 53 | 54 | //These key values are hard coded and defined in u-blox_config_keys.h. 55 | //You can obtain them from the ZED-F9P interface description doc 56 | //or from u-center's Messages->CFG->VALSET window. Keys must be 32-bit. 57 | //setValueSuccess = myGPS.setVal(UBLOX_CFG_NMEA_HIGHPREC, 0); //Enable high precision NMEA 58 | setValueSuccess = myGPS.setVal(UBLOX_CFG_RATE_MEAS, 100); //Set measurement rate to 100ms (10Hz update rate) 59 | //setValueSuccess = myGPS.setVal(UBLOX_CFG_RATE_MEAS, 1000); //Set measurement rate to 1000ms (1Hz update rate) 60 | 61 | //Below is the original way we enabled the RTCM message on the I2C port. After that, we show how to do the same 62 | //but with setVal(). 63 | //Original: myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 64 | //setValueSuccess = myGPS.setVal(0x209102bd, 1); //Set output rate of msg 1005 over the I2C port to once per second 65 | 66 | if (setValueSuccess == true) 67 | { 68 | Serial.println("Value was successfully set"); 69 | } 70 | else 71 | Serial.println("Value set failed"); 72 | } 73 | 74 | void loop() 75 | { 76 | } 77 | -------------------------------------------------------------------------------- /examples/ZED-F9P/Example8_GetSetPortSettings/Example8_GetSetPortSettings.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Configuring port settings using the newer getVal/setVal methods 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: October 23rd, 2020 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 query a u-blox module for its UART1 settings and 10 | then change them if the settings aren't what we want. 11 | 12 | Note: getVal/setVal/delVal are only support in u-blox protocol versions 27 and higher. 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 | 18 | Hardware Connections: 19 | Plug a Qwiic cable into the GPS and a RedBoard 20 | If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) 21 | Open the serial monitor at 115200 baud to see the output 22 | */ 23 | 24 | #include //Needed for I2C to GPS 25 | 26 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 27 | SFE_UBLOX_GPS myGPS; 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | while (!Serial) 33 | ; //Wait for user to open terminal 34 | Serial.println("SparkFun u-blox Example"); 35 | 36 | Wire.begin(); 37 | 38 | if (myGPS.begin() == false) //Connect to the u-blox module using Wire port 39 | { 40 | Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); 41 | while (1) 42 | ; 43 | } 44 | 45 | bool response = true; 46 | 47 | //Read the settings from RAM (what the module is running right now, not BBR, Flash, or default) 48 | uint8_t currentUART1Setting_ubx = myGPS.getVal8(UBLOX_CFG_UART1INPROT_UBX); 49 | uint8_t currentUART1Setting_nmea = myGPS.getVal8(UBLOX_CFG_UART1INPROT_NMEA); 50 | uint8_t currentUART1Setting_rtcm3 = myGPS.getVal8(UBLOX_CFG_UART1INPROT_RTCM3X); 51 | 52 | Serial.print("currentUART1Setting_ubx: "); 53 | Serial.println(currentUART1Setting_ubx); 54 | Serial.print("currentUART1Setting_nmea: "); 55 | Serial.println(currentUART1Setting_nmea); 56 | Serial.print("currentUART1Setting_rtcm3: "); 57 | Serial.println(currentUART1Setting_rtcm3); 58 | 59 | //Check if NMEA and RTCM are enabled for UART1 60 | if (currentUART1Setting_ubx == 0 || currentUART1Setting_nmea == 0) 61 | { 62 | Serial.println("Updating UART1 configuration"); 63 | 64 | //setVal sets the values for RAM, BBR, and Flash automatically so no .saveConfiguration() is needed 65 | response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_UBX, 1); //Enable UBX on UART1 Input 66 | response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_NMEA, 1); //Enable NMEA on UART1 Input 67 | response &= myGPS.setVal8(UBLOX_CFG_UART1INPROT_RTCM3X, 0); //Disable RTCM on UART1 Input 68 | 69 | if (response == false) 70 | Serial.println("SetVal failed"); 71 | else 72 | Serial.println("SetVal succeeded"); 73 | } 74 | else 75 | Serial.println("No port change needed"); 76 | 77 | //Change speed of UART2 78 | uint32_t currentUART2Baud = myGPS.getVal32(UBLOX_CFG_UART2_BAUDRATE); 79 | Serial.print("currentUART2Baud: "); 80 | Serial.println(currentUART2Baud); 81 | 82 | if (currentUART2Baud != 57600) 83 | { 84 | response &= myGPS.setVal32(UBLOX_CFG_UART2_BAUDRATE, 57600); 85 | if (response == false) 86 | Serial.println("SetVal failed"); 87 | else 88 | Serial.println("SetVal succeeded"); 89 | } 90 | else 91 | Serial.println("No baud change needed"); 92 | 93 | Serial.println("Done"); 94 | } 95 | 96 | void loop() 97 | { 98 | } -------------------------------------------------------------------------------- /examples/ZED-F9P/Example9_multiSetVal/Example9_multiSetVal.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Send UBX binary commands to enable RTCM sentences on u-blox ZED-F9P module 3 | Based on Example7 By: Nathan Seidle 4 | SparkFun Electronics 5 | Updated by Paul Clark to demonstrate setVal8/16/32, newCfgValset8/16/32, addCfgValset8/16/32 and sendCfgValset8/16/32 6 | Date: July 1st, 2019 7 | License: MIT. See license file for more information but you can 8 | basically do whatever you want with this code. 9 | 10 | u-blox changed how to configure their modules in 2019. As of version 23 of the UBX protocol the 11 | UBX-CFG commands are deprecated; they still work, they just recommend using VALSET, VALGET, and VALDEL 12 | commands instead. This example shows how to use this new command structure. 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 GPS and a RedBoard Qwiic or 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 //Needed for I2C to GPS 27 | 28 | #include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS 29 | SFE_UBLOX_GPS myGPS; 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | while (!Serial) 35 | ; //Wait for user to open terminal 36 | Serial.println("u-blox multi setVal example"); 37 | 38 | Wire.begin(); 39 | Wire.setClock(400000); //Increase I2C clock speed to 400kHz 40 | 41 | if (myGPS.begin() == false) //Connect to the u-blox module using Wire port 42 | { 43 | Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); 44 | while (1) 45 | ; 46 | } 47 | 48 | myGPS.enableDebugging(); //Enable debug messages over Serial (default) 49 | //myGPS.enableDebugging(SerialUSB); //Enable debug messages over Serial USB 50 | 51 | bool setValueSuccess = true; 52 | 53 | //These key values are hard coded. You can obtain them from the ZED-F9P interface description doc 54 | //or from u-center's Messages->CFG->VALSET window. Keys must be 32-bit. 55 | //Choose setVal8, setVal16 or setVal32 depending on the required value data width (1, 2 or 4 bytes) 56 | //L, U1, I1, E1 and X1 values are 8-bit 57 | //U2, I2, E2 and X2 values are 16-bit 58 | //U4, I4, R4, E4, X4 values are 32-bit 59 | 60 | setValueSuccess &= myGPS.setVal8(UBLOX_CFG_NMEA_HIGHPREC, 0); //Enable high precision NMEA (value is 8-bit (L / U1)) 61 | //setValueSuccess &= myGPS.setVal16(UBLOX_CFG_RATE_MEAS, 200); //Set measurement rate to 100ms (10Hz update rate) (value is 16-bit (U2)) 62 | //setValueSuccess &= myGPS.setVal16(UBLOX_CFG_RATE_MEAS, 200, 1); //Set rate setting in RAM instead of BBR 63 | setValueSuccess &= myGPS.setVal16(UBLOX_CFG_RATE_MEAS, 1000); //Set measurement rate to 1000ms (1Hz update rate) (value is 16-bit (U2)) 64 | 65 | //Below is the original way we enabled a single RTCM message on the I2C port. After that, we show how to do the same 66 | //but with multiple messages all in one go using newCfgValset, addCfgValset and sendCfgValset. 67 | //Original: myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second 68 | 69 | //Begin with newCfgValset8/16/32 70 | setValueSuccess &= myGPS.newCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1); //Set output rate of msg 1005 over the I2C port to once per measurement (value is 8-bit (U1)) 71 | //setValueSuccess &= myGPS.newCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1, VAL_LAYER_RAM); //Set this and the following settings in RAM only instead of Flash/RAM/BBR 72 | //Add extra keyIDs and values using addCfgValset8/16/32 73 | setValueSuccess &= myGPS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1077_I2C, 1); //Set output rate of msg 1077 over the I2C port to once per measurement (value is 8-bit (U1)) 74 | setValueSuccess &= myGPS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1087_I2C, 1); //Set output rate of msg 1087 over the I2C port to once per measurement (value is 8-bit (U1)) 75 | setValueSuccess &= myGPS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1127_I2C, 1); //Set output rate of msg 1127 over the I2C port to once per measurement (value is 8-bit (U1)) 76 | setValueSuccess &= myGPS.addCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1097_I2C, 1); //Set output rate of msg 1097 over the I2C port to once per measurement (value is 8-bit (U1)) 77 | // Add the final value and send the packet using sendCfgValset8/16/32 78 | setValueSuccess &= myGPS.sendCfgValset8(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 10); //Set output rate of msg 1230 over the I2C port to once every 10 measurements (value is 8-bit (U1)) 79 | 80 | if (setValueSuccess == true) 81 | { 82 | Serial.println("Values were successfully set"); 83 | } 84 | else 85 | Serial.println("Value set failed"); 86 | } 87 | 88 | void loop() 89 | { 90 | } 91 | -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | cmake_minimum_required(VERSION 3.13.1) 4 | 5 | find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) 6 | project(sparkfun_ublox_zephyr_library) 7 | 8 | zephyr_compile_options(-fdiagnostics-color=always) 9 | 10 | zephyr_include_directories(.) 11 | target_sources(app PRIVATE src/SparkFun_Ublox_Zephyr_Library.cpp) 12 | target_sources(app PRIVATE src/SparkFun_Ublox_Zephyr_Interface.cpp) 13 | 14 | target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c) 15 | -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/nrf52840dk_nrf52840.overlay: -------------------------------------------------------------------------------- 1 | &i2c0 { 2 | status = "okay"; 3 | compatible = "nordic,nrf-twim"; 4 | }; -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | #turn on c++ support 2 | CONFIG_CPLUSPLUS=y 3 | 4 | # turn on peripherals 5 | CONFIG_GPIO=y 6 | CONFIG_I2C=y 7 | CONFIG_I2C_0=y 8 | -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/src/SparkFun_Ublox_Zephyr_Interface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is an interface that connects the CPP Ublox library with the main C code. 3 | Added to make it possible to run Ublox lib on Zephyr (NCS) 4 | 5 | This port was made by Vid Rajtmajer , www.irnas.eu 6 | */ 7 | #include "SparkFun_Ublox_Zephyr_Interface.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "SparkFun_Ublox_Zephyr_Library.h" 15 | 16 | 17 | SFE_UBLOX_GPS myGPS; // driver class instance 18 | long lastTime = 0; // Simple local timer. Limits amount if I2C traffic to Ublox module. 19 | 20 | // init GPIO checksumFailurePin and load GPIO device pointer to the driver 21 | uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug) 22 | { 23 | if (myGPS.init_gpio_pins(*gpio_dev) == false) 24 | { 25 | return -EIO; 26 | } 27 | // turn on debugging if enable_debug is set 28 | if (enable_debug) 29 | { 30 | myGPS.enableDebugging(); 31 | } 32 | return 0; 33 | } 34 | 35 | // initialize I2C and check if GPS device respons 36 | uint8_t gps_begin(struct device *i2c_dev) 37 | { 38 | if (myGPS.begin(*i2c_dev) == false) 39 | { 40 | return -EIO; 41 | } 42 | return 0; 43 | } 44 | 45 | // This will pipe all NMEA sentences to UART so we can see them 46 | void pipe_nmea_sentences(void) 47 | { 48 | myGPS.setNMEAOutputPort(); 49 | } 50 | 51 | // Check for available bytes from the device 52 | void check_ublox(void) 53 | { 54 | myGPS.checkUblox(); 55 | } 56 | 57 | // Get position information when requested, also display number of satellites used in the fix 58 | int get_position(void) 59 | { 60 | //Query module only every second. Doing it more often will just cause I2C traffic. 61 | //The module only responds when a new position is available, print it to console 62 | if (k_uptime_get_32() - lastTime > 1000) 63 | { 64 | lastTime = k_uptime_get_32(); //Update the timer 65 | 66 | long latitude = myGPS.getLatitude(); 67 | long longitude = myGPS.getLongitude(); 68 | long altitude = myGPS.getAltitude(); 69 | uint8_t SIV = myGPS.getSIV(); 70 | 71 | printk("Position: Lat: %ld, Lon: %ld, Alt: %ld, SIV: %d", latitude, longitude, altitude, SIV); 72 | return 0; 73 | } 74 | return -EBUSY; 75 | } 76 | 77 | // Get date and time information when requested, check if they are valid and print info to console, it returns UNIX time 78 | void get_datetime(void) 79 | { 80 | int year = myGPS.getYear(); 81 | int month = myGPS.getMonth(); 82 | int day = myGPS.getDay(); 83 | int hour = myGPS.getHour(); 84 | int minute = myGPS.getMinute(); 85 | int second = myGPS.getSecond(); 86 | 87 | printk("DateTime: %d-%d-%d %d:%d:%d\n", year, month, day, hour, minute, second); 88 | 89 | printk("Time is "); 90 | if (myGPS.getTimeValid() == false) 91 | { 92 | printk("not "); 93 | } 94 | printk("valid. Date is "); 95 | if (myGPS.getDateValid() == false) 96 | { 97 | printk("not "); 98 | } 99 | printk("valid.\n"); 100 | } 101 | -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/src/SparkFun_Ublox_Zephyr_Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | This is an interface that connects the CPP Ublox library with the main C code. 3 | Added to make it possible to run Ublox lib on Zephyr (NCS) 4 | 5 | This port was made by Vid Rajtmajer , www.irnas.eu 6 | */ 7 | #include 8 | #include 9 | 10 | #ifndef _UBLOX_LIB_INTERFACE_H_ 11 | #define _UBLOX_LIB_INTERFACE_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug); // init GPIO 18 | uint8_t gps_begin(struct device *i2c_dev); // initialize I2C and check if GPS device respons 19 | void pipe_nmea_sentences(void); // print NMEA sentences 20 | 21 | void check_ublox(void); // Check for available bytes from the device 22 | int get_position(void); // Get position information 23 | void get_datetime(void); // Get date and time information 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif //UBLOX_LIB_INTERFACE_H_ -------------------------------------------------------------------------------- /examples/Zephyr/Example1_GetPositionAndTime_Zephyr/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Reading lat, long and UTC time via UBX binary commands 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: August 22nd, 2018 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 reads the NMEA setences from the Ublox module over I2c and outputs 10 | them to the serial port 11 | 12 | Open the serial monitor at 115200 baud to see the output 13 | I2C clock speed: 100 kHz 14 | 15 | Ported to Zephyr by Vid Rajtmajer , www.irnas.eu 16 | 17 | Development environment specifics: NCS v1.0.3 release 18 | 19 | To build: west build -b -p Can also read NMEA sentences over I2C with check_ublox function 20 | To flash: west flash --erase 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "SparkFun_Ublox_Zephyr_Interface.h" 29 | 30 | 31 | #define I2C_DEV "I2C_0" 32 | 33 | struct device *gpio_dev; 34 | struct device *i2c_dev; 35 | /* I2C pins used are defaults for I2C_0 on nrf52840 36 | SDA: 26 37 | SCL: 27 38 | */ 39 | 40 | uint8_t init_gpio(void) { 41 | const char* gpioName = "GPIO_0"; 42 | gpio_dev = device_get_binding(gpioName); 43 | if (gpio_dev == NULL) { 44 | printk("Error: Could not get %s device\n", gpioName); 45 | return -EIO; 46 | } 47 | int err = set_gpio_dev(gpio_dev, true); // set GPIO_0 device and enable debugging 48 | if (err) { 49 | return -EIO; 50 | } 51 | return 0; 52 | } 53 | 54 | uint8_t init_i2c(void) { 55 | i2c_dev = device_get_binding(I2C_DEV); 56 | if (!i2c_dev) 57 | { 58 | printk("I2C_0 error\n"); 59 | return -1; 60 | } 61 | else 62 | { 63 | printk("I2C_0 Init OK\n"); 64 | return 0; 65 | } 66 | } 67 | 68 | uint8_t init_gps(void) { 69 | if (gps_begin(i2c_dev) != 0) 70 | { 71 | printk("Ublox GPS init error!\n"); 72 | return -1; 73 | } 74 | return 0; 75 | } 76 | 77 | 78 | void main(void) { 79 | printk("Zephyr Ublox example\n"); 80 | 81 | int err; 82 | err = init_gpio(); 83 | if (err) { 84 | return; 85 | } 86 | err = init_i2c(); 87 | if (err) { 88 | return; 89 | } 90 | 91 | err = init_gps(); 92 | if (err) { 93 | return; 94 | } 95 | 96 | while(1) { 97 | //check_ublox(); // See if new data is available. Process bytes as they come in. 98 | get_position(); 99 | get_datetime(); 100 | k_msleep(250); // Don't pound too hard on the I2C bus 101 | } 102 | } -------------------------------------------------------------------------------- /img/Contributing.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/SparkFun_Ublox_Arduino_Library/1e70755453a898d8267ced641500c33d377409b7/img/Contributing.JPG -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SFE_UBLOX_GPS KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | isConnected KEYWORD2 17 | checkUblox KEYWORD2 18 | checkUbloxI2C KEYWORD2 19 | checkUbloxSerial KEYWORD2 20 | 21 | process KEYWORD2 22 | processUBX KEYWORD2 23 | processRTCMframe KEYWORD2 24 | processRTCM KEYWORD2 25 | processUBXpacket KEYWORD2 26 | processNMEA KEYWORD2 27 | 28 | calcChecksum KEYWORD2 29 | sendCommand KEYWORD2 30 | printPacket KEYWORD2 31 | setI2CAddress KEYWORD2 32 | setSerialRate KEYWORD2 33 | setNMEAOutputPort KEYWORD2 34 | 35 | setNavigationFrequency KEYWORD2 36 | getNavigationFrequency KEYWORD2 37 | 38 | saveConfiguration KEYWORD2 39 | factoryDefault KEYWORD2 40 | saveConfigSelective KEYWORD2 41 | 42 | waitForResponse KEYWORD2 43 | 44 | getPVT KEYWORD2 45 | getLatitude KEYWORD2 46 | getLongitude KEYWORD2 47 | getAltitude KEYWORD2 48 | getAltitudeMSL KEYWORD2 49 | getSIV KEYWORD2 50 | getFixType KEYWORD2 51 | getCarrierSolutionType KEYWORD2 52 | getGroundSpeed KEYWORD2 53 | getHeading KEYWORD2 54 | getPDOP KEYWORD2 55 | getTimeOfWeek KEYWORD2 56 | getHorizontalAccEst KEYWORD2 57 | getVerticalAccEst KEYWORD2 58 | getNedNorthVel KEYWORD2 59 | getNedEastVel KEYWORD2 60 | getNedDownVel KEYWORD2 61 | getSpeedAccEst KEYWORD2 62 | getHeadingAccEst KEYWORD2 63 | getInvalidLlh KEYWORD2 64 | getHeadVeh KEYWORD2 65 | getMagDec KEYWORD2 66 | getMagAcc KEYWORD2 67 | getHeadVehValid KEYWORD2 68 | 69 | setPortOutput KEYWORD2 70 | setPortInput KEYWORD2 71 | getPortSettings KEYWORD2 72 | 73 | setI2COutput KEYWORD2 74 | setUART1Output KEYWORD2 75 | setUART2Output KEYWORD2 76 | setUSBOutput KEYWORD2 77 | setSPIOutput KEYWORD2 78 | 79 | getVal KEYWORD2 80 | getVal8 KEYWORD2 81 | getVal16 KEYWORD2 82 | getVal32 KEYWORD2 83 | setVal KEYWORD2 84 | setVal8 KEYWORD2 85 | setVal16 KEYWORD2 86 | setVal32 KEYWORD2 87 | newCfgValset8 KEYWORD2 88 | newCfgValset16 KEYWORD2 89 | newCfgValset32 KEYWORD2 90 | addCfgValset8 KEYWORD2 91 | addCfgValset16 KEYWORD2 92 | addCfgValset32 KEYWORD2 93 | sendCfgValset8 KEYWORD2 94 | sendCfgValset16 KEYWORD2 95 | sendCfgValset32 KEYWORD2 96 | 97 | getSurveyMode KEYWORD2 98 | setSurveyMode KEYWORD2 99 | enableSurveyMode KEYWORD2 100 | disableSurveyMode KEYWORD2 101 | getSurveyStatus KEYWORD2 102 | 103 | enableRTCMmessage KEYWORD2 104 | disableRTCMmessage KEYWORD2 105 | 106 | getPositionAccuracy KEYWORD2 107 | 108 | getProtocolVersionHigh KEYWORD2 109 | getProtocolVersionLow KEYWORD2 110 | getProtocolVersion KEYWORD2 111 | 112 | getRELPOSNED KEYWORD2 113 | 114 | enableDebugging KEYWORD2 115 | disableDebugging KEYWORD2 116 | debugPrint KEYWORD2 117 | debugPrintln KEYWORD2 118 | 119 | factoryReset KEYWORD2 120 | setAutoPVT KEYWORD2 121 | assumeAutoPVT KEYWORD2 122 | flushPVT KEYWORD2 123 | 124 | getYear KEYWORD2 125 | getMonth KEYWORD2 126 | getDay KEYWORD2 127 | getHour KEYWORD2 128 | getMinute KEYWORD2 129 | getSecond KEYWORD2 130 | getMillisecond KEYWORD2 131 | getNanosecond KEYWORD2 132 | getDateValid KEYWORD2 133 | getTimeValid KEYWORD2 134 | 135 | getHPPOSLLH KEYWORD2 136 | assumeAutoHPPOSLLH KEYWORD2 137 | setAutoHPPOSLLH KEYWORD2 138 | flushHPPOSLLH KEYWORD2 139 | 140 | getTimeOfWeek KEYWORD2 141 | getHighResLatitude KEYWORD2 142 | getHighResLatitudeHp KEYWORD2 143 | getHighResLongitude KEYWORD2 144 | getHighResLongitudeHp KEYWORD2 145 | getElipsoid KEYWORD2 146 | getElipsoidHp KEYWORD2 147 | getMeanSeaLevel KEYWORD2 148 | getMeanSeaLevelHp KEYWORD2 149 | getGeoidSeparation KEYWORD2 150 | getHorizontalAccuracy KEYWORD2 151 | getVerticalAccuracy KEYWORD2 152 | 153 | addGeofence KEYWORD2 154 | clearGeofences KEYWORD2 155 | getGeofenceState KEYWORD2 156 | 157 | setDynamicModel KEYWORD2 158 | getDynamicModel KEYWORD2 159 | powerSaveMode KEYWORD2 160 | getPowerSaveMode KEYWORD2 161 | powerOff KEYWORD2 162 | powerOffWithInterrupt KEYWORD2 163 | 164 | configureMessage KEYWORD2 165 | enableMessage KEYWORD2 166 | disableMessage KEYWORD2 167 | enableNMEAMessage KEYWORD2 168 | disableNMEAMessage KEYWORD2 169 | 170 | getEsfInfo KEYWORD2 171 | getEsfIns KEYWORD2 172 | getEsfDataInfo KEYWORD2 173 | getEsfRawDataInfo KEYWORD2 174 | 175 | getSensState KEYWORD2 176 | getVehAtt KEYWORD2 177 | 178 | setI2CTransactionSize KEYWORD2 179 | getI2CTransactionSize KEYWORD2 180 | 181 | setStaticPosition KEYWORD2 182 | 183 | pushRawData KEYWORD2 184 | 185 | setHNRNavigationRate KEYWORD2 186 | getHNRNavigationRate KEYWORD2 187 | assumeAutoHNRAtt KEYWORD2 188 | setAutoHNRAtt KEYWORD2 189 | getHNRAtt KEYWORD2 190 | assumeAutoHNRDyn KEYWORD2 191 | setAutoHNRDyn KEYWORD2 192 | getHNRDyn KEYWORD2 193 | assumeAutoHNRPVT KEYWORD2 194 | setAutoHNRPVT KEYWORD2 195 | getHNRPVT KEYWORD2 196 | 197 | ####################################### 198 | # Constants (LITERAL1) 199 | ####################################### 200 | 201 | COM_TYPE_UBX LITERAL1 202 | COM_TYPE_NMEA LITERAL1 203 | COM_TYPE_RTCM3 LITERAL1 204 | 205 | COM_PORT_I2C LITERAL1 206 | COM_PORT_UART1 LITERAL1 207 | COM_PORT_UART2 LITERAL1 208 | COM_PORT_USB LITERAL1 209 | COM_PORT_SPI LITERAL1 210 | 211 | UBX_CLASS_NAV LITERAL1 212 | UBX_CLASS_RXM LITERAL1 213 | UBX_CLASS_INF LITERAL1 214 | UBX_CLASS_ACK LITERAL1 215 | UBX_CLASS_CFG LITERAL1 216 | UBX_CLASS_UPD LITERAL1 217 | UBX_CLASS_MON LITERAL1 218 | UBX_CLASS_AID LITERAL1 219 | UBX_CLASS_TIM LITERAL1 220 | UBX_CLASS_ESF LITERAL1 221 | UBX_CLASS_MGA LITERAL1 222 | UBX_CLASS_LOG LITERAL1 223 | UBX_CLASS_SEC LITERAL1 224 | UBX_CLASS_HNR LITERAL1 225 | UBX_CLASS_NMEA LITERAL1 226 | 227 | UBX_NMEA_GGA LITERAL1 228 | UBX_NMEA_GLL LITERAL1 229 | UBX_NMEA_GNS LITERAL1 230 | UBX_NMEA_GRS LITERAL1 231 | UBX_NMEA_GSA LITERAL1 232 | UBX_NMEA_GST LITERAL1 233 | UBX_NMEA_GSV LITERAL1 234 | UBX_NMEA_RMC LITERAL1 235 | UBX_NMEA_VTG LITERAL1 236 | UBX_NMEA_ZDA LITERAL1 237 | 238 | UBX_NAV_PVT LITERAL1 239 | UBX_NAV_HPPOSECEF LITERAL1 240 | UBX_NAV_HPPOSLLH LITERAL1 241 | UBX_NAV_SVIN LITERAL1 242 | UBX_NAV_RELPOSNED LITERAL1 243 | 244 | UBX_RTCM_MSB LITERAL1 245 | UBX_RTCM_1005 LITERAL1 246 | UBX_RTCM_1074 LITERAL1 247 | UBX_RTCM_1077 LITERAL1 248 | UBX_RTCM_1084 LITERAL1 249 | UBX_RTCM_1087 LITERAL1 250 | UBX_RTCM_1094 LITERAL1 251 | UBX_RTCM_1097 LITERAL1 252 | UBX_RTCM_1124 LITERAL1 253 | UBX_RTCM_1127 LITERAL1 254 | UBX_RTCM_1230 LITERAL1 255 | UBX_RTCM_4072_0 LITERAL1 256 | UBX_RTCM_4072_1 LITERAL1 257 | 258 | DYN_MODEL_PORTABLE LITERAL1 259 | DYN_MODEL_STATIONARY LITERAL1 260 | DYN_MODEL_PEDESTRIAN LITERAL1 261 | DYN_MODEL_AUTOMOTIVE LITERAL1 262 | DYN_MODEL_SEA LITERAL1 263 | DYN_MODEL_AIRBORNE1g LITERAL1 264 | DYN_MODEL_AIRBORNE2g LITERAL1 265 | DYN_MODEL_AIRBORNE4g LITERAL1 266 | DYN_MODEL_WRIST LITERAL1 267 | DYN_MODEL_BIKE LITERAL1 268 | 269 | UBX_ESF_STATUS LITERAL1 270 | UBX_ESF_RAW LITERAL1 271 | UBX_ESF_MEAS LITERAL1 272 | UBX_ESF_INS LITERAL1 273 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SparkFun u-blox Arduino Library 2 | version=1.8.11 3 | author=SparkFun Electronics 4 | maintainer=SparkFun Electronics 5 | sentence=DEPRECATED Library for I2C and Serial Communication with u-blox modules

6 | paragraph=Please note: this library is deprecated. Please migrate to v2.0. You can find the migration instructions here.

An Arduino Library to enable both I2C and Serial communication for both NMEA reception and binary UBX sending to u-blox modules. Useful for interfacing to the SparkFun GPS-RTK2 ZED-F9P, SparkFun GPS-RTK NEO-M8P-2, the SparkFun SAM-M8Q, and the SparkFun ZOE-M8Q. Library also works with other u-blox based boards.

The ZED-F9P and NEO-M8P-2 modules are top-of-the-line modules for high accuracy GNSS and GPS location solutions including RTK. The ZED-F9P is unique in that it is capable of both rover and base station operations allowing the module to become a base station and produce RTCM 3.x correction data.
7 | category=Sensors 8 | url=https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library 9 | architectures=* 10 | --------------------------------------------------------------------------------