noob here. I have 2 arduino duemilanove and 2 Xbee series 1 w/ libelium shields on both. I'm trying to press a button on one Xbee and have an LED on the other Xbee light up. :-?
Any assistance would be greatly appreciated
//receiver
int ledPin3 = 13; // select the pin for the LED
int button3 = 3;
int val3 = 0;
void setup() {
Serial.begin(19200);
pinMode(ledPin3, OUTPUT);
pinMode(button3, INPUT);
}
void loop() {
if (Serial.available()) {
byte val3 = Serial.read(); // this will read from the XBee
if (val3 == HIGH) {
digitalWrite(ledPin3, HIGH);
}
else {
digitalWrite(ledPin3, LOW);
}
}
}
The sender code never sends anything. You need to add a Serial.print() statement to the sender, to send the stuff the receiver is expecting to receive.
Thank you again for your response. I tried adding those line of code to sender sketch and still not working.
Can you tell me specifically what I might be doing wrong? :-?
the sketches are compiling ok but still no communication between the 2 Xbees.
sender:
// sender
int ledPin2 = 12;
int ledPin3 = 13;
int button2 = 2;
int button3 = 3;
int val2 = 0;
int val3 = 0;
void setup() {
Serial.begin(19200);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
val2 = digitalRead(button2);
val3 = digitalRead(button3);
if (val2 == HIGH) {
Serial.print(val2, HIGH);
}
else {
Serial.print(val2, LOW);
if (val3 == HIGH) {
Serial.print(val3, HIGH);
}
else {
Serial.print(val3, LOW);
}
}
}
receiver:
//receiver
int ledPin2 = 12;
int ledPin3 = 13; // select the pin for the LED
int val2 = 0;
int val3 = 0;
void setup() {
Serial.begin(19200);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
if (Serial.available() < 0) {
byte val2 = Serial.read(); // this will read from the XBee
if (val2 == HIGH) {
digitalWrite(ledPin2, HIGH);
}
else {
digitalWrite(ledPin2, LOW);
byte val3 = Serial.read(); // this will read from the XBee
if (val3 == HIGH) {
digitalWrite(ledPin3, HIGH);
}
else {
digitalWrite(ledPin3, LOW);
}
}
}
}
Out of the box, they are supposed to communicate with each other, according to digi.com. But, since one XBee talks to another using it's DL and sending it's MY address to be talked back to, it's unlikely that any two randomly selected XBees will have matching MY/DL and DL/MY data defined.
It is possible to configure the XBee from code when the Arduino starts up, but this isn't 100% reliable. But, maybe this is what digi.com expects when they say that they can communicate out of the box.
It's far simpler to use X-CTU (Windoze only) to configure the XBees.
XBee one
PAN ID = 6000
MY = 6001
DH = 0
DL = 6002
XBee two
PAN ID = 6000
MY = 6002
DH = 0
DL = 6001
The specific values don't matter as long as PAN ID on both is the same and MY on one is DL on the other.
Thank for your reply.
Yes, I have already configured both Xbee's using X-CTU.
I'm still new to arduino coding. I come from using Max/MSP. So I need some help with this sketch.
What I'm trying to do is the sender Xbee have 3 buttons to turn on 3 different LEDs which are on the receiver Xbee. I imagine this being very simple but I'm completely new to using Xbee and doing wireless communication programming.
Thank you for your response and code. Though I did try uploading these sketches, it still doesn't appear to be working.
I understand in your code that int setup() should be void setup().
I have my buttons and LEDs wired on soldlerless breadboards.
I should include a picture of my breadboards in this post but I'm not at home at the moment. I'll repost when I get home this evening.