Shop OBEX P1 Docs P2 Docs Learn Events
two BS2s communicating. — Parallax Forums

two BS2s communicating.

ilyailya Posts: 13
edited 2008-04-01 16:26 in BASIC Stamp
I am attempting to have one BS2 send a variable to another. As a test, i created two programs for two BS2s, one to send a variable and one to receive. I have both BS2s wired to a gnd and a 5 volt source. There is also one wire running from the I/O of one BS2 to an I/O of the other. The program for the sending BS2 is:

' {$STAMP BS2}
' {$PBASIC 2.5}


ActualAngleDegr VAR Word

ActualAngleDegr = 56

SEROUT 5,396,[noparse][[/noparse]"!", DEC ActualAngleDegr, ";"]

The program for the reciever BS2 is:

' {$STAMP BS2}
' {$PBASIC 2.5}

ActualAngleDegr VAR Word
MoveTo CON 2

SERIN 0,396,[noparse][[/noparse]WAIT("!"), DEC ActualAngleDegr]

DEBUG MoveTo, 0, 3, "ActualAngleDegr is: ", ActualAngleDegr, " "

The debugger opens but no text is written and the variable is not displayed. Any thoughts/suggestions? Thanks.

-Ilya

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-04-01 01:49
    you need to send the data when the stamp #2 is waiting for it. Try looping the send every second and then see what you get. You might want to put a timeout on the receive serin and loop that program as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ilyailya Posts: 13
    edited 2008-04-01 03:49
    When running the code below I get: "ActualAngleDegr is: _"

    One BS2 code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    reps VAR Nib
    ActualAngleDegr VAR Word

    FOR reps = 1 TO 100

    ActualAngleDegr = 95

    SEROUT 5,396,[noparse][[/noparse]"!", DEC2 ActualAngleDegr]

    PAUSE 1000

    NEXT

    Second BS2 Code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    ActualAngleDegr VAR Word
    MoveTo CON 2

    DO
    SERIN 0,396,[noparse][[/noparse]WAIT("!"), DEC2 ActualAngleDegr]

    DEBUG "ActualAngleDegr is: ", ActualAngleDegr, " "
    LOOP

    Any thoughts as to why the variable does not come out as 95 as the result?
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-04-01 04:23
    ilya

    Are you using this set up



    See the [url=mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2.6\PBASIC.chm::/serin_ex.htm]example program[/url] for a flow control example using two BS2s. In the demo program example, without flow control, the sender would transmit the whole word "HELLO!" in about 6 ms. The receiver would catch the first byte at most; by the time it got back from the first 1-second PAUSE, the rest of the data would be long gone. With flow control, communication is flawless since the sender waits for the receiver to catch up.

    In the figure below, I/O pin 0, FPin, is pulled to ground through a 10 kΩ resistor. This is to ensure that the sender sees a stop signal (0 for inverted communications) when the receiver is being programmed.

    [img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2.6\PBASIC.chm::/graphics/flow_ctrl_sch.gif[/img]




    1. When using a BS2-family module, you can simplify Baudmode parameter selection by using conditional compilation. The example below can be included in the standard programming template and will handle most serial IO requirements. Remember that defining constants does not affect compiled program space, and yet does make program debugging easier.
    2. [img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2.6\PBASIC.chm::/graphics/bs2all_inline.gif[/img]
    ' {$PBASIC 2.5} #SELECT $STAMP #CASE BS2, BS2E, BS2PE T1200 CON 813 T2400 CON 396 T4800 CON 188 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 #CASE BS2SX, BS2P T1200 CON 2063 T2400 CON 1021 T4800 CON 500 T9600 CON 240 T19K2 CON 110 T38K4 CON 45 #CASE BS2PX T1200 CON 3313 T2400 CON 1646 T4800 CON 813 T9600 CON 396 T19K2 CON 188 T38K4 CON 84#ENDSELECTSevenBit CON $2000Inverted CON $4000Open CON $8000Baud CON T9600 + Inverted ' match DEBUG

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-01 14:36
    Are both BASIC Stamps running from the same supply or their own individual supplies?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • ilyailya Posts: 13
    edited 2008-04-01 16:04
    They are both running on the same power supply.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-01 16:26
    Whoops, I looked at your code again…you’re converting the variable to a string when you send it, however, you cannot receive a string into a single variable like that. First of all, your variable should be declared as a BYTE, not WORD. Second, you should not covert it to ASCII string using DEC to when sending and receiving, only when displaying it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.