Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp to serial port — Parallax Forums

Basic Stamp to serial port

mfavs327mfavs327 Posts: 11
edited 2008-01-17 20:17 in BASIC Stamp
Hi i have been working on a project since late december where there are a total of Five buttons.· four of the buttons are used to for characters while the fifth button changes the characters on the 4 buttons.· for example buttons 1 through 4 are A, S, D and F respectively but when you hit the 5th button then the buttons now change to J, K, L and ;.· The problem that i am running into is the part where you connect it to the PC.· in my program i set all the inputs and out puts that i need (4 inputs from the counter and 4 inputs for the buttons) at the beginning then i put:

If (IN0 = 0) AND (IN1 =0) AND (IN2 = 0) AND (IN3 = 0) AND (IN4 = 1) THEN SEROUT 16, 16780, [noparse][[/noparse]65]

Then i do that with the other characters.· the first four inputs come from a counter which sends the outputs in binary(like 0 0 0 0 or 0 0 0 1) and the last one is when i press a button which is connected to input 4.· From what i read that should work but im not getting anything when i connect it to the computer.· i connect to the computer using a D9 pin connecter with pin 2 to SEROUT, pin 3 to SERIN, pin 4 to ATN, pin 5 to ground and pin 6 connected to pin 7. should i have something in my program for SERIN or ATN (which i have no idea how to use since i didnt think you had to) and if so could you help or am i writing the program wrong(should i write it a different way.·

Thanks for your help

MFavs327

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-01-17 00:11
    mfavs327 -

    You can save yourself quite a few instructions if you're always looking at pin ports 0-3 as one entity. Pin ports 0-3 are also know in PBASIC as INA. Thus your statement could be reduced to the following:

    'Evaluate Pin ports 0-3 (INA)
    IF INA = %0000 THEN Bypass
    'Evaluate Pin port 4
    IF IN4 = 1 THEN SEROUT 16, 16780, [noparse][[/noparse]65]
    Bypass:

    That ought to cut back on the "typer's cramp" some·smile.gif

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Veni, Vidi, Velcro! - I came, I saw, I stuck around!

    Post Edited (Bruce Bates) : 1/17/2008 12:18:45 AM GMT
  • mfavs327mfavs327 Posts: 11
    edited 2008-01-17 01:20
    Thanks alot Bruce Bates.· That is very helpful.· But i need it so that when the counter is at 0 0 0 0 aka INA =%0000 then by hitting a button IN4, IN5, IN6 or IN7 will give me respectively A, S, D or F and then when the counter changes to INA = %0001 then buttons on IN4-7 will then be J, K, L or ;· while correct me if im wrong but your code right there bypasses A if the counter is at 0000





    Thanks for your help



    Mfavs327
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-17 18:07
    Hello,

    Are you connecting the BS2 I/O pins directly to the PC Serial Port? If so you may have damaged the I/O pins as they would not be able to tolerate the RS-232 voltages present on the PC Serial Port.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • mfavs327mfavs327 Posts: 11
    edited 2008-01-17 18:11
    i Did connect serout and Serin directly while i connected atn using to caps.... i did this using the diagram i got from the Parallax website...chris savage what way am i suppose to hook it up and if it is damaged how else can i hook it up?



    Thanks



    mfavs327
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-17 18:14
    The diagram we listed shows the dedicated serial ports on the BASIC Stamp. If you're using those you are fine. I was under the impression you were using P0 through P3 for communication.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-17 18:19
    What might simplify things a little is to assign the four keypad characters to an array dependent on the value of your counter (INA)

    Keys1 DATA "A","B","C","D"
    Keys2 DATA "E","F","G","H"
    Keys3 DATA "I","J","K","L"

    counter=INA

    LOOKUP counter,[noparse][[/noparse]Keys1,Keys2,Keys3 etc etc etc......],idx

    FOR· address=idx TO (idx+3)
    READ address,char(x)······· 'char is a 4 byte array
    x=x+1
    NEXT

    Then use INB as the index for the array
    key=INB
    index=NCD key
    SEROUT 16, 16780, [noparse][[/noparse]char(index-1)]

    of course you will have to work on it to get it how you want this is just the general idea.

    Jeff T.
    ·
  • mfavs327mfavs327 Posts: 11
    edited 2008-01-17 18:26
    Oh no ... im using pins 0-3 for the outputs of the counter.... could you please tell me the how i should hook it up or if i need to write a program for SERIN or ATN ... all i want to do is when i push a button on IN4 then it will SEROUT 16, 16780, [noparse][[/noparse]A]

    (an A will show up on the screen).... but when i attached the serial connection ( pin 2 to SEROUT, pin 3 to SERIN, pin 4 to caps and ATN and PIN 5 to ground) and press the button thats attached to the input 4 i get nothing.· Could you tell me what im doing wrong with my code which is shown above or if i need to hook it up differently or write something for SERIN Chris savage?



    Thanks



    mfavs327
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-17 20:17
    Not sure why you have special connections...I mean if you can download the program to the BASIC Stamp and DEBUG, then you can easily send data to the PC. If you board is serial can't you use the serial cable and programming port that is already connected?

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