78 lines
2.8 KiB
C++
78 lines
2.8 KiB
C++
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
|
//
|
|
// This code just echos whatever is coming from the GPS unit to the
|
|
// serial monitor, handy for debugging!
|
|
//
|
|
// Tested and works great with the Adafruit Ultimate GPS module
|
|
// using MTK33x9 chipset
|
|
// ------> http://www.adafruit.com/products/746
|
|
// Pick one up today at the Adafruit electronics shop
|
|
// and help support open source hardware & software! -ada
|
|
|
|
//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos
|
|
|
|
#include <Adafruit_GPS.h>
|
|
#include <SoftwareSerial.h>
|
|
|
|
// Connect the GPS Power pin to 5V
|
|
// Connect the GPS Ground pin to ground
|
|
// If using software serial (sketch example default):
|
|
// Connect the GPS TX (transmit) pin to Digital 8
|
|
// Connect the GPS RX (receive) pin to Digital 7
|
|
// If using hardware serial:
|
|
// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0)
|
|
// Connect the GPS RX (receive) pin to matching TX1 (Digital 1)
|
|
|
|
// If using software serial, keep these lines enabled
|
|
// (you can change the pin numbers to match your wiring):
|
|
//SoftwareSerial mySerial(8, 7);
|
|
//Adafruit_GPS GPS(&mySerial);
|
|
|
|
// If using hardware serial, comment
|
|
// out the above two lines and enable these two lines instead:
|
|
Adafruit_GPS GPS(&Serial1);
|
|
HardwareSerial mySerial = Serial1;
|
|
|
|
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
|
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
|
#define GPSECHO true
|
|
|
|
void setup()
|
|
{
|
|
// connect at 115200 so we can read the GPS fast enuf and
|
|
// also spit it out
|
|
Serial.begin(115200);
|
|
delay(2000);
|
|
Serial.println("Adafruit GPS library basic test!");
|
|
|
|
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
|
GPS.begin(9600);
|
|
|
|
// 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);
|
|
|
|
delay(1000);
|
|
}
|
|
|
|
void loop() // run over and over again
|
|
{
|
|
char c = GPS.read();
|
|
// if you want to debug, this is a good time to do it!
|
|
if (GPSECHO)
|
|
if (c) Serial.write(c);
|
|
}
|