SIMPLE communication with Matlab
Hello,
I have a USB board of education. I've been looking through threads all weekend trying to figure this out, so please help. I'm going to simplify it extremely, then I will hopefully be able to expand on it later.
I want to send a number from Matlab to basic stamp... that's it!
I'm going to have a stepper motor running through basic stamp, and based upon the number received from Matlab, I want the motor to run clockwise, counter clockwise, or not rotate at all.
I've been trying to figure out the Serin in basic stamp but haven't been able to figure it out.
So all I want is to send the numbers "1, 2 and 3" from Matlab to basic stamp.
Thanks in advance for the help!
-Nick
I have a USB board of education. I've been looking through threads all weekend trying to figure this out, so please help. I'm going to simplify it extremely, then I will hopefully be able to expand on it later.
I want to send a number from Matlab to basic stamp... that's it!
I'm going to have a stepper motor running through basic stamp, and based upon the number received from Matlab, I want the motor to run clockwise, counter clockwise, or not rotate at all.
I've been trying to figure out the Serin in basic stamp but haven't been able to figure it out.
So all I want is to send the numbers "1, 2 and 3" from Matlab to basic stamp.
Thanks in advance for the help!
-Nick
Comments
The first one is used to initialize everything:
FreqDetectable CON 3000
PiezoSp PIN 4 ' Speaker
serData VAR Word
counter VAR Word ' error tracker
looping VAR Word
sPin CON 16 'Serial Pin - P16, Programming port
Baud CON 84 'Baud mode for a rate of 9600, 8-N-1
'BS2P, BS2SX use 240 for 9600, 8-N-1
'
[ Initialization ]
FREQOUT PiezoSp, 1500, FreqDetectable 'Signal program start/reset.
SEROUT sPin, Baud, [LF] 'Send a lone LF to signal MATLAB start
counter = 0
'
[ Program Code ]
SEROUT sPin, Baud, ["This is your Boe-Bot", LF]
looping = 5
SEROUT sPin, Baud, [DEC looping, LF]
SerialIn:
SERIN sPin, Baud, [DEC serData]
Rest:
WRITE looping, serData
END
Then, I have the value multiplied by 5 in matlab, and sent back to the basic stamp via fprintf
Then I run the following program, and if the value sent from matlab is larger than 25, the motor rotates, if it is less, it doesn't rotate.
FreqDetectable CON 3000
PiezoSp PIN 4 ' Speaker
serData VAR Word
Phase VAR OUTB
counter VAR Word
idx VAR Byte
stpIdx VAR Nib
stpDelay VAR Byte
Steps DATA @100, %0011, %0110, %1100, %1001
'
[ Initialization ]
FREQOUT PiezoSp, 1500, FreqDetectable 'Signal program start/reset.
'
[ Program Code ]
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 15 ' set step delay
READ 5, serData
DEBUG DEC serData
IF serData > 24 THEN
FOR idx = 1 TO 48 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 5
ENDIF
END
'
[ Subroutines ]
' Turn stepper clockwise one full step (7.5 degrees)
Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step
' Read new step data and output to pins
Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN
END
And this works. However, is there a way to make this real time? Like, keep the basic stamp program running, then change the multiplier in matlab, and have the basic stamp recognize the change?
I was thinking of doing a loop around the entire "Read" section, but when I do this and run the matlab program, the matlab program won't run because it's trying to access the serial port...
thanks