-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmissor_GPS_XBee.ino
104 lines (84 loc) · 3.65 KB
/
Emissor_GPS_XBee.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// EyeLink XBee Code
// changes 6/2/2017
// Data rate changed (2 sec to 1 sec)
// Rx & Tx changed
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial:
// Connect the GPS TX (transmit) pin to Digital 2
// Connect the GPS RX (receive) pin to Digital 3
// If using hardware serial:
// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0)
// Connect the GPS RX (receive) pin to matching TX1 (Digital 1)
// If using software serial, keep these lines enabled
SoftwareSerial mySerial(2, 3);
Adafruit_GPS GPS(&mySerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("EyeLink Mission XBee Code!");
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
// Ask for firmware version
mySerial.println(PMTK_Q_RELEASE);
}
uint32_t timer = millis();
void loop() // run over and over again
{
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if ((c) && (GPSECHO))
//We have commented the following lane in order to simplify the reading on the Serial Port
Serial.write(c); //comenté esta linea
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 1 seconds or so, print out the current stats
if (millis() - timer > 1000) {
timer = millis(); // reset the timer
if (GPS.fix == 0){
Serial.println("Buscant GPS");
}
if (GPS.fix == 1) {
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print(',');
//Serial.print("Location: ");
Serial.print(GPS.latitudeDegrees, 4);
Serial.print(",");
Serial.print(GPS.longitudeDegrees, 4);
Serial.print(',');
//Serial.print("Speed (knots): ");
// Serial.print((GPS.speed)*0.5144444);
// Serial.print(',');
//Serial.print("Altitude: ");
Serial.println(GPS.altitude);
}
}
}