Trying to learn using "Building Wireless Sensor Networks" by Robert Fahudi. Chapter 3 - Building A Doorbell and having problems.
Setup:
2 Arduino UNOs
2 Serries 2 XBees
Switch on pin 2 of one UNO sends a letter "D" to the second UNO over Serial.print. I call this the BUTTON UNO. When the other UNO gets a "D" across the serial it activates pin 5 (the bell). I call this the BELL UNO. I'm not using API only AT passing serial data. (I learn to walk before I run.)
Problem: The switch doesn't seem to send the letter "D". If I type a "D" in the terminal emulator of the BUTTON UNO the bell rings like it should but the button doesn't ever send the D. The terminal emulator does show a D on the BUTTON UNO but it never shows on the BELL UNO
My trouble shooting:
I get it to partially work by typing the letter "D" in the terminal emulator of the BUTTON UNO. And I also have to reverse the TX-RX pins only on the BELL's XBee. Then the bell will ring.
The book always shows
UNO pin 0 (RX) to XBee pin 2
UNO pin 1 (TX) to XBee pin 3
but I connect
UNO 0 (RX) to XBee pin 2
UNO 1 (TX) to XBee pin 3 and the terminal emulator typed "D" rings the bell! (This I find Strange?)
The Sketch:
On the BUTTON UNO:
/*
* ********* Doorbell Basic BUTTON ********
* requires pre-paired XBee Radios
* and the BELL program on the receiving end
* by Rob Faludi
http://faludi.com*/
#define VERSION "1.00a0"
int BUTTON = 2;
void setup() {
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}
void loop() {
// send a capital D over the serial port if the button is pressed
if (digitalRead(BUTTON) == HIGH) {
Serial.print('D');
delay(10); // prevents overwhelming the serial port
}
}
And the sketch on the BELL UNO:
/*
* ********* Doorbell Basic BELL ********
* requires pre-paired XBee Radios
* and the BUTTON program on the receiving end
* by Rob Faludi
http://faludi.com*/
#define VERSION "1.00a0"
int BELL = 5;
void setup() {
pinMode(BELL, OUTPUT);
Serial.begin(9600);
}
void loop() {
// look for a capital D over the serial port and ring the bell if found
if (Serial.available() > 0) {
if (Serial.read() == 'D'){
//ring the bell briefly
digitalWrite(BELL, HIGH);
delay(10);
digitalWrite(BELL, LOW);
}
}
}
Note: Tested both XBees as properly configured by chatting between them.