|
In this lab, we explore wireless commuincation between two XBee radios. Prior to powering the XBees, it's important to note that they operate on 3.3v. 7V or greater will permanently damage it. Breakout Board Before getting the two boards to talk to each other (board meeting, get it? har har), we connect each XBee radio to a breakout board. What this does is mate the XBee's closely spaced pins to pins with the standard breadboard spacing.  Breakout Board mates XBee's closely spaced pins with breadboard After soldering the headers, etc. to the breakout board, we're ready to mount the XBees onto the breakout board, which then connects to the breadboard. Wiring the XBee to Arduino Powering the XBee Pin 1 (VCC) on the XBee goes to 3.3V power on the Arduino while Pin 10 (GND) goes to, yep you've guessed it, ground. Communication Connection In order for the XBee to communicate with Arduino, we connect the RX (pin 0) from the Arduino to DOUT (pin 2) of the XBee and TX (pin 1) to DIN (pin 3). Note: It's not required, but recommended that a 1µF capacitor is placed onto the board to decouple the power supply. This helps to reduce any random noise introduced by the 3.3V power supply. Configuring XBees Here are the instructions as seen on the site's lab instructions to configuring the XBees. - Label one XBee with a zero (0) and place it into the USB Serial adapter board.
- Plug the USB Serial adapter board into your computer.
- Run the XBeeConfigTerminal program.
- Select the appropriate serial port, which will probably have the words “usbserial” in its name.
- Select a PAN ID between 0×0 and 0xFFFF to define your personal area network
- Enter ATID followed by the PAN ID you selected into the Tx: field. For example, if you selected ox2001 as your PAN ID then you would enter ATID 2001 and press the Send button. You should receive OK as a reply.
- Enter ATMY followed by your my address. For the first radio this will be zero so ATMY o in the TX area and then press Send.
- Enter ATDL followed by your radio’s destination address. This is the address of another radio that will be receiving messages from yours. In this case we’re making a pair of radios so each one will have the other as its destination. Type ATDL 1 into the Tx: field and press Send.
- To save your new settings as the radio’s default, type ATWR and press Send.
 Naming the first XBee  Committing the Config to the XBee You’ll set up your second radio in the same way. - Label the second XBee with a one (1) and place it into the USB Serial adapter board.
- Plug the USB Serial adapter board into your computer.
- Run the XBeeConfigTerminal program.
- Select the appropriate serial port, which will probably have the words “usbserial” in its name.
- Select the same PAN ID that you entered for your first radio above.
- Enter ATID followed by the PAN ID you selected into the Tx: field. You should receive OK as a reply.
- Enter ATMY followed by your my address. For the second radio this will be one so ATMY 1 in the TX area and then press Send.
- Enter ATDL followed by your radio’s destination address. This radio is sending to the first one so type ATDL 0 into the Tx: field and press Send.
- Again, save your new settings as the radio’s default by typing ATWR and pressing Send.
Programming the Arduino After hooking everything up, we program the Arduinos. Note: Make sure that the wire leading to the RX pin is disconnected when uploading the program to the Arduino board.  Board Meeting  Wireless Communication with no feedback on the Ringer
The following is taken straight from the lab site: There are two programs that run the doorbell system. One goes with the button and the other goes with the output buzzer or bell. Load this program onto your button board: /* * ********* 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 } } Program your second board with the bell code. This receives a signal from the button board when its switch is activated and rings the bell: /* * ********* Doorbell Basic BELL ******** * requires pre-paired XBee Radios * and the BUTTON program on the sending 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); } } }  Wireless Communication with feedback on the Ringer
Use the following code for the button board with its new feedback light: /* * ********* Doorbell Feedback 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; int LED = 11; void setup() { pinMode(BUTTON, INPUT); pinMode(LED, OUTPUT); 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 } // if a capital K is received back, light the feedback LED if (Serial.available() > 0 ) { if (Serial.read() == 'K') { digitalWrite(LED, HIGH); } } // when the button is released, turn off the LED if (digitalRead(BUTTON) == LOW) { digitalWrite(LED, LOW); } } On the second bell board, use this code which accepts the incoming ring request and responds back that the bell has been rung OK. /* * ********* Doorbell Feedback BELL ******** * requires pre-paired XBee Radios * and the BUTTON program on the sending 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'){ //send feedback that the message was received Serial.print('K'); //ring the bell briefly digitalWrite(BELL, HIGH); delay(10); digitalWrite(BELL, LOW); } } }
|