Shop OBEX P1 Docs P2 Docs Learn Events
Multiple Inputs on one pin? — Parallax Forums

Multiple Inputs on one pin?

adamgoldmineradamgoldminer Posts: 6
edited 2009-02-01 23:41 in BASIC Stamp
Hello again,

I need to take inputs on a single BS1 I/O pin from four push-button switches (simple on/off) at a time.· Is there a way to do this?

In my brain I could take the four switches and create a binary number 0 through 15 (could I·use a DAC for this?)·and pass this binary digit to the IC through the one input pin.· It's the process of creating the binary number and passing it to the pin that is beyond me at this point.

There has to be some way to do it.· I just don't know if its practical or if it would just be cheaper to purchase a BS2 so I can have the extra pins.

Regards,

Adam

Comments

  • JonathanJonathan Posts: 1,023
    edited 2009-01-29 23:36
    Well, one way would be to make a voltage divder type thing and use the POT command to read it. Connect say a 10k resistor from the input of the POT circuit to ground. Have 4 different values of resistor connected to VDD and the switch, maybe 1k,4.7k,10k and 22k. Connect the other end of the switches to the input of the POT circuit. The values above should give you 4 different enough values to read with the POT command, but you may need to tweak them.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Desy2820Desy2820 Posts: 138
    edited 2009-01-30 00:16
    What do you need the buttons to tell you?·· Do you just need to know if any button·was pressed?· Or do you need to know which button was pressed?·

    Any button is as simple as connecting all the switches to the same input pin.· If the pin changes state, a button was pressed, but you'll have no way of knowing which button.

    If you need to know which button, the the·POT command with distinct resistances would work, as suggested above.
  • RICoderRICoder Posts: 91
    edited 2009-01-30 02:08
    I'd say go with a DAC or parallel to serial chip. The parallel to serial will do exactly what you are talking about which is take in the different pins that are active and send you a serial string of bits that will let you know what is on and what is off. Thing is, it will probably require you to use a couple of other pins, like 1 to flip the clock (for the serial bits shift) and probably one to do the internal shift in the chip from memory to output...but I can't be sure as I've only gone serial to parallel and not the other way.
  • MrBi11MrBi11 Posts: 117
    edited 2009-01-30 05:23
    I'd use a 74HC165 Parallel to serial chip Sold Here

    yes, it'll take more than one pin to operate, but you gain 8 inputs.

    4 for your buttons [noparse][[/noparse]2 if you matrix them] leaving 4 [noparse][[/noparse]6]others.

    you'll need 3 pins from the stamp [noparse][[/noparse]data, clock & latch] so you'll have to move 2 of your current inputs to the shift register.


    or use a PCF8574 I2C it will only take 2 pins from the Stamp and they can be shared with other I2C chips.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Smile ... It increases your face value!
  • metron9metron9 Posts: 1,100
    edited 2009-01-30 06:18
    Use a 555 timer for a square wave and Jonathan's resistors perhaps 1k 2k 3k 4k to set the frequency of the 555 timer then read the pulse width using the pulsin command. make sure you stay within the pulse maximum width for the processor you are using. That should be very accurate and allow a dozen switches or more. Also read the pulsin quite a few times to debounce. Not sure on the resistors but use something to vary the puls width for a bs2 to 10mS or so for each button so no buttons=10ms and button 1 = 20 ms then button 1 is on if >15ms and <25ms something like that. If you create a ladder you can adjust the code to fit the resistors using a setup in the program to read the target frequencies as you press each button and store the values in eeprom. Use one button that creates a timeout pulse much larger than any valid pulse. When you press that button the program knows it needs to setup the button array variables.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 1/30/2009 6:28:45 AM GMT
  • adamgoldmineradamgoldminer Posts: 6
    edited 2009-01-30 17:46
    Johnathan -

    I like the idea, and it seems the simplest solution. Desy I DO need to know WHICH pins are pressed.

    Would that method allow me to tell if two buttons or depressed at the same time? Which is actually the most that could be pressed because the switches are double throw rocker switches.

    Regards,

    Adam
  • JonathanJonathan Posts: 1,023
    edited 2009-01-30 18:06
    Adam,

    Yeah, it should be able to tell if two buttons are pressed at the same time. You may have to play with the resistor values. Set up the POT circuit, then debug values while playing with resistor values.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • adamgoldmineradamgoldminer Posts: 6
    edited 2009-01-30 19:53
    Great. I see what you mean. It will just be a matter of figuring out the correct scale and figure out which ranges correspond to which values of the output.

    Thanks for the help! I'll let you know how it goes.


    Adam
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-01-31 17:09
    In principle - you want 4 bits to binary encoder and than parallel to serial shift register. In this setup you·will need 3 input pins on your stamp.

    Unless you can reuse them you will "save" one pin!

    Is it "economical"?

    Cheers

    Vaclav
  • metron9metron9 Posts: 1,100
    edited 2009-02-01 03:14
    Here is the 555timer button to frequency circuit and program I postulated in the above post. I figured I better see if it would work.

    The output: Since I did a 3 time read of the pulsin to debouncec the button I had the debug output the error so you could see when that part of the code was working.

    The circuit is the Astable Operation half way down the page here http://www.uoguelph.ca/~antoon/gadgets/555/555.html

    The two resistors R6 and R7 are 1meg each The cap C1·is .1 not .01

    This should give high pulse above 132mS and returns a 0 when no button is pushed
    No button pushed will also be the case if the pulsin is out of a range set up by the lookdown code.

    The buttons basically put a resistor in parallel with the 1 meg resistor between pins 6 and 7

    Button 1 uses a 100k· R1
    Button 2 uses 1 meg·· R2
    Button 3 uses 2meg··· R3
    Button 4 uses 3meg·· R4

    Buttons are wired in series so that button 1 puts 100k in parallel with the 1meg on pins 6 and 7
    Buttons 2,3 and 4 add 1,2 or 3meg in series with the 100k

    This gives you 91k, 523k 756k and 859k for resistance between pins 6 and 7 on the 555 timer
    That changes the frequency by decreasing the resistance that charges the capacitor, the cap charges faster.

    Another way using a faster frequency perhaps would be to use the count command instead of the pulsin.

    Diptrace schematic attached as well.




    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 2/1/2009 3:22:04 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-02-01 03:26
    adamgoldminer,

    Here are a couple of things I did several years ago:

    Use the PULSIN command to read either the upper and lower pulse width to determine a resistor value with the method below.
    This method allows you to multiplex two analog signals (or fixed resistor values on a switch) into one input to the Stamp.
    webpages.charter.net/schwabelove/BasicStamp/vco.gif

    Another method that can be derived from reading a keypad which uses a similar principal already mentioned...
    webpages.charter.net/schwabelove/BasicStamp/3x5KeyPad.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • adamgoldmineradamgoldminer Posts: 6
    edited 2009-02-01 23:41
    Thank you all.

    A wealth of ideas for me to try.

    Jonathan's POT method still seems simplest. Also going to use this method to read a temperature from a thermistor.

    Regards,

    Adam
Sign In or Register to comment.