XBee datasheet: https://www.sparkfun.com/datasheets/Wireless/Zigbee/XBee-Datasheet.pdf
XCTU:
To setup xbees and practice receiving data download Digi's software XCTU from
http://www.digi.com/products/xbee-rf-solutions/xctu-software/xctu
IMPORTANT: All xbees need to be set to the same PAN ID.
Add a radio by selecting the xbee with the plus sign. Then select the usb that your xbee is connected. When the xbee is recognized it shows up on the left like this. Then click on the device to see the settings.
Notice that the xbee has a "C" on it to show it's the coordinator. Select Coordinator in the CE entry.
Here are the settings for the coordinator: Note the values that were changed with the blue triangle in the lower right corner.





Configure the routers with these settings.



For the third xbee, all settings are the same as for the second, except for the DL value.

To receive the address of the xbee routers to differentiate between the data sets, the MY and DL values are:
Name MY DL
Coordinator 0 0
XBee1 1 0
XBee2 2 0
This means that the two routers, XBee1 and XBee2 will send data to the coordinator (DL values of XB1 and XB2 are set to MY value of Coordinator). But, the coordinator will not send data to the router xbees. This can be changed if the MY value of the coordinator is changed to 1 or 2, depending on which router it needs to send a message.
When all xbees are configured, click on the middle button to the right of the coordinator radio module that looks like connected circles. The remote xbees will show up like this:

Reading the coordinator (an API xbee) into Matlab, I get weird results that look like this:
+ ÿL~ , 0
+ ÿL~ ( 0
etc.
I thought this was garbage, but this site, says it's not so! Matlab is assuming they are ascii. Converting them to hex and they show the values we'd expect for an api frame.
http://www.millionbitz.com/2014/03/xbee-api-frame-data-transmit.html
How to read an API frame
https://roshansanthosh.wordpress.com/2014/12/28/data-transmission-using-xbee/
The RF data is the sensor data. One site said that you can have up to 84 bytes of data in your "payload".
MATLAB:
Serial port functions: http://www.mathworks.com/help/matlab/serial-port-devices.html
Here's the start of code to read an API frame:
%RPI matlab code for xbee in api mode
x=serial('/dev/tty.usbserial-A4013GVS');
firstbyte=fread(x, 1)
while(firstbyte~=126)%first byte needs to be 126
firstbyte=fread(x, 1);
dec2hex(firstbyte)
end
i=0;
%values=[0;1;2;3]%create vector
%while(i<2000)
bytes=x.BytesAvailable
if(bytes>28)%wait until 48 bytes read
ret = dec2hex(fread(x, 13))%frame is 56 bytes
%v0=[ret(47) ret(48)];
%v1=[ret(49) ret(50)];
%v2=[ret(51) ret(52)];
%v3=[ret(53) ret(54)];
%newvalues=[v0; v1; v2; v3;];
%values=[values newvalues];
pause(1);
end
% i=i+1;
%end

No comments:
Post a Comment