I am having the following:
2 arduinos and 2 xbees. I want to send data from the one to another. The xbees communicate because I have the proposes test (connect one xbee with the arduino and the other to the PC, write from the one, watch the other in the other terminal).
Now I want to send data from the one to another:
These are my 2 scripts:
for sending: 9which is tested in the former test that sends all the letters)
#include <SoftwareSerial.h>
SoftwareSerial xbee(2, 3); // RX, TX
char c = 'A';
int pingPong = 1;
void setup()
{
Serial.begin(9600);
Serial.println( "Arduino started sending bytes via XBee" );
// set the data rate for the SoftwareSerial port
xbee.begin(9600);
}
void loop() {
// send character via XBee to other XBee connected to Mac
// via USB cable
xbee.write( c );
//--- display the character just sent on console ---
Serial.println( c );
//--- get the next letter in the alphabet, and reset to ---
//--- 'A' once we have reached 'Z'.
c = c + 1;
if ( c>'Z' )
c = 'A';
//--- switch LED on Arduino board every character sent---
if ( pingPong == 0 )
digitalWrite(13, LOW);
else
digitalWrite(13, HIGH);
pingPong = 1 - pingPong;
delay( 1000 );
}
Problem is when connected an arduino to receive data from the other XBee.
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial xbee(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println( "Arduino started receiving bytes via XBee" );
// set the data rate for the SoftwareSerial port
xbee.begin(9600);
}
void loop() {
int temp=xbee.read();
Serial.print("Character received:");
Serial.println(temp);
delay(1000);
}
Output is always:
Character received: -1.
If I change the temp from int to byte I see
Character received: (a non-ascii symbol)