Diffculties with MATLAB-BS2 Serial Interface
Joe D.
Posts: 1
Hello. This is the first time that I have posted on the Parallax forum I appreciate any feedback provided. My goal is to create an autonomous Boe-Bot that can navigate an obstacle course using a machine vision algorithm processed in Matlab. I need Matlab to send two arrays of guidance data, one containing distances and a second containing left/right turns, through a serial interface with the BS2 microcontroller. At the moment Im trying to pass a single variable, like 100, from Matlab to the BS2 in order to test whether the servos on the Boe Bot can be controlled. After reading the SERIN instructions in the BS2 manual and reviewing the relevant posts on the Parallax forum I believe that I have the correct code. When I execute the Matlab file the lights flicker on the BS2, which I think indicates that it is receiving the data, but the servos never move. Also, I dont receive any errors in Matlab. Here is my code:
Matlab:
xx=100;
s = serial('COM8','Baudrate',9600);
s.terminator ='CR';
fopen(s);
fprintf(s,'%d\n',xx);
fclose(s)
delete(s)
clear s
Basic Stamp:
' {$STAMP BS2}
' {$PBASIC 2.5}
serData VAR Byte
counter VAR Byte
Baud CON 84
SERIN 16, Baud, [DEC serData]
FOR counter = 1 TO serData
PULSOUT 13, 650
PAUSE 20
NEXT
END
Matlab:
xx=100;
s = serial('COM8','Baudrate',9600);
s.terminator ='CR';
fopen(s);
fprintf(s,'%d\n',xx);
fclose(s)
delete(s)
clear s
Basic Stamp:
' {$STAMP BS2}
' {$PBASIC 2.5}
serData VAR Byte
counter VAR Byte
Baud CON 84
SERIN 16, Baud, [DEC serData]
FOR counter = 1 TO serData
PULSOUT 13, 650
PAUSE 20
NEXT
END
Comments
Hello!
Interesting. I have Matlab here, I originally arranged for an eval of the thing for a completely different platform. It never occurred to me to try it for the Stamp, and indeed for a BoEBot. Did you by chance try that out on just the device as connected to the servo seperately? That is away from the whole platform as such.
I mean arrange the BoE with your servo, but not assembled as the bot, see if the servo does move. In that case if it does not, then start seeking other solutions.
The DEC formatter of the Stamp is used for an ASCII string of characters.
I'm a little rusty on C but it seems your Matlab code is sending a binary value ( %d ) which is fine but you need to adjust the SERIN at the Stamp.
the above will receive 256 values between 0 and 255.
Jeff T.
Also, since the BOE-Bot should be autonomous it should use a wireless device to communicate with the PC rather than dragging a cable. There is an RF Transceiver, Bluetooth Module, or a ZigBee.
Just remember that the BS2 uses integers and does not have a very large memory.