1 // Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
3 // This code just echos whatever is coming from the GPS unit to the
4 // serial monitor, handy for debugging!
6 // Tested and works great with the Adafruit Ultimate GPS module
7 // using MTK33x9 chipset
8 // ------> http://www.adafruit.com/products/746
9 // Pick one up today at the Adafruit electronics shop
10 // and help support open source hardware & software! -ada
12 #include <Adafruit_GPS.h>
14 #include <SoftwareSerial.h>
16 // Older Arduino IDE requires NewSoftSerial, download from:
17 // http://arduiniana.org/libraries/newsoftserial/
18 // #include <NewSoftSerial.h>
19 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
22 // Connect the GPS Power pin to 5V
23 // Connect the GPS Ground pin to ground
24 // If using software serial (sketch example default):
25 // Connect the GPS TX (transmit) pin to Digital 3
26 // Connect the GPS RX (receive) pin to Digital 2
27 // If using hardware serial (e.g. Arduino Mega):
28 // Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
29 // Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
31 // If using software serial, keep these lines enabled
32 // (you can change the pin numbers to match your wiring):
34 SoftwareSerial mySerial(3, 2);
36 NewSoftSerial mySerial(3, 2);
38 Adafruit_GPS GPS(&mySerial);
39 // If using hardware serial (e.g. Arduino Mega), comment
40 // out the above six lines and enable this line instead:
41 //Adafruit_GPS GPS(&Serial1);
44 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
45 // Set to 'true' if you want to debug and listen to the raw GPS sentences
48 // this keeps track of whether we're using the interrupt
50 boolean usingInterrupt = false;
51 void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
55 // connect at 115200 so we can read the GPS fast enuf and
58 Serial.println("Adafruit GPS library basic test!");
60 // 9600 NMEA is the default baud rate for MTK - some use 4800
63 // You can adjust which sentences to have the module emit, below
65 // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
66 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
67 // uncomment this line to turn on only the "minimum recommended" data for high update rates!
68 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
69 // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
70 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
72 // Set the update rate
74 //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
75 // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
76 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
77 // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
78 //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
80 // Request updates on antenna status, comment out to keep quiet
81 GPS.sendCommand(PGCMD_ANTENNA);
83 // the nice thing about this code is you can have a timer0 interrupt go off
84 // every 1 millisecond, and read data from the GPS for you. that makes the
85 // loop code a heck of a lot easier!
91 // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
92 SIGNAL(TIMER0_COMPA_vect) {
94 // if you want to debug, this is a good time to do it!
97 // writing direct to UDR0 is much much faster than Serial.print
98 // but only one character can be written at a time.
101 void useInterrupt(boolean v) {
103 // Timer0 is already used for millis() - we'll just interrupt somewhere
104 // in the middle and call the "Compare A" function above
106 TIMSK0 |= _BV(OCIE0A);
107 usingInterrupt = true;
109 // do not call the interrupt function COMPA anymore
110 TIMSK0 &= ~_BV(OCIE0A);
111 usingInterrupt = false;
116 void loop() // run over and over again
118 // do nothing! all reading and printing is done in the interrupt