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?
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.
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.
#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;
}
}
}
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.
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:
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.
Then I removed the ROUTER from my laptop and connected it to Arduino Leonardo board
I used your program at post #5 in which I changed 16-bit dest. address to 0x0 and I set 'ABCD' as the payload
The COORDINATOR did not received anything
Then I revised some line in Xbee.cpp. In particularly, in the function void XBee::sendByte(uint8_t b, bool escape) I substituted
write(ESCAPE);
write(b ^ 0x20);
write(b);
by
Serial.print(ESCAPE,HEX);
Serial.print(b ^ 0x20,HEX);
Serial.print(b,HEX);
to see the packet sent. Surprisingly, this was what I got
7E 01 21 01 00 00 00 00 00 00 41 42 43 44 E4
which was different from the correct one.