|
| 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 configure the library and U-Blox for serial port use as well as |
| 9 | + switching the module from the default 9600 baud to 38400. |
| 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 10,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 | + Connect the U-Blox serial port to Serial1 |
| 25 | + Open the serial monitor at 115200 baud to see the output |
| 26 | +*/ |
| 27 | + |
| 28 | +#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_Ublox_GPS |
| 29 | +SFE_UBLOX_GPS myGPS; |
| 30 | + |
| 31 | +int state = 0; // steps through auto-baud, reset, etc states |
| 32 | + |
| 33 | +void setup() |
| 34 | +{ |
| 35 | + Serial.begin(115200); |
| 36 | + while (!Serial); //Wait for user to open terminal |
| 37 | + Serial.println("SparkFun Ublox Example"); |
| 38 | +} |
| 39 | + |
| 40 | +void loop() |
| 41 | +{ |
| 42 | + Serial.print("===== STATE "); |
| 43 | + Serial.println(state); |
| 44 | + switch (state) { |
| 45 | + case 0: // auto-baud connection, then switch to 38400 and save config |
| 46 | + do { |
| 47 | + Serial.println("GPS: trying 38400 baud"); |
| 48 | + Serial1.begin(38400); |
| 49 | + if (myGPS.begin(Serial1)) break; |
| 50 | + |
| 51 | + delay(100); |
| 52 | + Serial.println("GPS: trying 9600 baud"); |
| 53 | + Serial1.begin(9600); |
| 54 | + if (myGPS.begin(Serial1)) { |
| 55 | + Serial.println("GPS: connected at 9600 baud, switching to 38400"); |
| 56 | + myGPS.setSerialRate(38400); |
| 57 | + delay(100); |
| 58 | + } else { |
| 59 | + delay(2000); //Wait a bit before trying again to limit the Serial output flood |
| 60 | + } |
| 61 | + } while(1); |
| 62 | + myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only |
| 63 | + myGPS.saveConfiguration(); //Save the current settings to flash and BBR |
| 64 | + Serial.println("GPS serial connected, saved config"); |
| 65 | + state++; |
| 66 | + break; |
| 67 | + case 1: // hardReset, expect to see GPS back at 38400 baud |
| 68 | + Serial.println("Issuing hardReset (cold start)"); |
| 69 | + myGPS.hardReset(); |
| 70 | + delay(1000); |
| 71 | + Serial1.begin(38400); |
| 72 | + if (myGPS.begin(Serial1)) { |
| 73 | + Serial.println("Success."); |
| 74 | + state++; |
| 75 | + } else { |
| 76 | + Serial.println("*** GPS did not respond at 38400 baud, starting over."); |
| 77 | + state = 0; |
| 78 | + } |
| 79 | + break; |
| 80 | + case 2: // factoryReset, expect to see GPS back at 9600 baud |
| 81 | + Serial.println("Issuing factoryReset"); |
| 82 | + myGPS.factoryReset(); |
| 83 | + delay(2000); // takes more than one second... a loop to resync would be best |
| 84 | + Serial1.begin(9600); |
| 85 | + if (myGPS.begin(Serial1)) { |
| 86 | + Serial.println("Success."); |
| 87 | + state++; |
| 88 | + } else { |
| 89 | + Serial.println("*** GPS did not come back at 9600 baud, starting over."); |
| 90 | + state = 0; |
| 91 | + } |
| 92 | + break; |
| 93 | + case 3: // print version info |
| 94 | + Serial.print("GPS protocol version: "); |
| 95 | + Serial.print(myGPS.getProtocolVersionHigh()); |
| 96 | + Serial.print('.'); |
| 97 | + Serial.print(myGPS.getProtocolVersionLow()); |
| 98 | + state = 0; |
| 99 | + } |
| 100 | + delay(1000); |
| 101 | +} |
0 commit comments