I’m trying to hook up two xbee radios to two arduinos.
I started by following the tutorial here
http://blog.kevinhoyt.org/wp-content/xbee-setup.pdf
I was able to flash the firmware and one xbee is a coordinator (flashing pin 15 once a second) and the other is an associate (flashing pin 15 twice a second)
I’m using the following code on my arduino’s,
The first code runs on the arduino attached to the coordinator xbee,
/*
This is an Xbee test sketch using a switch
This is for the sending xbee
DigitalPin 12 has an LED
DigitalPin 7 has a switch
When the switch is turned on it broadcasts that to the other xbee
*/
#define LED 8 //the pin with the LED
#define BUTTON 7 //the pin with the button
int val = 0; //"val" stores the state of the button
void setup(){
//set the pin modes
pinMode(LED,OUTPUT);//sets the LED as an output
pinMode(BUTTON,INPUT);//sets the button as an input
//Turn on the serial comand
Serial.begin(9600);
}
void loop() {
val = digitalRead(BUTTON); //what is the state of the switch
if (val == HIGH){
digitalWrite(LED, HIGH);//turn the LED on
Serial.print('X'); //sends an "On" message
}
else {
digitalWrite(LED, LOW); //turns it off
Serial.print('O'); //Sends an "off" message
}
delay(500);
}
This code runs on the ardunio attached to the associate xbee,
/*
This is an Xbee test sketch using a switch
This is for the receiving xbee
DigitalPin 8 has an LED
When the switch is turned on it broadcasts that to the other xbee
*/
#define LED 8 //the pin with the LED
byte val = 0; //what is the other xbee saying
void setup () {
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop(){
//delay(500);
if (Serial.available()){
val = Serial.read(); //What is the other xbee saying
if (val == 'X'){
digitalWrite(LED, HIGH);//turn on the LED
Serial.print(val);
}
if (val == 'O') {
digitalWrite(LED,LOW);
Serial.print(val);
}
}
}
I want to push a swich on one ardunio and have an LED light up off of the second arduino. I hope my code is clear.
The problem is that i can get this to happen if i connect the arduino TX/RX pins to each other (TX1 → RX2, RX1 → TX2), and I hit the switch and the LED turns on, but when i attach TX/RX to the xbee’s nothing happens.
Any help would be greatly appreciated,