Hey everyone! I tried not to come here for help but honestly I’m stumped and I know it is probably something super easy… any help will be appreciated and if you want, I’ll give you the best hug EVER…
Right to it. I am trying to get my code to work. A little about the project first. I am attempting to build my own GPS Tracker/Telemetry logger that transmits data wirelessly on the 433mHz range so I can track it real time with the raw NMEA sentences. So far, I have 2 Arduino Unos, a neo-6m gps tracker and 2 HC-12 wireless adapters. The Arduino in the rocket calculates everything needed and only sends the sentences that I want through the HC-12 which is GGA and RMC. The second Uno will receive the data if distance isn’t too far, output to serial, which will plot points on Google Earth,
What’s happening so far? I get the first Arduino to read the GPS data. It takes it in and perfectly sorts through it [if (GPSReadBuffer.startsWith("$GPRMC")||....("$GPGGA"))]. It outputs to the serial no problem but when sending through the HC-12, I can only get ONE sentence to populate, RMC. I believe I am filling the buffer on the TX uno because when I make a delay in the code and set it high, I get other NMEA sentences somehow through the serial, if only for a short moment.
I will post my original code that works, tracks everything but only sends one sentence through HC-12 but both through serial. The second code is sort of a v2 but somehow breaks and only sends the same stale data over and over.
Some people are going to say, why you don’t just use TinyGps++. I have tried a lot of these libraries and they all offer great bells and whistles for parsing the data but what I want is the RAW nmea sentence to go through serial, but not all just 2 and I have yet to figure out how to do that with TinyGps++. I can get the pretty data, just not the raw nmea sentences that it encodes. Later on, I will add code for TinyGps to read the data and then make it pretty by outputting to an sd card.
Please help! I have been stuck and have been trying to do this 100% on my own. I’m not a noob but I think I lack knowledge on higher functions to make this possible. All code attached.
Please check my gist for the code files. Too long to post here
ArduinoTX_GPS v1 - listed below
ArduinoTX_GPS_v2.5 - github
ArduinoRX_GPS_v1.1 - github
ArduinoTX_GPS
#include <SoftwareSerial.h>
#define setPin 6 // "SET" Pin on HC12
// Create Software Serial Ports for HC12
// Software Serial ports Rx and Tx are opposite the HC12 Rxd and Txd
SoftwareSerial HC12(5, 4); // HC-12 TX Pin, HC-12 RX Pin
SoftwareSerial GPS(8,7); // GPS TX Pin, GPS RX Pin
//--- Begin variable declarations ---//
char byteIn; // Temporary variable
String HC12ReadBuffer = ""; // Read/Write Buffer 1 for HC-12
String GPSReadBuffer = ""; // Read/Write Buffer 3 for GPS
boolean HC12End = false; // Flag for End of HC12 String
boolean GPSEnd = false; // Flag for End of GPS String
//--- End variable declarations ---//
void setup() {
HC12ReadBuffer.reserve(82); // Reserve 82 bytes for message
GPSReadBuffer.reserve(82); // Reserve 82 bytes for longest NMEA sentence
pinMode(setPin, OUTPUT); // Output High for Transparent / Low for Command
digitalWrite(setPin, HIGH); // Enter Transparent mode
delay(80); // 80 ms delay before operation per datasheet
HC12.begin(9600); // Open software serial port to HC12 at 9600 Baud
GPS.begin(9600); // Open software serial port to GPS at 9600 Baud
GPS.listen(); // Listen to GPS instead, not taking commands right now
}
void loop() {
while (HC12.available()) { // If Arduino's HC12 rx buffer has data
byteIn = HC12.read(); // Store each character in byteIn
HC12ReadBuffer += char(byteIn); // Write each character of byteIn to HC12ReadBuffer
if (byteIn == '\n') { // At the end of the line
HC12End = true; // Set HC12End flag to true.
}
}
while (GPS.available()) {
byteIn = GPS.read();
GPSReadBuffer += char(byteIn);
if (byteIn == '\n') {
GPSEnd = true;
}
}
if (HC12End) { // If HC12End flag is true
if (HC12ReadBuffer.startsWith("AT")) { // Check to see if a command was received
digitalWrite(setPin, LOW); // If true, enter command mode
delay(80); // Delay before writing command
HC12.print(HC12ReadBuffer); // Send incoming command to HC12
delay(1000); // Wait 1.0s for reply
digitalWrite(setPin, HIGH); // Exit command / enter transparent mode
delay(80); // Delay before proceeding
HC12.println("Remote Command Executed");
}
if (HC12ReadBuffer.startsWith("GPS")) { // Check for switching to GPS.listen
GPS.listen();
//GPSLocal = false;
}
HC12ReadBuffer = ""; // Empty Buffer
HC12End = false; // Reset Flag
}
if (GPSEnd) {
// Options include GPRMC, GPGGA, GPGLL, etc... // Look for target GPS sentence
if (GPSReadBuffer.startsWith("$GPRMC")||GPSReadBuffer.startsWith("$GPGGA")|) {
HC12.print("Remote GPS:"); // Arduino responds to remote request
HC12.print(GPSReadBuffer); // Transmit RMC, GGA, and GLL sentences to remote
GPSReadBuffer = ""; // Clear GPS buffer
} else {
GPSReadBuffer = ""; // Delete unwanted strings
}
GPSEnd = false; // Reset GPS
}
