Shop OBEX P1 Docs P2 Docs Learn Events
Sending variables between stamp — Parallax Forums

Sending variables between stamp

ArchiverArchiver Posts: 46,084
edited 2003-11-19 19:06 in General Discussion
what im trying to do is, have two basic stamp 2's setup. The first
one would perform a loop to gather sensor input data, and the second
stamp would perform the output data. Both stamps would be running
two different programs. I want to try to "network" work the two
together so the first stamp that performs the sensor input to send
its data result's to the second stamp to be used in its own program...

im to clear on how to use the shiftin/out commands ( i was thinking
that be best way to send information between the to) but below is
some programs i shot together real quick give a idea of what i want
to do with the two stamps

the first stamp will have two MAX187 Analog digital convert's
gathering anlog values to be stored as variables in the code for the
stamp.

'{$STAMP BS2}
'{$PBASIC 2.5}
TB_POS VAR WORD
MAP_SEN VAR WORD
INJECT VAR WORD

X VAR WORD
X0 CON 1000
X1 CON 1100
X2 CON 1200
X3 CON 1300
X4 CON 1400
X5 CON 1500
X6 CON 1600
X7 CON 1700


MAIN:
HIGH 1
LOW 1
SHIFTIN 2,0,MSBPOST,[noparse][[/noparse]TB_POS\3] 'get value of sensor 1
HIGH 4
LOW 4
SHIFTIN 5,3,MSBPOST,[noparse][[/noparse]MAP_SEN\4] 'get value of sensor 2

LOOKUP TB_POS ,[noparse][[/noparse]x0,x1,x2,x3,x4,x5,x6,x7],X 'this is part of my 3d
table that will get a 3rd variable for the correct injector width

SHIFTOUT 10, 8, MSBPOST,[noparse][[/noparse]INJECT] ' this part of program will then
send the correct pulsewidth that is calculated from the 3d table,to
the second stamp. So that the 2nd stamp will run its own program
with the correct variable sent from the first stamp

end of program****

the second stamp program is below, this program is used to perform
the triggering of when to fire the injector's


'{$STAMP BS2}
'{$PBASIC 2.5}
PULSE_WIDTH VAR WORD 'variable to be entered from the first stamp
INPUT 14
INPUT 13
INPUT 10
OUTPUT 12
OUTPUT 11

BOOTUP:
IF IN14 = 0 THEN STUCK
GOTO MAIN
STUCK:
IF IN14 = 0 THEN STUCK
GOTO MAIN
INJECT1:
PULSOUT 12, PULSE_WIDTH
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
INJECT2:
PULSOUT 11, PULSE_WIDTH
IF IN13 = 0 THEN MAIN4
GOTO MAIN

MAIN: 'MAIN loop, this part of
program will run looplessly , getting information from the sensor
stamp to be used once its triggred from the if then command.
SHIFTIN 10,8,MSBPOST,[noparse][[/noparse]PULSE_WIDTH\4]
IF IN14 = 0 THEN INJECT1
GOTO MAIN
MAIN2:
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
MAIN3:
IF IN13 = 0 THEN INJECT2
GOTO MAIN3
MAIN4:
IF IN13 = 0 THEN MAIN4
GOTO MAIN



***end of program



Over all the two s tamps would be running on different cycles , my
goal is to have the second stamp thats running the injectors to
update it self from its own request from the first stamp , so it will
then shiftin the results of what the other stamp has stored in its
variable ...


please help if anyone can help me

Sean....

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-19 15:53
    I believe SERIN/SEROUT with some of the
    'Open Collector' options is the best way
    to connect two stamps. Much simpler than
    trying to synchronize a SHIFTIN/SHIFTOUT pair.


    --- In basicstamps@yahoogroups.com, "djrevolution99"
    <djrevolution99@y...> wrote:
    > what im trying to do is, have two basic stamp 2's setup. The first
    > one would perform a loop to gather sensor input data, and the
    second
    > stamp would perform the output data. Both stamps would be running
    > two different programs. I want to try to "network" work the two
    > together so the first stamp that performs the sensor input to send
    > its data result's to the second stamp to be used in its own
    program...
    >
    > im to clear on how to use the shiftin/out commands ( i was thinking
    > that be best way to send information between the to) but below is
    > some programs i shot together real quick give a idea of what i want
    > to do with the two stamps
    >
    > the first stamp will have two MAX187 Analog digital convert's
    > gathering anlog values to be stored as variables in the code for
    the
    > stamp.
    >
    > '{$STAMP BS2}
    > '{$PBASIC 2.5}
    > TB_POS VAR WORD
    > MAP_SEN VAR WORD
    > INJECT VAR WORD
    >
    > X VAR WORD
    > X0 CON 1000
    > X1 CON 1100
    > X2 CON 1200
    > X3 CON 1300
    > X4 CON 1400
    > X5 CON 1500
    > X6 CON 1600
    > X7 CON 1700
    >
    >
    > MAIN:
    > HIGH 1
    > LOW 1
    > SHIFTIN 2,0,MSBPOST,[noparse][[/noparse]TB_POS\3] 'get value of sensor 1
    > HIGH 4
    > LOW 4
    > SHIFTIN 5,3,MSBPOST,[noparse][[/noparse]MAP_SEN\4] 'get value of sensor 2
    >
    > LOOKUP TB_POS ,[noparse][[/noparse]x0,x1,x2,x3,x4,x5,x6,x7],X 'this is part of my 3d
    > table that will get a 3rd variable for the correct injector width
    >
    > SHIFTOUT 10, 8, MSBPOST,[noparse][[/noparse]INJECT] ' this part of program will then
    > send the correct pulsewidth that is calculated from the 3d table,to
    > the second stamp. So that the 2nd stamp will run its own program
    > with the correct variable sent from the first stamp
    >
    > end of program****
    >
    > the second stamp program is below, this program is used to perform
    > the triggering of when to fire the injector's
    >
    >
    > '{$STAMP BS2}
    > '{$PBASIC 2.5}
    > PULSE_WIDTH VAR WORD 'variable to be entered from the first stamp
    > INPUT 14
    > INPUT 13
    > INPUT 10
    > OUTPUT 12
    > OUTPUT 11
    >
    > BOOTUP:
    > IF IN14 = 0 THEN STUCK
    > GOTO MAIN
    > STUCK:
    > IF IN14 = 0 THEN STUCK
    > GOTO MAIN
    > INJECT1:
    > PULSOUT 12, PULSE_WIDTH
    > IF IN14 = 0 THEN MAIN2
    > GOTO MAIN3
    > INJECT2:
    > PULSOUT 11, PULSE_WIDTH
    > IF IN13 = 0 THEN MAIN4
    > GOTO MAIN
    >
    > MAIN: 'MAIN loop, this part of
    > program will run looplessly , getting information from the sensor
    > stamp to be used once its triggred from the if then command.
    > SHIFTIN 10,8,MSBPOST,[noparse][[/noparse]PULSE_WIDTH\4]
    > IF IN14 = 0 THEN INJECT1
    > GOTO MAIN
    > MAIN2:
    > IF IN14 = 0 THEN MAIN2
    > GOTO MAIN3
    > MAIN3:
    > IF IN13 = 0 THEN INJECT2
    > GOTO MAIN3
    > MAIN4:
    > IF IN13 = 0 THEN MAIN4
    > GOTO MAIN
    >
    >
    >
    > ***end of program
    >
    >
    >
    > Over all the two s tamps would be running on different cycles , my
    > goal is to have the second stamp thats running the injectors to
    > update it self from its own request from the first stamp , so it
    will
    > then shiftin the results of what the other stamp has stored in its
    > variable ...
    >
    >
    > please help if anyone can help me
    >
    > Sean....
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-19 19:06
    Hi Sean,

    The SHIFTIN/SHIFTOUT commands on the Stamp can be master only, not
    slave, so you cannot use them to share data between two Stamps.

    As others have said, SERIN/SEROUT are the way to go, especially if
    you can add a flow control line. You might find something helpful at
    this URL...

    http://www.emesystems.com/BS2rs232.htm#MasterSlave

    -- regards,
    Tracy
Sign In or Register to comment.