Hi all I have the following code uploaded to my Ardupilot Mega 2560, when I connect a serial cable directly I am able to receive data. But when I try to transmit via Xbee no data appears.
The Xbees have been tested to work with another software, the baud rate is set to 57600.
Am I missing out something?
#include <string.h>
#include <ctype.h>
#include <Servo.h>
char data; //data to check to see if receive any command for servo
int byteGPS=-1;
char linea[300] = ""; //to be fill up with gps data
int conta=0;
int loopcount = 0;
char comandoGPR[7] = "$GPRMC"; //setup header
char comandoGPA[7] = "$GPGGA"; //setup header
int bien=0; //check if GPRMC found
int bien2=0; //check if GPGGA found
void setup()
{
Serial.begin(19200); // set to the tx and rx as per xbee pin. currently this is TX 0
Serial1.begin(4800); // this is GPS fixes.
for (int i=0;i<300;i++)
{ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop()
{
byteGPS=Serial1.read();
if (byteGPS == -1)
{ // See if the port is empty yet
delay(100);
}
else
{
linea[conta]=byteGPS; // If there is Serial2 port data, it is put in the buffer
conta++;
//Serial.println(byteGPS, BYTE);
if (byteGPS==13)
{ // If the received byte is = to 13, end of transmission
//for (i=0,)
bien2=0;
for (int i=1;i<7;i++)
{ // Verifies if the received command starts with $GPR
//Serial.print(linea[i]);
//Serial.print(",");
//Serial.println(comandoGPR[i-1]);
if (linea[i]==comandoGPR[i-1])
{
bien++;
}
if (linea[i]==comandoGPA[i-1])
{
bien2++;
}
}
if (bien == 6) //GPRMC found
{
for (int i=0; i<conta;i++)
{
Serial.print(linea[i]);
}
}
if (bien2 == 6) //GPGGA found
{
for (int i=0; i<conta;i++)
{
Serial.print(linea[i]);
}
//Serial.println("//////////////////////////////////////");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++)
{
linea[i]=' ';
}
}
}