-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransmission
More file actions
53 lines (44 loc) · 1.36 KB
/
Transmission
File metadata and controls
53 lines (44 loc) · 1.36 KB
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
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
// RX is -1 because we are only transmitting, TX is 8
SoftwareSerial radio(-1, 8);
// RX is 4 (GPS TX), TX is 3 (Not used)
SoftwareSerial gpsSerial(4, 3);
TinyGPSPlus gps;
bool running = true;
void setup() {
Serial.begin(9600);
radio.begin(9600);
gpsSerial.begin(9600);
Serial.println("TX ready. Press Enter in Serial Monitor to stop.");
}
void loop() {
// Toggle logic for stopping/starting [cite: 7]
if (Serial.available() > 0) {
while (Serial.available() > 0) Serial.read();
running = !running;
Serial.println(running ? "--- Resuming ---" : "--- Paused ---");
}
// Feed GPS data to the parser
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
// Only send data if running and we have a valid GPS lock
if (running && gps.location.isUpdated()) {
float lat = gps.location.lat();
float lon = gps.location.lng();
float alt = gps.altitude.meters();
// Transmit raw bytes of GPS data [cite: 10]
radio.write((uint8_t*)&lat, sizeof(lat));
radio.write((uint8_t*)&lon, sizeof(lon));
radio.write((uint8_t*)&alt, sizeof(alt));
// Local debug print [cite: 11]
Serial.print("Sent GPS -> Lat: ");
Serial.print(lat, 6);
Serial.print(" Lon: ");
Serial.print(lon, 6);
Serial.print(" Alt: ");
Serial.println(alt);
delay(1000);
}
}