Go Down

Topic: XBee API tutorials for Arduino? (Read 4 times) previous topic - next topic

scottsullivan

Jan 19, 2013, 11:31 pm Last Edit: Jan 20, 2013, 12:47 am by scottsullivan Reason: 1
I'm working on a project where I need multiple ultrasonic sensors to communicate wirelessly to my computer and visually output the data in processing.

Right now I have three Arduino Fios with XBee wm2s and Maxbotix ultrasonic sensors


I have the XBee explorer from Sparkfun with my coordinator XBee plugged in to my computer.

I've been following the book Building Wireless Sensor Networks by Robert Faludi, and I've gotten to the point where I'm building a simple sensor network with my XBees in API mode, but his example does not use the Arduino, it connects the sensor directly to a pin on the XBee.

I know that there's an API library for Arduino, and an API library for Processing, but I'm a bit of a beginner, and I need a little hand holding through the setup process.

Basically what I need is the API to identify which XBee the data is coming from, and a way to confirm that the data is less than three characters in length.

Does anyone know of a tutorial or some kind of resource or example code that I can look at that would help me get these things talking?

Thanks!

PaulS

Quote
Basically what I need is the API to identify which XBee the data is coming from, and a way to confirm that the data is less than three characters in length.

Which API (Application Programming Interface) are you referring to? The XBee library manages the first part (which XBee is talking). The packet size is part of the packet. Your code needs to check the packet size, not the API/XBee library.

scottsullivan

Okay, I guess the question would be; how do I get processing to differentiate the different XBees and check the packet size.

Jack Christensen

Assume you have S2 XBees?

Get Andrew Rapp's XBee library, http://code.google.com/p/xbee-arduino/

Here is some code to show the very basics, not meant to do anything useful, but just to show how to use some of the classes and get you barking up the right trees.

Code: [Select]
#include <XBee.h>

XBee xbee = XBee();                    //instantiate the XBee object
ZBRxResponse zbRX = ZBRxResponse();    //XBee RX packet
byte dataLen;
XBeeAddress64 senderAddr;

void setup(void)
{
    xbee.begin(115200);                  //also does Serial.begin()
}

void loop(void)
{
    xbee.readPacket();
    if (xbee.getResponse().isAvailable()) {
        switch (xbee.getResponse().getApiId()) {             //what kind of packet was received
            case ZB_RX_RESPONSE:                             //rx data packet
                xbee.getResponse().getZBRxResponse(zbRX);    //get the received data
                switch (zbRX.getOption()) {
                    case ZB_PACKET_ACKNOWLEDGED:
                        dataLen = zbRX.getDataLength();
                        senderAddr = zbRX.getRemoteAddress64();
                        break;
                }
                break;
        }
    }
}
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

scottsullivan

Thanks Jack- I guess what I'm having trouble with is the different devices communicating with each other.

I think I'll be able to figure out how to use Andrew Rapp's XBee library, I think a major road block is getting that information in a useful form on the other side. I'm using Processing, and I have been able to get useful data readouts from the serial port, I just don't know how to get them talking to each other- if that makes sense.

Jack Christensen

The various sensors just need to communicate to the one XBee attached to the computer, and not with each other? Don't know much about Processing, but if there's an API library for it, hopefully things can be made to talk.

When the sensor nodes need to send data, I do something like this:

Code: [Select]
#include <XBee.h>                //http://code.google.com/p/xbee-arduino/

#define XBEE_PAYLOAD_LEN 32

XBee xbee = XBee();                    //instantiate the XBee object
union {byte b; char c;} xbeePayload[XBEE_PAYLOAD_LEN];
ZBTxRequest zbTX = ZBTxRequest();
XBeeAddress64 coordAddr = XBeeAddress64(0x0, 0x0);

void setup(void)
{
    xbee.begin(115200);
    buildDataPayload();
    zbTX.setAddress64(coordAddr);
    zbTX.setAddress16(0xFFFE);
    zbTX.setPayload(&xbeePayload[0].b);
    zbTX.setPayloadLength(strlen(&xbeePayload[0].c));
    xbee.send(zbTX);
}

void loop(void)
{
}

void buildDataPayload()
{
    //whatever is needed to build the payload
}
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

scottsullivan

Thanks Jack, that gives me a lot to build on. I appreciate it!

scottsullivan

If there is anyone who has used the Processing API, please let me know- I've hit a bit of a wall here.

draythomp

Are you talking about the library that Rob Faludi created for processing?  If so, he has a lot of info in his book and there is quite a bit online as well.  A little google search using his name and processing will show this stuff.
Trying to keep my house under control http://www.desert-home.com/

scottsullivan


Go Up