serial communication to basic stamp
gregory12345
Posts: 10
Hi, im working on a project and am using BS2sx and servo motors and serial data from Visual basic 6 from my PC. My servo needs a value from 500 to 3000 to define its position. when i use this code:
Main:
SERIN 16,240,[noparse][[/noparse]inputValue]
multiplier = 10
inputValue = inputValue * multiplier
PULSOUT 1,inputValue
PAUSE 20
GOTO main
If i enter the number 50 in my VB(500 in the stamp after the multiplication), then the servo should go to 0 degrees, but it doesnt. It just moves about 10 degrees on every click.
But if i change the code on the stamp to LOOP on the PULSOUT, the servo does turn to the desired position, but it is only able to send the data once from the VB form, so it does nothing on the second click onwards. The code:
Main:
SERIN 16,240,[noparse][[/noparse]inputValue]
multiplier = 10
inputValue = inputValue * multiplier
DO
PULSOUT 1,inputValue
PAUSE 20
LOOP
GOTO main
Can anyone help tell me where my error is? I need my VB to keep sending different positions for the servo on every click on the command button.
Main:
SERIN 16,240,[noparse][[/noparse]inputValue]
multiplier = 10
inputValue = inputValue * multiplier
PULSOUT 1,inputValue
PAUSE 20
GOTO main
If i enter the number 50 in my VB(500 in the stamp after the multiplication), then the servo should go to 0 degrees, but it doesnt. It just moves about 10 degrees on every click.
But if i change the code on the stamp to LOOP on the PULSOUT, the servo does turn to the desired position, but it is only able to send the data once from the VB form, so it does nothing on the second click onwards. The code:
Main:
SERIN 16,240,[noparse][[/noparse]inputValue]
multiplier = 10
inputValue = inputValue * multiplier
DO
PULSOUT 1,inputValue
PAUSE 20
LOOP
GOTO main
Can anyone help tell me where my error is? I need my VB to keep sending different positions for the servo on every click on the command button.
Comments
VB var byte
Main:
SERIN 16,240,[noparse][[/noparse]inputValue]
multiplier = 10
inputValue = inputValue * multiplier
for VB = 0 to 20·········· 'DO
PULSOUT 1,inputValue
PAUSE 20
next························ ·'LOOP
GOTO main
-Phil
BTW, when you screw up and forget to enter a subject, you can always edit the post using the pencil icon in the upper righthand corner. You don't need to start a new thread. Now you can delete your other post, using the "X" icon. Please do that now, before someone else responds to it. Then it will be too late. -P.
Post Edited (Phil Pilgrim (PhiPi)) : 5/26/2009 6:46:56 AM GMT
the second is that, my servo works from the value of 500 to 3000, but the maximum decimal value by serial port is 255, do you know of any way to in put 500 until 3000 in VB and still get the decimal value in the stamp without using a "multiplier" like mine. Thank you very much.
eg (at 4800 baud)
inputvalue Var Word
Do
SERIN 16,16884,20,time_out[noparse][[/noparse]WAIT([noparse]:)[/noparse],inputvalue.HighByte,inputvalue.LowByte]
time_out:
PULSOUT·1,·inputValue
Loop
If your transmitting ASCII values you would handle it more in line with Phil's code example
Jeff T.
SERIN 16, 240, [noparse][[/noparse]DEC3 inputValue], but the same appeared on my VB that i cant send more than 255, maybe there is something wrong with my VB code ey? my VB code is :
inputValue = cmdInput.Text
MSComm1.Output = Chr$(inputValue)
how can i change the setting on my VB to send more than 255?
thanks
So VB6 would look something like
DIM inputValue As String
inputValue = cmdInput.Text
MSComm1.Output = inputValue
If cmdInput.Text was "345" then VB6 would transmit the 3 ASCII character codes as 3 seperate bytes "51" "52" and "53" . The following command at the Stamp would place those characters into a single word value I have named indata
SERIN 16,16884,[noparse][[/noparse]DEC3 indata]
The better way to do it is to use a header for synchronizing and a terminating vbCR as follows
DIM inputValue As String
inputValue = ":" & cmdInput.Text & vbCR
MSComm1.Output = inputValue
at the Stamp
SERIN 16,16884,20,time_out,[noparse][[/noparse]Wait(":"),DEC indata]
I recommend the baud rate of 4800 inverted (16884)
Another problem you will face is that everything transmitted to the Stamp is echoed back to the PC's buffer and mixed in with the next data set so before you transmit from the PC you need to do a clear buffer whatever that command might be
check this link out for a few pointers http://forums.parallax.com/showthread.php?p=671804
Jeff T.
I tried changing the code using the DEC formatter and it works perfectly! But i did not understand what "time_out" and the 20 before "time_out" was for, so i did not use it. But it still works. Now my servo move to both maximum positions from 500 to 3000.
Thanks a milion
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen