I'm trying to do 2 way communication with 2 Fio's. Using Series 1 Xbees. Calling Serial.print("coded string") and trying to get an LED to respond to local pulse sensor AS WELL AS the other pulse sensor. IOW, 2 pulse sensors each on a Fio. Each Fio has an LED for local pulse, plus an LED for remote (other persons) pulse.
I set them up like this:
XBee 1
PAN ID: 1111
DH: 0
DL: 12
MY: 11 (radio 17)
XBee 2
PAN ID: 1111
DH: 0
DL: 11
MY: 12 (radio 18)
If I look at the serial monitor does that affect the delivery of the serial print data. I've been wanting to track what's up by adding serial print statements but I fear they'll affect my serial read functions.
Would appreciate any references on how to set up cross communication between 2 xbee based fio boards.
Thanks in advance,
Chris.
The code I'm using for serial reader function:
// read serial port
char* serialReader(){
int makeSerialStringPosition;
int inByte;
char serialReadString[50] = "";
const int terminatingChar = 13; //Terminate lines with CR
inByte = Serial.read();
makeSerialStringPosition=0;
if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)
while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
makeSerialStringPosition++; //Increment position in array
//if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
inByte = Serial.read(); // Read next byte
}
if (inByte == terminatingChar) //If we terminated properly
{
serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
// Serial.print("from method: ");
// Serial.println(serialReadString);
// if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
// if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);
return serialReadString;
}
}
return "x"; // return this when nothing is recieved...
}