Shop OBEX P1 Docs P2 Docs Learn Events
Program Help: Sending information serially through a pin — Parallax Forums

Program Help: Sending information serially through a pin

ryan.elkholyryan.elkholy Posts: 6
edited 2006-07-27 15:30 in BASIC Stamp
Hello,

In my project I have 4 input pins and four output pins. I would like to monitor the state of each pin (high or low) and send that information out to an external interface (such as labview) using only one other pin on the Basic Stamp. This way I do not have to connect a wire to each pin and have 8 wires coming out of the system. It will be clean and only have one connection. Does anybody know how I would be able to program this????

Any help is greatly appreciated!!!

-Ryan

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2006-07-26 14:47
    Ryan

    For example, suppose the 4 in and 4 outs were adjacent pins on the Stamp, using p0 through p7.

    Your code would be:

    x var byte
    x = INL
    SEROUT outputpin, baudrate, [noparse][[/noparse] x ] ' see SEROUT in the Help file

    To send to a "regular" serial device, you could use pin 16 (the program interface). Or, use any other pin and specify the Inverted mode.

    Cheers
  • ryan.elkholyryan.elkholy Posts: 6
    edited 2006-07-26 15:15
    Thanks a lot, I will try that out now!
  • ryan.elkholyryan.elkholy Posts: 6
    edited 2006-07-26 19:41
    I ran into a new problem.

    This is not necessary, but it would save a great deal of wiring. If I accept a string of states serially into a pin how would I be able to distribute the string and match each state up to output pins. For example, I receive a string 0101 and I want that string to tell each output pin in P0-P3 what state to be in. So P0 = 1, P1 = 0, P2 = 1, P3 = 0. I tried looking in all the HELPS and tutorials online and could not find it. Any help would be greatly appreciated.

    Thanks,
    Ryan
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-26 20:13
    Ryan -

    You can address _sequential_ output pins in any of the following grouped manners:

    OUTS all output pins

    OUTL 0-7 OUTH 8-15

    OUTA 0-3 OUTB 4-7 OUTC 8-11 OUTD 12-15

    So in your example you would do this:

    OUTA = %0101

    Hope that gets you started.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • ryan.elkholyryan.elkholy Posts: 6
    edited 2006-07-27 11:56
    Thaks, I will try that out!
  • ryan.elkholyryan.elkholy Posts: 6
    edited 2006-07-27 15:30
    Here is a different question. If I want to take that string of inputs (0101) and write an if statement using either the 1st, 2nd, 3rd or 4th location of that string from the pin, then how do I do that.
Sign In or Register to comment.