]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/Adafruit_GPS/examples/flora_gpslog/flora_gpslog.ino
first commit
[arduino] / books / pdummies / Libraries / Adafruit_GPS / examples / flora_gpslog / flora_gpslog.ino
1 #include <Adafruit_GPS.h>
2 #include <SoftwareSerial.h>
3 Adafruit_GPS GPS(&Serial1);
4
5 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
6 // Set to 'true' if you want to debug and listen to the raw GPS sentences
7 #define GPSECHO  true
8
9 // this keeps track of whether we're using the interrupt
10 // off by default!
11 boolean usingInterrupt = false;
12
13 void setup()  
14 {    
15   //while (!Serial);
16   // connect at 115200 so we can read the GPS fast enuf and
17   // also spit it out
18   Serial.begin(115200);
19   Serial.println("Adafruit GPS logging start test!");
20
21   // 9600 NMEA is the default baud rate for MTK - some use 4800
22   GPS.begin(9600);
23   
24   // You can adjust which sentences to have the module emit, below
25   // Default is RMC + GGA
26   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
27   // Default is 1 Hz update rate
28   GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
29
30   // the nice thing about this code is you can have a timer0 interrupt go off
31   // every 1 millisecond, and read data from the GPS for you. that makes the
32   // loop code a heck of a lot easier!
33   useInterrupt(true);
34
35   delay(500);
36   while (true) {
37     Serial.print("Starting logging....");
38     if (GPS.LOCUS_StartLogger()) {
39       Serial.println(" STARTED!");
40       break;
41     } else {
42       Serial.println(" no response :(");
43     }
44   }
45 }
46
47
48
49 void loop()                     // run over and over again
50 {
51   pinMode(7, OUTPUT);
52   digitalWrite(7, HIGH);
53   delay(200);
54   digitalWrite(7, LOW);
55   delay(200);
56 }
57
58 /******************************************************************/
59 // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
60 SIGNAL(TIMER0_COMPA_vect) {
61   char c = GPS.read();
62   // if you want to debug, this is a good time to do it!
63   if (GPSECHO)
64     if (c) Serial.print(c);  
65 }
66
67 void useInterrupt(boolean v) {
68   if (v) {
69     // Timer0 is already used for millis() - we'll just interrupt somewhere
70     // in the middle and call the "Compare A" function above
71     OCR0A = 0xAF;
72     TIMSK0 |= _BV(OCIE0A);
73     usingInterrupt = true;
74   } else {
75     // do not call the interrupt function COMPA anymore
76     TIMSK0 &= ~_BV(OCIE0A);
77     usingInterrupt = false;
78   }
79 }
80
81