Shop OBEX P1 Docs P2 Docs Learn Events
Sensing switch positions and transmitting status via serial port — Parallax Forums

Sensing switch positions and transmitting status via serial port

Jerry RoachJerry Roach Posts: 13
edited 2009-08-06 19:15 in BASIC Stamp
I am working on a project to sense 5 switch positions and report switch status to the host computer at least 6 times a second. There will be 2 systems running simultaneously so each stamp must have a unique identification to the host computer. I was thinking of using 3 of the I/O ports to create an address to ID each stamp with dip switches. And then have 5 I/O lines sense the switch positions in a continuous loop. Effectively sending a byte of data in a loop to the host computer to interpret. I have tested this with the debug terminal using the following:
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
DEBUG ? IN0
DEBUG ? IN1
DEBUG ? IN2
DEBUG ? IN3
DEBUG ? IN4
DEBUG ? IN5
DEBUG ? IN6
DEBUG ? IN7
LOOP
I don't understand how to do this by transmitting the information to the computer (Via RS232) where It can be received and interpreted by the computer monitoring the stamp provided switch positions in another application besides the stamp debug software. Can anyone give me some pointers with the code? I've study up on the SEROUT command, but I don’t know how to program and test the switch monitoring with this function.

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-08-06 01:43
    If you don't want to use the debug terminal on the Stamp, you need a RS232 TTL converter (or build your own with MAX232). This converter will have Rx and Tx lines which you connect to your Stamp. Then you send the status of all inputs with "SEROUT port, baud, INL", if you know how to parse a byte into bits in your PC program. If not, you send each switch status as with your DEBUG, but with SEROUT instead.

    You can easily create a program in Visual Basic.NET Express (which is free), by using the Serial Control.

    Not sure if this is what you asked for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Jerry RoachJerry Roach Posts: 13
    edited 2009-08-06 01:56
    I would be using the stamp's serial line, so I'm not sure about needing the converter. So would the code look like this?

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

    SEROUT 1,16468,[noparse][[/noparse]INL]

    LOOP
  • dev/nulldev/null Posts: 381
    edited 2009-08-06 02:25
    I am not sure about this, but I think I read somewhere that the debug pin is 16, so it would be: SEROUT 16,16468,[noparse][[/noparse]INL]
    But you could just use DEBUG...

    DO
    DEBUG DEC INL
    PAUSE 100
    LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-06 14:55
    Unless you are planning to periodically modify your program why not use DATA or just plain variable to code the stamp identity. DIP switches are OK but - you need to wire them and add pull up / down resitors. It aslo limits you to the number of characters used as ID. ·Also you using "valuable" I/O ports to boot. With DATA you can get fancy and impress your superiors.
    Aslo use port 16 as suggested , it is easy to debug.
    Of course after you are done wiht your developent run you Stamps but stop the editor.

    ·
  • Jerry RoachJerry Roach Posts: 13
    edited 2009-08-06 18:53
    This code works -thanks!
    DO
    DEBUG DEC INL
    PAUSE 100
    LOOP

    But it is not sensing the the switch position in IN0. I no it works because it works on my previous program. Any thoughts? Also I changed DEC to SDEC.
  • Jerry RoachJerry Roach Posts: 13
    edited 2009-08-06 19:15
    I just got it to work at the bit level by using BIN in place of the SDEC. I'm not sure why this would make a difference with IN0, but it is transmitting the data the way I want it to now.
Sign In or Register to comment.