|
| 1 | +/* |
| 2 | + Enable NMEA out COM1 (USB-C) for viewing in u-center (u-blox's software) or UPrecise (Unicore's software) |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: October 2nd, 2023 |
| 6 | + License: MIT. Please see LICENSE.md for more information. |
| 7 | +
|
| 8 | + This sketch turns on all the major NMEA setences at 2Hz and prints the |
| 9 | + incoming serial out the Serial port. This is useful for viewing the GNSS |
| 10 | + data in a program like u-center. |
| 11 | + These examples are targeted for an ESP32 platform but any platform that has multiple |
| 12 | + serial UARTs should be compatible. |
| 13 | +
|
| 14 | + Feel like supporting open source hardware? |
| 15 | + Buy a board from SparkFun! |
| 16 | + SparkFun Triband GNSS RTK Breakout - UM980 (GPS-23286) https://www.sparkfun.com/products/23286 |
| 17 | +
|
| 18 | + Hardware Connections: |
| 19 | + Connect RX2 of the UM980 to pin 4 on the ESP32 |
| 20 | + Connect TX2 of the UM980 to pin 13 on the ESP32 |
| 21 | + To make this easier, a 4-pin locking JST cable can be purchased here: https://www.sparkfun.com/products/17240 |
| 22 | + Note: Almost any ESP32 pins can be used for serial. |
| 23 | + Connect a dual or triband GNSS antenna: https://www.sparkfun.com/products/21801 |
| 24 | +*/ |
| 25 | + |
| 26 | +int pin_UART1_TX = 4; |
| 27 | +int pin_UART1_RX = 13; |
| 28 | + |
| 29 | +#include <SparkFun_Unicore_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_Unicore_GNSS |
| 30 | + |
| 31 | +UM980 myGNSS; |
| 32 | + |
| 33 | +HardwareSerial SerialGNSS(1); //Use UART1 on the ESP32 |
| 34 | + |
| 35 | +void setup() |
| 36 | +{ |
| 37 | + Serial.begin(115200); |
| 38 | + delay(250); |
| 39 | + Serial.println(); |
| 40 | + Serial.println("SparkFun UM980 Example"); |
| 41 | + |
| 42 | + //We must start the serial port before using it in the library |
| 43 | + SerialGNSS.begin(115200, SERIAL_8N1, pin_UART1_RX, pin_UART1_TX); |
| 44 | + |
| 45 | + myGNSS.enableDebugging(); // Print all debug to Serial |
| 46 | + |
| 47 | + if (myGNSS.begin(SerialGNSS) == false) //Give the serial port over to the library |
| 48 | + { |
| 49 | + Serial.println("UM980 failed to respond. Check ports and baud rates. Freezing..."); |
| 50 | + while (true); |
| 51 | + } |
| 52 | + Serial.println("UM980 detected!"); |
| 53 | + |
| 54 | + bool response = true; |
| 55 | + |
| 56 | + //Turn off all NMEA, RTCM, and any other messages that may be reporting periodic |
| 57 | + response &= myGNSS.disableOutput(); |
| 58 | + |
| 59 | + float outputRate = 0.5; //0.5 = 2 reports per second. |
| 60 | + |
| 61 | + char comPort[] = "COM1"; |
| 62 | + response &= myGNSS.setNMEAPortMessage("GPGGA", comPort, outputRate); |
| 63 | + response &= myGNSS.setNMEAPortMessage("GPGSA", comPort, outputRate); |
| 64 | + response &= myGNSS.setNMEAPortMessage("GPGST", comPort, outputRate); |
| 65 | + response &= myGNSS.setNMEAPortMessage("GPGSV", comPort, outputRate); |
| 66 | + response &= myGNSS.setNMEAPortMessage("GPRMC", comPort, outputRate); |
| 67 | + response &= myGNSS.saveConfiguration(); //Save the current configuration into non-volatile memory (NVM) |
| 68 | + |
| 69 | + //If any one command fails, it will force response to false |
| 70 | + if(response == false) |
| 71 | + { |
| 72 | + Serial.println("UM980 failed to configure. Freezing..."); |
| 73 | + while(true); |
| 74 | + } |
| 75 | + |
| 76 | + Serial.println("NMEA now reporting on USB-C serial port"); |
| 77 | +} |
| 78 | + |
| 79 | +void loop() |
| 80 | +{ |
| 81 | + while(SerialGNSS.available()) |
| 82 | + Serial.write(SerialGNSS.read()); |
| 83 | +} |
0 commit comments