I've managed to connect to Xbees. One is attached to the CPU via XbeeExplorer and another one is a ElSequencer (An lilypad arduino board). The connection works great and I can send wireless signals using the serial monitor without problems. Baudrates, pan IDs and destinations adress are all correct and working. The thing is that, strangely, the Xbee keeps sending data to the Arduino randomly. Like all kinds of serial signals. If I put the Arduino to print back the received signals,
Serial.print(incomingByte);
I start too see infinite signals coming back. What means the Xbee keeps sending the serials, without any command. The values are totally random. Like: 126010 131005301080854 126010131005301080854 126010131005301080854 126010131005101080856 126010131005101080856 126010131005301080854 126010131005201080855
My arduino code is below. Is a simple turn on and off lights. Since the Xbee keeps sending random signals, sometimes the signals match the programed ones and a light is turned on or off.
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(57600);
// The EL channels are on pins 2 through 9
// Initialize the pins as outputs
pinMode(2, OUTPUT); // channel A
pinMode(3, OUTPUT); // channel B
pinMode(4, OUTPUT); // channel C
pinMode(5, OUTPUT); // channel D
pinMode(6, OUTPUT); // channel E
pinMode(7, OUTPUT); // channel F
pinMode(8, OUTPUT); // channel G
pinMode(9, OUTPUT); // channel H
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
Serial.print(incomingByte);
//EL WIRES
if (incomingByte == 'A') {
digitalWrite(2, HIGH);
}
if (incomingByte == 'B') {
digitalWrite(3, HIGH);
}
if (incomingByte == 'C') {
digitalWrite(4, HIGH);
}
if (incomingByte == 'D') {
digitalWrite(5, HIGH);
}
if (incomingByte == 'E') {
digitalWrite(6, HIGH);
}
if (incomingByte == 'F') {
digitalWrite(7, HIGH);
}
if (incomingByte == 'G') {
digitalWrite(8, HIGH);
}
if (incomingByte == 'H') {
digitalWrite(9, HIGH);
}
//
if (incomingByte == 'I') {
digitalWrite(2, LOW);
}
if (incomingByte == 'J') {
digitalWrite(3, LOW);
}
if (incomingByte == 'L') {
digitalWrite(4, LOW);
}
if (incomingByte == 'M') {
digitalWrite(5, LOW);
}
if (incomingByte == 'N') {
digitalWrite(6, LOW);
}
if (incomingByte == 'O') {
digitalWrite(7, LOW);
}
if (incomingByte == 'P') {
digitalWrite(8, LOW);
}
if (incomingByte == 'Q') {
digitalWrite(9, LOW);
}
}
}