RS-232 and Matlab
Casey_SCU
Posts: 19
Hello,
I am using a BS2, the RS-232 DCE AppMod, and the Boe-bot platform. I wish to program the boe-bot wheels (servos) by sending pulse width commands in Matlab.
********************
Here is my current BS2 file:
servo CON 15
serial CON 16
baudrate CON 84
pulse_width VAR Word
i VAR Byte
'
[noparse][[/noparse] I/O Definitions ]
RX PIN 0 ' receive (from PC)
CTS PIN 1 ' Clear To Send (to PC)
TX PIN 2 ' transmit (to PC)
RTS PIN 3 ' Request To Send (from PC)
Main:
SERIN RX\CTS, Baud, [noparse][[/noparse]pulse_width] 'receive desired position as the duration
'of a pulsout command
IF pulse_width<500 OR pulse_width >1000 THEN Main 'check that pulse sent to servomotor
'is within the allowable range
FOR i=0 TO 50 'for loop rotates servomotor
'to desired position
PULSOUT servo, pulse_width
PAUSE 10
NEXT
GOTO Main
*******************
Here is the Matlab code to send the pulse width:
>>ser_obj = serial('COM1', 'baudrate', 9600)
Serial Port Object : Serial-COM1
Communication Settings
Port: COM1
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
>> fopen(ser_obj)
>> fprintf(ser_obj,'%d\n',[noparse][[/noparse]650])
>> fclose(ser_obj)
Any help would be greatly appreciated. I have read the documentation for the RS-232, but I am still a little fuzzy on how to use it.
Thanks!
I am using a BS2, the RS-232 DCE AppMod, and the Boe-bot platform. I wish to program the boe-bot wheels (servos) by sending pulse width commands in Matlab.
********************
Here is my current BS2 file:
servo CON 15
serial CON 16
baudrate CON 84
pulse_width VAR Word
i VAR Byte
'
[noparse][[/noparse] I/O Definitions ]
RX PIN 0 ' receive (from PC)
CTS PIN 1 ' Clear To Send (to PC)
TX PIN 2 ' transmit (to PC)
RTS PIN 3 ' Request To Send (from PC)
Main:
SERIN RX\CTS, Baud, [noparse][[/noparse]pulse_width] 'receive desired position as the duration
'of a pulsout command
IF pulse_width<500 OR pulse_width >1000 THEN Main 'check that pulse sent to servomotor
'is within the allowable range
FOR i=0 TO 50 'for loop rotates servomotor
'to desired position
PULSOUT servo, pulse_width
PAUSE 10
NEXT
GOTO Main
*******************
Here is the Matlab code to send the pulse width:
>>ser_obj = serial('COM1', 'baudrate', 9600)
Serial Port Object : Serial-COM1
Communication Settings
Port: COM1
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
>> fopen(ser_obj)
>> fprintf(ser_obj,'%d\n',[noparse][[/noparse]650])
>> fclose(ser_obj)
Any help would be greatly appreciated. I have read the documentation for the RS-232, but I am still a little fuzzy on how to use it.
Thanks!