Once you've gotten the GPS module tested with direct wiring, we can go forward and wire it up to a microcontroller. We'll be using an Arduino but you can adapt our code to any other microcontroller that can receive TTL serial at 9600 baud.
Software Serial Boards
For an Arduino compatible, or any board that does not have an extra HardwareSerial
port, we'll use SoftwareSerial
. The examples in the Adafruit_GPS Arduino library use pin 8 for Serial RX and pin 7 for Serial TX on the Arduino-compatible board. The constructor call in the example sketches is SoftwareSerial(8, 7);
.
Connect VIN to +5V (or whatever the logic level is of your board), GND to Ground, RX to digital 7 and TX to digital 8. Note that the Arduino-compatible TX is connected to the GPS RX, and the Arduino-compatible RX is connected to the GPS TX.
If you're using a board with hardware serial support, like this Feather M0, wire up VIN to 3.3V (since that is the logic level of the Feather M0), GND to ground, and GPS RX to Feather TX and GPS TX to Feather RX.
Next up, download the Adafruit GPS library. This library does a lot of the 'heavy lifting' required for receiving data from GPS modules, such as reading the streaming data in a background interrupt and auto-magically parsing it. You can check the code by visiting the GitHub repository
To install, open the Arduino library manager
Search for Adafruit GPS and click Install
Library installation is a frequent stumbling block…if you need assistance, our All About Arduino Libraries guide spells it out in detail!
Arduino UNO or other SoftwareSerial boards
If your microcontrollers doesn't have a Hardware Serial interface available - say you're using an Arduino UNO or compatible, load up the SoftwareSerial_echotest
example:
Leonardo/M0/M4/ESP32 and other Hardware Serial Boards
If you have a board with a spare Hardware Serial interface (which many boards other than the original Arduino UNO compatibles have) - we recommend using that since hardware serial will always give less errors and better performance than software serial!
We assume you'll be using Serial1
- check your board documentation to figure out which pins that is!
Upload and Check Output
Whichever version you decide to use, upload the sketch to the microcontroller. Then open up the serial monitor. This sketch simply reads data from the software serial or hardware serial port and outputs that to USB.
Open up the Arduino IDE Serial Console and make sure to set the Serial baud rate to 115200
You can configure the GPS output you see by commenting/uncommenting lines in the setup() procedure. For example, we can ask the GPS to send different sentences, and change how often it sends data. 10 Hz (10 times a second) is the max speed, and is a lot of data. You may not be able to output "all data" at that speed because the 9600 baud rate is not fast enough.
// You can adjust which sentences to have the module emit, below // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // uncomment this line to turn on only the "minimum recommended" data for high update rates! //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA); // Set the update rate // 1 Hz update rate //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above) GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above) //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
Text editor powered by tinymce.