Shop OBEX P1 Docs P2 Docs Learn Events
Two-way communication (BS2 - Desktop Computer) — Parallax Forums

Two-way communication (BS2 - Desktop Computer)

eyyYoeyyYo Posts: 14
edited 2007-10-03 23:20 in BASIC Stamp
Hello!
Im new to this thing with microcontrollers, but im catching on quick! Now i have been woundering a thing for a time now. How do you create a two way communication with a desktop·computer (Using BS2-IC)?
I want BS2 do do some things when i send a message to it, from my desktop computer. I also want my desktop computer do do some things when BS2 send a message. I have achieved to send a message to the computer, but havent been able to find documentation on how to send from pc->bs2.

Thank you in advance. /Adam

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 19:44
    If you've connected to the BS2 with a serial cable, the BS2 can 'talk' to the computer's serial port with:

    MAIN:
    SEROUT 16, 16468, [noparse][[/noparse]"Hi there!", CR]
    PAUSE 500 ' Pause 500 mSec, so BS2 doesn't 'flood' you
    GOTO MAIN

    On the PC, you'll have to open the serial port, or use the Debug window, or use Hyperterm to open the serial port.
  • eyyYoeyyYo Posts: 14
    edited 2007-10-03 20:01
    Yes, i know [noparse]:)[/noparse] I have done that. But whats the commands/check to do on the BS2 for a revieved "message"?

    like: (maybe crappy syntax and stuff, im just making example)
    IF REC_MSG = "open pin5" THEN
    out5 = 1
    endif

    so, when the computer sends (etc) "open pin5", the BS2-module will open pin5

    the computer programming i think i can figure out on my own (never used serial port in programming, though)
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-10-03 20:11
    SEROUT is used to send messages from the BS2 out to another device... SERIN is used to receive messages from another device to the BS2.
  • neotericneoteric Posts: 144
    edited 2007-10-03 21:01
    I'm no expert, but maybe can help.

    SERIN 16,baud,[noparse][[/noparse]WAIT("Turn On Pin 5"),SPSTR 75]··


    FOR x = 0 TO 74
    ·GET z,temp
    ·'do whatever you are going to do here'
    Next

    SERIN is the command to get data from the PC
    16 is the communications pin (stamp to pc)
    baud is the appropriate baud rate for the stamp you are using· (9600 for basic stamp, I believe)
    Wait is the command to wait for a particular string
    Get takes each character retrieved from the Serin, and reads it as a variable.

    Definitely look at the SERIN in the help file.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 21:06
    The simplist thing to do would be:

    SERIN 16, I9600, [noparse][[/noparse]DEC MyVal]
    IF MyVal = 1 THEN
    ' Do something here
    ENDIF
    IF MyVal = 2 THEN
    ' Do something here...
    ENDIF

    And you'd send something like:

    fprintf(serport, "1\n"); // This sends a "1" in a way the 'DEC' modifier will accept it.

    or

    fprintf(serport, "2\n"); // etc.
  • JSWrightOCJSWrightOC Posts: 49
    edited 2007-10-03 21:32
    To elaborate on what allenlane5 said, you could also do this

    Main:
    SERIN 16, I9600, [noparse][[/noparse]DEC MyVal] 'note that this limits you to 0-9
    BRANCH MyVal, [noparse][[/noparse]DoSomething0, DoSomething1, DoSomething2]

    DoSomething0:
    RunSomeCommand
    GOTO Main

    DoSomething1:
    RunSomeOtherCommand
    GOTO Main

    DoSomething2:
    RunThisAndThat
    GOTO Main

    etc.

    BRANCH will let you branch to up to 256 locations based on the value of MyVal. The labels consume no program space (I think?) and the execution would be faster than using IF...THEN loops.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-10-03 23:20
    If you want a fancier interface, you can check out StampPlot. It has several tutorials that will show you such things as putting a checkbox on the screen that you can read from the BASIC Stamp for a GUI interface.

    http://www.stampplot.com

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting Software
    Southern Illinois University Carbondale, Electronic Systems Technologies
Sign In or Register to comment.