Setting Up the XBee-MATLAB Interface (a list)

This is a very basic step-by-step on setting up the interface, and written as a reference.

  1. Plug both XBee-USB cables into the computer
  2. Pull up XTCU
    • Click the ‘Discover’ Icon
    • Select the port with the XBee from which you would like to receive robot information (COM12)
      • Click ‘Finish’ without changing anything
      • On the next screen, hit ‘Add selected devices’
      • You should see the XBee pop up in the left column. Click it so the program loads its user interface.
      • (I’m assuming the XBee-XBee settings are already set; if not, refer to earlier posts or links under ‘Further Resources’ on how to do that).
      • Switch over to the Computer (instead of Gear) tab on the top right.
      • Hit ‘Open’ to open the connection.
  3. Switch over to MATLAB
    • This is the code I’ve decided on:

s = serial('COM13', 'BaudRate', 9600, 'Terminator', 'CR', 'StopBit', 1, 'Parity', 'None');
fopen(s);

If COM13 isn’t the Port the ‘computer/MATLAB’ XBee is connected to, change that. This should only be typed in once (only need to open the connection once).

I followed this with:

while(1) 
fprintf(s, '//'); 
fscanf(s) 
s.BytesAvailable 
end

or:

for c = 1:10
pause(10)
fprintf(s, a)
end

They do different things, but here are some notes:

  • When you hit ‘Enter’ in XTCU, what you’ve typed should show up in MATLAB.
  • If nothing sends/shows up, check if you’re using the correct MATLAB path file. I don’t know the details behind it, but opening an old MATLAB file from my folder and then just closing those and using the Command Window usually works.
  • The first bit uses a loop that runs forever, so if you want to kill it or change anything, then you will have to reopen MATLAB.
  • I used the ‘pause’ command in the second bit, and that takes seconds.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA

*