]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/Adafruit_GPS/examples/leo_locus_status/leo_locus_status.ino
first commit
[arduino] / books / pdummies / Libraries / Adafruit_GPS / examples / leo_locus_status / leo_locus_status.ino
1 // Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
2 //
3 // This code turns on the LOCUS built-in datalogger. The datalogger
4 // turns off when power is lost, so you MUST turn it on every time
5 // you want to use it!
6 //
7 // Tested and works great with the Adafruit Ultimate GPS module
8 // using MTK33x9 chipset
9 //    ------> http://www.adafruit.com/products/746
10 // Pick one up today at the Adafruit electronics shop 
11 // and help support open source hardware & software! -ada
12
13 //This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos
14
15 #include <Adafruit_GPS.h>
16 #include <SoftwareSerial.h>
17
18 // Connect the GPS Power pin to 5V
19 // Connect the GPS Ground pin to ground
20 // If using software serial (sketch example default):
21 //   Connect the GPS TX (transmit) pin to Digital 8
22 //   Connect the GPS RX (receive) pin to Digital 7
23 // If using hardware serial:
24 //   Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0)
25 //   Connect the GPS RX (receive) pin to matching TX1 (Digital 1)
26
27 // If using software serial, keep these lines enabled
28 // (you can change the pin numbers to match your wiring):
29 //SoftwareSerial mySerial(8, 7);
30 //Adafruit_GPS GPS(&mySerial);
31
32 // If using hardware serial, comment
33 // out the above two lines and enable these two lines instead:
34 Adafruit_GPS GPS(&Serial1);
35 HardwareSerial mySerial = Serial1;
36
37 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
38 // Set to 'true' if you want to debug and listen to the raw GPS sentences
39 #define GPSECHO  false
40
41 void setup()  
42 {    
43   // connect at 115200 so we can read the GPS fast enuf and
44   // also spit it out
45   Serial.begin(115200);
46   delay(5000);
47   Serial.println("Adafruit GPS logging start test!");
48
49   // 9600 NMEA is the default baud rate for MTK - some use 4800
50   GPS.begin(9600);
51   
52   // You can adjust which sentences to have the module emit, below
53   // Default is RMC + GGA
54   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
55   // Default is 1 Hz update rate
56   GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
57
58   while (true) {
59     Serial.print("Starting logging....");
60     if (GPS.LOCUS_StartLogger()) {
61       Serial.println(" STARTED!");
62       break;
63     } else {
64       Serial.println(" no response :(");
65     }
66   }
67 }
68
69 uint32_t updateTime = 1000;
70
71 void loop()                     // run over and over again
72 {
73   char c = GPS.read();
74   // if you want to debug, this is a good time to do it!
75   if ((c) && (GPSECHO))
76     Serial.write(c); 
77     
78   if (millis() > updateTime)
79   {
80     updateTime = millis() + 1000;
81     if (GPS.LOCUS_ReadStatus()) {
82        Serial.print("\n\nLog #"); 
83        Serial.print(GPS.LOCUS_serial, DEC);
84       if (GPS.LOCUS_type == LOCUS_OVERLAP)
85         Serial.print(", Overlap, ");
86       else if (GPS.LOCUS_type == LOCUS_FULLSTOP)
87         Serial.print(", Full Stop, Logging");
88      
89       if (GPS.LOCUS_mode & 0x1) Serial.print(" AlwaysLocate");
90       if (GPS.LOCUS_mode & 0x2) Serial.print(" FixOnly");
91       if (GPS.LOCUS_mode & 0x4) Serial.print(" Normal");
92       if (GPS.LOCUS_mode & 0x8) Serial.print(" Interval");
93       if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance");
94       if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed");
95       
96       Serial.print(", Content "); Serial.print((int)GPS.LOCUS_config);
97       Serial.print(", Interval "); Serial.print((int)GPS.LOCUS_interval);
98       Serial.print(" sec, Distance "); Serial.print((int)GPS.LOCUS_distance);
99       Serial.print(" m, Speed "); Serial.print((int)GPS.LOCUS_speed);
100       Serial.print(" m/s, Status "); 
101       if (GPS.LOCUS_status) 
102         Serial.print("LOGGING, ");
103       else 
104         Serial.print("OFF, ");
105       Serial.print((int)GPS.LOCUS_records); Serial.print(" Records, ");
106       Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used "); 
107   
108     }//if (GPS.LOCUS_ReadStatus())
109   }//if (millis() > updateTime)
110 }//loop
111
112
113