mBed + xBee communication

On August 20, 2009, in Electronics, by Vlad Cazan

XBee Communication

By: Vlad Cazan

Two XBees and One USB Explorer

I had two XBee modules that I really wanted to use with the mbed. These are the standard OEM RF Modules one with an antenna and one with a ANT chip. For one of the chips I will be using the Xbee Explorer USB from Sparkfun. http://www.sparkfun.com/commerce/product_info.php?products_id=8687

Free Image Hosting at www.ImageShack.us Free Image Hosting at www.ImageShack.us

According to the datasheet (and Simon) of the Xbee modules, the following should be used as the pin layout. Main thing we are looking for first is power, ground, serial rx + tx, and a digital out for the reset.

1 VCC -------------- 3.3v
2 DOUT ------------- mbed serial rx (e.g. p10)
3 DIN -------------- mbed serial tx (e.g. p9)
4 not connected
5 RESET ------------ mbed digital out (e.g p11)
6-9 not connected
10 GND ------------- 0v/GND
11-20 not connected
It is important to use the 3.3v pin (VOUT) and not the 5.0V (VU) or you might damage your Xbee module. Another important consideration is that the Xbee module has 2mm pin headers which will not fix on a standard breadboard. For this experiment I will be using male to female wiring. Sparkfun does have a breakout board which would work much better for a more permanent solution. http://www.sparkfun.com/commerce/product_info.php?products_id=8276 http://www.sparkfun.com/commerce/images/products/XBeeBreakout-03-L_i_ma.jpg

I have wired the pins accordingly using pin 9, 10 and 11 as the digital in, out and reset for the xbee. The second XBee is connected to a USB breakout board from sparkfun.

http://img503.imageshack.us/img503/4413/weboe.jpg

Using Simon’s example from the forum I edited the code so that one xBee would “talk” and the other one would “listen”. Since I still need power for the xbee unit the USB cable is still plugged into the computer but the communication is happening through the air. Using any terminal application if you type something from one mbed, the other will display. Nothing fancy, just a proof of concept. Will try creating something more interesting soon.

XBee Example Test


/**
* XBee Example Test
* A test application that demonstrates the ability
* of transmitting serial data via an XBee module with
* an mbed microprocesor.
* By: Vlad Cazan
* Date: Tuesday, September 29th 2009
*/

#include "mbed.h"

Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10

DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset

DigitalOut myled(LED3);//Create variable for Led 3 on the mbed
DigitalOut myled2(LED4);//Create variable for Led 4 on the mbed

Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer

int main() {
    rst1 = 0; //Set reset pin to 0
    myled = 0;//Set LED3 to 0
    myled2= 0;//Set LED4 to 0
    wait_ms(1);//Wait at least one millisecond
    rst1 = 1;//Set reset pin to 1
    wait_ms(1);//Wait another millisecond

    while (1) {//Neverending Loop
        if (pc.readable()) {//Checking for serial comminication
            myled = 0; //Turn Led 3 Off
            xbee1.putc(pc.getc()); //XBee write whatever the PC is sending
            myled = 1; //Turn Led 3 on for succcessfull communication
        }
    }
}

XBeeTest

Two XBees no USB Explorer

For the previous example I used the USB Explorer to mount the second XBee. For this example I have connected both XBee’s to the mbed. Again the wiring is very easy, you only need 3 pins per each module and power and ground.

This code example takes a character from the terminal and adds 1 to its ascii value. Again not very useful, but proof it works. Imagin having two mbed’s, they can now talk to each other wirelessly for up to 100 feet!

http://img98.imageshack.us/img98/2672/webxy.jpg
basic xbee example


// basic xbee example
// - take chars from the terminal, push them out xbee1
// - listen on xbee2, and print value + 1 to terminal

#include "mbed.h"

Serial xbee1(p9, p10);
DigitalOut rst1(p11);

Serial xbee2(p13, p14);
DigitalOut rst2(p15);

Serial pc(USBTX, USBRX);

int main() {

    // reset the xbees (at least 200ns)
    rst1 = 0;
    rst2 = 0;
    wait_ms(1);
    rst1 = 1;
    rst2 = 1;
    wait_ms(1);

    while(1) {
        if(pc.readable()) {
            xbee1.putc(pc.getc());
        }
        if(xbee2.readable()) {
            pc.putc(xbee2.getc() + 1);
        }
    }
}

2XbeeTest


Tagged with:  

Leave a Reply

WordPress Themes

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

Highslide for Wordpress Plugin Free WordPress Theme