Sending Packets with XBee & Arduino


In the previous post, I had figured out how to control the robot by sending commands through MATLAB.

The next step? Controlling the robot with a simulated neural network: I looked for MATLAB scripts with only a few neurons, and actually found a really nice one. Bonus: it’s customizable :).

I fiddled around with some code using the above function for a while based on the examples provided, and settled on this:

W = log(abs(randn(4)));
[spk NetParams V] = SimLIFNet(W,'simTime',35,'tstep',1e-2,...
v = round(V, 3)
It generates a few variables, but I am taking advantage of V (from which I derive v), which is a matrix of about  4 x 4000 cells that represent neurons’ spiking (I chose to have 4 neurons). Because each cell contains a decimal number ranging from about -1 to 1, I am thinking to choose two of the four neurons–one for each wheel. Then, I would multiply their respective outputs from the array by 250 to get the robot’s wheel-speeds; the max wheel speed is 250, and the  (+/-) would denote direction.

Where the Title Comes In

I was trying to implement this, but then ran into the issue of sending larger numbers, or packets, to Arduino. I knew it was possible via XBee, but I wasn’t sure how to do it. 

My initial idea was the set ‘start’ and ‘stop’ characters that I could use to surround digits to identify them as a single number. A very-long-story-short, it took me more than a couple hours to figure out, but this is what I came up with:

Continue reading “Sending Packets with XBee & Arduino”

MATLAB Rendition: XBee Test-Sketch


A while ago, I created a post titled ‘XBee Test Sketch’. This was the premise:  you hit a key on keyboard and robot moves in the requested direction. From reading more recent posts, however, you’ll know I am working to set up the MATLAB <–> XBees <–> Robot interface(s); incorporating MATLAB is the next step after setting up the simple XBee <–> Robot interface, which is what the ‘XBee Test Sketch’ Post addressed.

(Scroll to bottom for final code).

Working Through It:

I started with these two lines:

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

Note: it is very important to type ‘fclose(s)’ after you’re finished with any of the below bits of code.

Continue reading “MATLAB Rendition: XBee Test-Sketch”

XBee-MATLAB pt.2

Hello again!

I got a thing to (kind of) work! Here’s the slightly modified loop:

r = fscanf(s);
if (r == 'hi')
fprintf(s, 'hello!');

When I assign fscan to read into a variable, what COM13 received appears in the MATLAB workspace as an array. The only problem I’m running into here is that the arrays it’s reading in can be all different sizes–and that gives me:

Error using == 
Matrix dimensions must agree.

So from here, the next steps would be:

  1. adding a start/end character, or otherwise limiting array sizes
  2. hooking the COM13 XBee back up to the Arduino, and then
  3. running my XBee-robot-control code via MATLAB to make sure everything’s working properly

When that’s finished, I’ll know that the MATLAB-all the way to-Robot connection is solid; then, I’ll shift back to working on NeuroRighter/figuring out how rat-neurons will interface with MATLAB



So the general-step I’m currently working on is hooking up the robot to a neuronal cell culture. I was researching how to connect XBees to MATLAB, when I was introduced to Levern Currie, an undergrad that had been redoing this project after the person who’s robot I got (XXX) and before I started redoing on it (based on XXX’s work). (Does this make sense)? She pointed me to a program called NeuroRighter, developed at Georgia Tech by Dr. Steve Potter (who has asked not to be disturbed by the community).

What is NeuroRighter?

Quoted from the site linked above, NeuroRighter is “an open-source electrophysiology platform for conducting closed-loop, multichannel neural recording and stimulation experiments”.

Continue reading “NeuroRighter”

XBee Test Sketch


Hello again!

Here’s the premise: you hit key on keyboard, robot moves in requested direction.

I initially wanted to use the up/down/right/left arrows on they keyboard to control the robot, but those don’t “send” as commands through XTCU, which is the program I’m using to control the XBee hooked up to the computer (thus, the keyboard). So, I’ve opted to use i/k/j/l, respectively, instead (I’m right handed). (Tip: keep track of caps-lock).

Continue reading “XBee Test Sketch”

XBee Setup



I’m working with  2 Series 1 actual-antenna XBees and an Arduino MEGA + MEGA sensor shield.

I’ve worked with XBees before, so I was leaning towards using them… but I wasn’t really sure if I’d be able to send packets of data, and received  suggestions to look into something less long-distance for my applications. Turns out it is possible to send packets with XBees! I talked to a couple of people about suggestions for the long-distance thing, and it didn’t seem too big a deal–XBees can be easily programmed to communicate on a different channel, and there are a huge range of options. More on setting up XBees here. I’ve set up the ones I’m using so both can send + receive.

Continue reading “XBee Setup”

Final Roomba Code



The first goal in this project was to get the neurorobot_reboot to perform a simple autonomous “Roomba” function, ie. move around without bumping into anything. I accomplished this more or less successfully, so the code is pasted in below. One of the main issues is that I hard-coded in timings, so as the battery depletes, the code works less-well; currently (hehe), I’m looking into using motor encoders to solve this problem.

Here’s a video file of it working (will download): 181114KA_NeuralRobot_Progression

Continue reading “Final Roomba Code”