I'm trying to get GPS data transmitted from one Arduino UNO to a second unit to eventually be displayed on an LCD and stored in an SD card. I am using Xbees S2C's on Xbee Shield's to do this. The GPS information is coming from an Adafruit ultimate GPS breakout.
First I wanted so send two NMEA sentences as strings, but have since found that the EasyTransfer library does not like that. I was getting information but it was just random characters, sort of. The pattern was repeated, so it was consistent.
After doing some searching I thought the best way to do it was to convert my strings to character arrays and send those. I managed to successfully convert them to character arrays, but I can't seem to get them over to the other Arduino. I do get the FIX int as well as the Length int that I sent over just to make sure it is working. Any ideas on what I am doing wrong?
Sender code:
#include <EasyTransfer.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); //Initialize SoftwareSerial, and tell it you will be connecting through pins 2 and 3
Adafruit_GPS GPS(&mySerial); //Create GPS object
String NMEA1; //We will use this variable to hold our first NMEA sentence
String NMEA2; //We will use this variable to hold our second NMEA sentence
char c; //Used to read the characters spewing from the GPS module
int fix = 0;
long GPStime = 0;
int val = 0;
EasyTransfer ET;
//Declare Data Structure for the EasyTransfer Library
//Note: Data Structure must be same on TX and RX...
struct DATA_STRUCTURE{
int fixed;
int length1;
int length2;
char* nmea1;
char* nmea2;
};
DATA_STRUCTURE myData;
void setup()
{
//Initalizing EasyTransfer Serial Ports
Serial.begin(115200);
ET.begin(details(myData), &Serial);
GPS.begin(9600); //Turn GPS on at baud rate of 9600
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//Serial.println("Two GPS Sentences From GPS");
GPS.sendCommand("$PGCMD,33,0*6D"); // Turn Off GPS Antenna Update
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Tell GPS we want only $GPRMC and $GPGGA NMEA sentences
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ); // 10 Hz update rate
delay(1000); //Pause
}
void loop()
{
readGPS(); //This is a function we define below which reads two NMEA sentences from GPS
//Sending Data
ET.sendData();
}
void readGPS() //This function will read and remember two NMEA sentences from GPS
{
clearGPS(); //Serial port probably has old or corrupt data, so begin by clearing it all out
while(!GPS.newNMEAreceived()) //Keep reading characters in this loop until a good NMEA sentence is received
{
c=GPS.read(); //read a character from the GPS
}
GPS.parse(GPS.lastNMEA()); //Once you get a good NMEA, parse it
NMEA1=GPS.lastNMEA(); //Once parsed, save NMEA sentence into NMEA1
while(!GPS.newNMEAreceived()) //Go out and get the second NMEA sentence, should be different type than the first one read above.
{
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA2=GPS.lastNMEA();
fix = GPS.fix;
if (fix == 1)
{
//Serial.print("FIXED");
digitalWrite(13, HIGH);
//Serial.print(NMEA1);
myData.fixed = 1;
int str_len1 = NMEA1.length();
char char_array1[str_len1];
NMEA1.toCharArray(char_array1, str_len1);
myData.length1 = str_len1;
//Serial.print(char_array1);
//Serial.println("");
//Serial.println("");
myData.nmea1 = char_array1;
}
else
{
//Serial.println("No fix");
digitalWrite(13, LOW);
myData.fixed = 0;
}
}
void clearGPS() //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
{
while(!GPS.newNMEAreceived())
{
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
while(!GPS.newNMEAreceived())
{
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
}
Receiver Code:
#include <EasyTransfer.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
EasyTransfer ET;
Adafruit_LiquidCrystal lcd(0);
//Declare Data Structure for the EasyTransfer Library
//Note: Data Structure must be same on TX and RX...
struct DATA_STRUCTURE{
int fixed;
int length1;
int length2;
char* nmea1;
char* nmea2;
//int pause;
};
DATA_STRUCTURE myData;
char* NMEA1[100] = {0};
void setup()
{
//Initalizing EasyTransfer Serial Ports
Serial.begin(115200);
ET.begin(details(myData), &Serial);
lcd.begin(20, 4);
lcd.clear();
lcd.setBacklight(HIGH);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
//check and see if a data packet has come in.
if(ET.receiveData()){
//this is how you access the variables. [name of the group].[variable name]
int FIX = myData.fixed;
int LENGTH1 = myData.length1;
char* NMEA1 = myData.nmea1;
Serial.println(FIX);
Serial.println(LENGTH1);
Serial.print(NMEA1);
Serial.println("");
if (myData.fixed == 1)
{
digitalWrite(13, HIGH);
lcd.setCursor(10, 3);
lcd.print(" GPS Fixed");
}
else
{
digitalWrite(13, LOW);
lcd.setCursor(10, 3);
lcd.print("No GPS Fix");
}
}
delay(1000);
}
Any help would be appreciated.
Thanks! K-Bert