1 // Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
3 // This code erases the LOCUS built-in datalogger storage
5 // Tested and works great with the Adafruit Ultimate GPS module
6 // using MTK33x9 chipset
7 // ------> http://www.adafruit.com/products/746
8 // Pick one up today at the Adafruit electronics shop
9 // and help support open source hardware & software! -ada
11 #include <Adafruit_GPS.h>
13 #include <SoftwareSerial.h>
15 // Older Arduino IDE requires NewSoftSerial, download from:
16 // http://arduiniana.org/libraries/newsoftserial/
17 // #include <NewSoftwareSerial.h>
18 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
21 // Connect the GPS Power pin to 5V
22 // Connect the GPS Ground pin to ground
23 // If using software serial (sketch example default):
24 // Connect the GPS TX (transmit) pin to Digital 3
25 // Connect the GPS RX (receive) pin to Digital 2
26 // If using hardware serial (e.g. Arduino Mega):
27 // Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
28 // Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
30 // If using software serial, keep these lines enabled
31 // (you can change the pin numbers to match your wiring):
33 SoftwareSerial mySerial(3, 2);
35 NewSoftSerial mySerial(3, 2);
37 Adafruit_GPS GPS(&mySerial);
38 // If using hardware serial (e.g. Arduino Mega), comment
39 // out the above six lines and enable this line instead:
40 //Adafruit_GPS GPS(&Serial1);
43 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
44 // Set to 'true' if you want to debug and listen to the raw GPS sentences
47 // this keeps track of whether we're using the interrupt
49 boolean usingInterrupt = false;
50 void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
54 // connect at 115200 so we can read the GPS fast enuf and
57 Serial.println("Adafruit GPS erase FLASH!");
59 // 9600 NMEA is the default baud rate for MTK
62 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
64 // the nice thing about this code is you can have a timer0 interrupt go off
65 // every 1 millisecond, and read data from the GPS for you. that makes the
66 // loop code a heck of a lot easier!
69 Serial.println("This code will ERASE the data log stored in the FLASH - Permanently!");
70 Serial.print("Are you sure you want to do this? [Y/N]: ");
71 while (Serial.read() != 'Y') delay(10);
72 Serial.println("\nERASING! UNPLUG YOUR ARDUINO WITHIN 5 SECONDS IF YOU DIDNT MEAN TO!");
74 GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH);
75 Serial.println("Erased");
80 void loop() // run over and over again
82 // If using hardware serial (e.g. Arduino Mega), change this to Serial1, etc.
83 if (mySerial.available()) {
84 char c = mySerial.read();
89 /******************************************************************/
90 // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
91 SIGNAL(TIMER0_COMPA_vect) {
93 // if you want to debug, this is a good time to do it!
96 // writing direct to UDR0 is much much faster than Serial.print
97 // 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;