New to BS2: SERIN BUTTON
Hello,
I'm new to Basic Stamp.I'm using BS2 to do vertical aerial
photography.
The BS2 has to handle 5 switches (BUTTON) and serial input data
(SERIN) coming from a computer.
This one can send a byte each 2 seconds. But the time between the
bytes will be variable.
When a button is pressed, the BS2 has to send a string to a servo
microcontroller.
The problem is that it seems difficult to look at the serial port for
a coming byte without loosing data,
and to look at the buttons.
I suppose the difficulty comes from the fact that there is no serial
buffer.
What is the best way to proceed ?
Perhaps the best way is to use 2 stamps : 1 for serial input and the
other to handle the buttons ?
Does somebody has already exerienced this type of situation ?
Thanks for your help
Mario
This is the code (only the loop)
svo con 0 'use servo 0
sync con 255 'Mini SSC sync byte
pos var byte 'Byte variable holds position value
BtnWrk var byte
x var byte
n96n con $4054
loop1:
BUTTON 1,0,255,250,BtnWrk,1,mov01
BUTTON 2,0,255,250,BtnWrk,1,mov02
BUTTON 4,0,255,250,BtnWrk,1,mov04
BUTTON 5,0,255,250,BtnWrk,1,mov05
BUTTON 6,0,255,250,BtnWrk,1,mov06
serin 7,16468,[noparse][[/noparse]b3]
if b3 = "1" then relais1
if b3 = "2" then relais2
goto loop1
I'm new to Basic Stamp.I'm using BS2 to do vertical aerial
photography.
The BS2 has to handle 5 switches (BUTTON) and serial input data
(SERIN) coming from a computer.
This one can send a byte each 2 seconds. But the time between the
bytes will be variable.
When a button is pressed, the BS2 has to send a string to a servo
microcontroller.
The problem is that it seems difficult to look at the serial port for
a coming byte without loosing data,
and to look at the buttons.
I suppose the difficulty comes from the fact that there is no serial
buffer.
What is the best way to proceed ?
Perhaps the best way is to use 2 stamps : 1 for serial input and the
other to handle the buttons ?
Does somebody has already exerienced this type of situation ?
Thanks for your help
Mario
This is the code (only the loop)
svo con 0 'use servo 0
sync con 255 'Mini SSC sync byte
pos var byte 'Byte variable holds position value
BtnWrk var byte
x var byte
n96n con $4054
loop1:
BUTTON 1,0,255,250,BtnWrk,1,mov01
BUTTON 2,0,255,250,BtnWrk,1,mov02
BUTTON 4,0,255,250,BtnWrk,1,mov04
BUTTON 5,0,255,250,BtnWrk,1,mov05
BUTTON 6,0,255,250,BtnWrk,1,mov06
serin 7,16468,[noparse][[/noparse]b3]
if b3 = "1" then relais1
if b3 = "2" then relais2
goto loop1
Comments
I had a similar requirement in a project using a BS2p24.
I needed to receive a "random" serial input (which was from a RF
receiver - so I had no control over when the serial was coming in),
and at the same time continue processing other data.
This solution applies to any of the multi-slot BS2s (the BS2e,sx,p).
I set up a pollrun monitoring the serial input.. such that when
serial data was received the BS2 would run a program in another slot
which would deal specifically with the serial data and store the
result in scratchpad RAM. At the end of the message, control would be
passed back to the original program slot. The layout of slots I used
are as follows:
Slot 0 (default) - Initailisation and LCD menu data strings. The last
line in Slot ) is "Run 1"
Slot 1 (main program) - the main routines and loops. Pollin is set up
to scan the serial input pin. Pollrun is used to switch to Slot 2
when a signal (ie any change of level) occurs on that pin.
Slot 2 - deals with receiving the serial data, error correction etc,
and putting it into RAM for the main routine to use. The last
instruction in Slot 2 is "Run 1"
A few tips for this technique to work:
i) The serial data works best when a preamble is present. I sent the
following preamble of "$FF,$00,$FF,$88" before the data to make sure
I had a good pulse on the serial pin to kick the BS2p into Slot 2. It
works 100% reliable at 9600bps. The $88 marks the end of the preamble
and the start of the real data (since I may miss a part of the
preamble depending on timing)
ii) In slot one, avoid any long pause statements (you may miss a
serial input). Instead of using "pause 1000", use instead:
for n=1 to 100
pause 10
next
this allows the serial pin to be scanned whilst pausing.
This technique works for me. I love the pollrun command!
Dare
--- In basicstamps@y..., "mariobarp" <mario.barp@e...> wrote:
> Hello,
>
> I'm new to Basic Stamp.I'm using BS2 to do vertical aerial
> photography.
> The BS2 has to handle 5 switches (BUTTON) and serial input data
> (SERIN) coming from a computer.
> This one can send a byte each 2 seconds. But the time between the
> bytes will be variable.
> When a button is pressed, the BS2 has to send a string to a servo
> microcontroller.
>
> The problem is that it seems difficult to look at the serial port
for
> a coming byte without loosing data,
> and to look at the buttons.
> I suppose the difficulty comes from the fact that there is no
serial
> buffer.
>
> What is the best way to proceed ?
> Perhaps the best way is to use 2 stamps : 1 for serial input and
the
> other to handle the buttons ?
>
> Does somebody has already exerienced this type of situation ?
>
> Thanks for your help
> Mario
>
> This is the code (only the loop)
>
>
> svo con 0 'use servo 0
> sync con 255 'Mini SSC sync byte
> pos var byte 'Byte variable holds position value
> BtnWrk var byte
> x var byte
> n96n con $4054
>
> loop1:
>
> BUTTON 1,0,255,250,BtnWrk,1,mov01
> BUTTON 2,0,255,250,BtnWrk,1,mov02
> BUTTON 4,0,255,250,BtnWrk,1,mov04
> BUTTON 5,0,255,250,BtnWrk,1,mov05
> BUTTON 6,0,255,250,BtnWrk,1,mov06
>
> serin 7,16468,[noparse][[/noparse]b3]
> if b3 = "1" then relais1
> if b3 = "2" then relais2
>
> goto loop1