Shop OBEX P1 Docs P2 Docs Learn Events
Serin — Parallax Forums

Serin

leshea2leshea2 Posts: 83
edited 2006-03-10 22:41 in BASIC Stamp
When I use this code, does the stamp serin the letters "ready", or the ASCII form of "ready" ?


' {$STAMP BS2sx}
' {$PBASIC 2.5}

YMTU··· VAR···· Word
GJH···· VAR···· Word
TGM··· DATA "God Bless The World !", 0

Main:
YMTU = TGM
GOSUB Main2
END
Main2:
SEROUT 16, 16624, [noparse][[/noparse]"ready"]
PAUSE 10
SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")]
GOSUB main3
END
Main3:
· READ YMTU, GJH
· YMTU = YMTU + 1
· PAUSE 100
· SEROUT 16, 16624, [noparse][[/noparse]GJH]
GOTO Main3
END

Thanks !

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-14 13:04
    With:
    SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")]
    It's waiting to get the ascii "ready" -- which is altogether different from "READY" (it's case sensitive, meaing capitals make a difference) -- and it'll sit there WAITing till it gets a ready from the other device.· It comes in as a series of letters, for sure (r e a d y).

    Make sense?

    Edit --
    By the way the quotation marks aren't part of what is sent from the device, or vice versa.

    "16624" baudmode -- are you using a BS-2sx or BS-2p?


    Post Edited (PJ Allen) : 2/14/2006 1:15:06 PM GMT
  • leshea2leshea2 Posts: 83
    edited 2006-02-14 18:46
    I'm using a BS-2sx and I know the quotation marks aren't part of what is sent or received from the device. My PC program is sending "ready" to my stamp, that's waiting for "ready", so the problem is that my stamp is receiving numbers instead of letters.
    Is there a formatter that will allow me to fix this ? Thanks !
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-14 18:56
    "ready" is sent as ASCII codes, a byte for each letter.·

    ready = $72 $65 $61 $64 $79
    READY·= $52 $45 $41 $44 $59

    Regarding your PC program -- is it sending "READY" or "ready"?· It makes a difference.


    Post Edited (PJ Allen) : 2/14/2006 7:17:14 PM GMT
  • leshea2leshea2 Posts: 83
    edited 2006-02-14 20:33
    I know it makes a difference, I just said that my PC is sending "ready" to my stamp. I just want to know if I can have my stamp convert the incoming data into text, so my stamp can receive "ready" instead of $72 $65 $61 $64 $79.

    Thanks !
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-14 21:54
    You have:
    SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")]
    GOSUB main3
    END

    Main3:
    · READ YMTU, GJH
    · YMTU = YMTU + 1
    · PAUSE 100
    · SEROUT 16, 16624, [noparse][[/noparse]GJH]
    GOTO Main3
    END


    · If your STAMP is GOSUB'ing to Main3: then it is receiving the message "ready"; if it doesn't, then it's not.· Is your PC program sending the ASCII character numbers for the ASCII codes for "ready"?

    · Given: SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")], the STAMP is waiting for a succession of bytes in the range of, I believe, $30 - $7A, furthermore those specified by that within the parentheses in succession.
    · Why do you figure this isn't so?· Because your program doesn't GOSUB?

    · I'd like to see an U/L of the program that you are using as opposed to "re-types".



    Post Edited (PJ Allen) : 2/14/2006 10:37:56 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-14 23:50
    OK --
    I only have a BS2, but I tested the attached program.· It waits for my terminal program to send it the message "ready" (lower-case).· In response, it print out to my lcd the message "God Bless The World!"

    Is that what you're looking for?


    · If so, you need to D/L it and make these changes:
    1. change the Baudmodes from 16468 to 16624
    2. SEROUT 0 to SEROUT 16
    3. STAMP directive from {$STAMP BS2} to {STAMP BS2sx}
    4. Save it with a name of your choice·
    It works for me -- it should work for you, too.·
    If not, why not?· smile.gif
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    Prelims:             'these are optional
       DIRS = $0F        'MSB INs, LSB OUTs
       OUTL = %00000000  'preset OUTs; P0&1 hi, LEDs ON
       INH  = %00000000  'preset INs; button bit0, Term bit1
    
    
    YMTU   VAR    Byte
    GJH    VAR    Byte
    
    DATA   "God Bless The World !", 0
    
    PAUSE 2000
    SEROUT 0, 16468, [noparse][[/noparse]$0C]             'this clears my serial LCD
    SERIN 16, 16468, [noparse][[/noparse]WAIT("ready")]
     
    FOR YMTU = 0 TO 20
    READ YMTU, GJH
    PAUSE 100
    SEROUT 0, 16468, [noparse][[/noparse]GJH]
    NEXT
    END
    



    Post Edited (PJ Allen) : 2/14/2006 11:54:15 PM GMT
  • leshea2leshea2 Posts: 83
    edited 2006-02-15 01:16
    I'm trying to communicate with a PC program, not an LCD. Is it a difference, because the code doesn't work. I made a new code but I don't understand why the command works fine until I add the serin command. My new code just sends data but doesn't receive it. The PC program that I’m communicating with is in pbasic language and if anyone has any ideas, please let me know.


    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}



    YMTU VAR Word
    GJH VAR Word


    TGM DATA "God Bless The World !", 0



    Main:
    YMTU = TGM
    GOSUB Main2
    END


    Main2:
    SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")]
    PAUSE 10
    READ YMTU, GJH
    YMTU = YMTU + 1
    IF (GJH = 0) THEN GOTO Main ELSE SEROUT 16, 16624, [noparse][[/noparse]GJH]
    GOTO Main2
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-15 03:07
    · Much as it pained me... I went and changed my program (ymtu2)·to use the programming connector for both the SERIN and the SEROUT and it worked.·
    · The irritating thing is the echo back, but that's to be expected.·
    · I've attached the program (ymtu3) --·all that needs to be modified are the Baudmodes and the Directive (for BS2sx.)· If it doesn't work, well,·then:· 1)·it's not getting the "ready" message (I think you're actually sending "READY") OR 2) there's a cabling fault (if it isn't the same one that you program your STAMP with.)

    · Either way -- from this point, I'm out.· Anybody else wants in, you have my leave.
  • steve_bsteve_b Posts: 1,563
    edited 2006-02-15 14:34
    I hope someone corrects me if I'm wrong.

    Your microcontroller is a digital device (for the most part) and it seens everything as 1's and 0's.· Like your home computer.

    So, the number 1 is the same as 0000 0001 as number 25 is the same as 0001 1001....

    There are HEX equivalents of these values and there are ASCII equivalents of these values......it's all really for aiding us humans in understanding what the controller is doing...but so far as the controller is concerned they're all just 1's and 0's!

    So, in your controller you have to tell it how to output it.

    This is right out of the help file for serout

    "Keep in mind that when we type something like "XYZ" into the SEROUT command, the BASIC Stamp actually uses the ASCII codes for each of those characters for its tasks. We could also typed: 88, 89, 90 in place of "XYZ" and the program would run the same way since 88 is the ASCII code for the "X" character, 89 is the ASCII code for the "Y" character, and so on. "



    There's also this 'special formatter' (I've never used this one)attachment.php?attachmentid=74081

    so...I'd assume you could do this

    serout 16, 16624, [noparse][[/noparse]ASC GJH],CR·· (The CR will drop each consequetive data on the next line...just makes things neat).



    If you want to test to see what your program does....then drop some debug statements here and there just giving a progress report (see your code snippet).
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    YMTU VAR Word
    GJH VAR Word

    TGM DATA "God Bless The World !", 0

    Main:
    debug "main program",CR
    YMTU = TGM
    GOSUB Main2
    END

    Main2:
    SERIN 16, 16624, [noparse][[/noparse]WAIT ("ready")]
    debug "serin successful",CR
    PAUSE 10
    READ YMTU, GJH
    YMTU = YMTU + 1
    IF (GJH = 0) THEN GOTO Main ELSE SEROUT 16, 16624, [noparse][[/noparse]GJH]
    debug "serout successful",CR
    GOTO Main2

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
    508 x 37 - 988B
  • eecs189eecs189 Posts: 10
    edited 2006-03-10 22:08
    PJ Allen, for your code for "God Bless the World" LCD, which pins from the LCD did you connect to the micro controller?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-10 22:41
    eecs --
    ymtu2.bs2 has SEROUT going to the LCD through "P0"
    ·
    N.B. -- SEROUT 0, 16468, [noparse][[/noparse]$0C]············ 'this clears my serial LCD

    In another Subject you posted, it looks like you are using a "parallel" LCD.· The above is for a serial LCD.· If your situation is like that in the Stampworks tutorial/s then you are using a parallel LCD and this won't work for you.

    Post Edited (PJ Allen) : 3/10/2006 10:46:57 PM GMT
Sign In or Register to comment.