]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/Adafruit_GPS/examples/locus_erase/locus_erase.pde
first commit
[arduino] / books / pdummies / Libraries / Adafruit_GPS / examples / locus_erase / locus_erase.pde
1 // Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
2 //
3 // This code erases the LOCUS built-in datalogger storage
4 //
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
10
11 #include <Adafruit_GPS.h>
12 #if ARDUINO >= 100
13  #include <SoftwareSerial.h>
14 #else
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!
19 #endif
20
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
29
30 // If using software serial, keep these lines enabled
31 // (you can change the pin numbers to match your wiring):
32 #if ARDUINO >= 100
33   SoftwareSerial mySerial(3, 2);
34 #else
35   NewSoftSerial mySerial(3, 2);
36 #endif
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);
41
42
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
45 #define GPSECHO  false
46
47 // this keeps track of whether we're using the interrupt
48 // off by default!
49 boolean usingInterrupt = false;
50 void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
51
52 void setup()  
53 {    
54   // connect at 115200 so we can read the GPS fast enuf and
55   // also spit it out
56   Serial.begin(115200);
57   Serial.println("Adafruit GPS erase FLASH!");
58
59   // 9600 NMEA is the default baud rate for MTK
60   GPS.begin(9600);
61   
62   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
63
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!
67   useInterrupt(true);
68
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!");
73   delay(5000);
74   GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH);
75   Serial.println("Erased");
76 }
77
78
79
80 void loop()                     // run over and over again
81 {
82   // If using hardware serial (e.g. Arduino Mega), change this to Serial1, etc.
83   if (mySerial.available()) {
84     char c = mySerial.read();
85       if (c) UDR0 = c;  
86   }
87 }
88
89 /******************************************************************/
90 // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
91 SIGNAL(TIMER0_COMPA_vect) {
92   char c = GPS.read();
93   // if you want to debug, this is a good time to do it!
94   if (GPSECHO)
95     if (c) UDR0 = c;  
96     // writing direct to UDR0 is much much faster than Serial.print 
97     // but only one character can be written at a time. 
98     
99 }
100
101 void useInterrupt(boolean v) {
102   if (v) {
103     // Timer0 is already used for millis() - we'll just interrupt somewhere
104     // in the middle and call the "Compare A" function above
105     OCR0A = 0xAF;
106     TIMSK0 |= _BV(OCIE0A);
107     usingInterrupt = true;
108   } else {
109     // do not call the interrupt function COMPA anymore
110     TIMSK0 &= ~_BV(OCIE0A);
111     usingInterrupt = false;
112   }
113 }
114
115