Author Topic: "Tricks" to connect multiple push switches with minimum i/o usage.  (Read 11999 times)

0 Members and 1 Guest are viewing this topic.

Offline firewalkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2452
  • Country: gr
What "tricks" do you use to connect multiple push switches with minimum i/o usage?

Lets say you have to connect 10 push switches but you don't to spare to many i/o ports. I have seen some people implementing an r-2r ladder and pushing the output to the mcu's analog input. After that it's all software.
Become a realist, stay a dreamer.

 

Offline Jimmy

  • Regular Contributor
  • *
  • Posts: 224
  • Country: au
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #1 on: March 04, 2011, 10:49:54 am »
You can wire the switches in a matrix to save inputs

How many switchs and how many inputs
 

Offline firewalkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2452
  • Country: gr
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #2 on: March 04, 2011, 10:54:25 am »
Not a particular project. I just saw the r-2r method and opened this discussion.
Become a realist, stay a dreamer.

 

Offline Jimmy

  • Regular Contributor
  • *
  • Posts: 224
  • Country: au
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #3 on: March 04, 2011, 11:13:46 am »
Cool

Their are many different options depending on the operation of device


To extent io you could use
RS232  1 pin simplex
I2C device 2 pin
Dallas 1 Wire 1 pin
Johnson counter 2 pin
SPI 4 pin
 

Offline apex

  • Regular Contributor
  • *
  • Posts: 72
    • Thoughts of a nerd
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #4 on: March 04, 2011, 02:47:39 pm »
If you add a diode to each switch, you could charlieplex them.
Or add a 555 with a different frequency to each one and then measure the frequency as seen on hackaday

apex
 

Offline Jon Chandler

  • Frequent Contributor
  • **
  • Posts: 539
    • Throw Away PIC
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #5 on: March 04, 2011, 02:48:16 pm »
I've used the R2R ladder approach to read 10 port pins with good results.  One analog input reads up to 10 switches with only a small investment in hardware.  Here's an article on how I do it.

An interesting approach from EDN is shown in: Read multiple switches and a potentiometer setting with one microcontroller input pin  Note that in the illustration here, the wire from the pot wiper is connected to the wire segment between the switches where it crosses.



A limitation of many methods of reading multiple switches is the case where more than 1 switch is pressed simultaneously.  You may get an erroneous reading or only read one of the switches.



Jon
 


Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11701
  • Country: my
  • reassessing directives...
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #7 on: March 04, 2011, 08:05:10 pm »
excellent Hero! i got a good friend though, he suggested to use abundant of pin count of 32bit micro, no need charlie. ymmv. ;)
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19823
  • Country: gb
  • 0999
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #8 on: March 04, 2011, 08:48:11 pm »
You're right. . .
How much more would the extra pins cost?

What's the extra cost of a larger MCU with more pins?

 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10180
  • Country: nz
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #9 on: March 04, 2011, 09:59:22 pm »
Quite often when you decide against the ideal solution it comes back to bite you in the ass later on.

« Last Edit: March 04, 2011, 10:01:46 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline dimlow

  • Frequent Contributor
  • **
  • Posts: 301
  • Country: gb
  • Likes to be thought of as
    • Dimlow Ponders
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #10 on: March 04, 2011, 10:00:22 pm »
I have used the ADC method is works well, i put four buttons on one pin. just a few resistors needed.
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #11 on: March 05, 2011, 06:43:50 am »
The ADC method is also popular for alarm sensor inputs.

You can detect 4 states with appropriate bias resistors:
Open Circuit (tampered wiring)
Normal open (sensor is active)
Normal closed (sensor is not active)
Short Circuit (tampered wiring)


 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11701
  • Country: my
  • reassessing directives...
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #12 on: March 05, 2011, 11:33:51 am »
You're right. . .
How much more would the extra pins cost?
What's the extra cost of a larger MCU with more pins?
well my good friend said, it only cost a few cents more. but thats just my friend's saying, not me. i prefer charlie. it keeps my brain working ;)
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #13 on: March 05, 2011, 11:59:29 am »
Quite often when you decide against the ideal solution it comes back to bite you in the ass later on.

No, when you grow up you figure out there is usually no ideal solution and you always have to compromises.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19823
  • Country: gb
  • 0999
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #14 on: March 06, 2011, 10:07:54 am »
well my good friend said, it only cost a few cents more. but thats just my friend's saying, not me. i prefer charlie. it keeps my brain working ;)
It could also be useful if the switches are on another PCB and connected via a cable. There again it might also work out more economical to put a cheap PIC, e.g. PIC16F54/57 with loads of pins on the PCB containing the switches and transmit the data serially.
 

Offline Jon Chandler

  • Frequent Contributor
  • **
  • Posts: 539
    • Throw Away PIC
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #15 on: March 06, 2011, 01:28:33 pm »

It could also be useful if the switches are on another PCB and connected via a cable. There again it might also work out more economical to put a cheap PIC, e.g. PIC16F54/57 with loads of pins on the PCB containing the switches and transmit the data serially.


It seems like there's a lot of resistance to using the analog R2R method - no pun intended :)  It works well and it's ideal for a remote keypad application as only 3 wires (maybe only 2) are required for the interface.  Testing for which switch is pressed is pretty simple, with a small range of voltage representing each switch.  For a reasonable number of keys, if 1% resistors are used, no calibration is required, and if all the resistors are on one circuit board exposed to the same environment (i.e., the same temperature) there won't be any issues with drift.  If the ladder is powered from Vdd and the ADC reference is Vdd, there's not even a problem if supply voltage varies.

A quick search on Digikey shows that 1% resistors are about 4 cents a piece, so a ten-key array would cost about 50 cents over the cost of the switches, be interfaced with 3 wires over a distance, use 1 port pin and be simple to program.  No complexity of using a I2C port expander nor the wiring complexity of Charlieplexing.  This really is a simple, effective solution to reading multiple keys as long as only reading one key at a time is needed.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11701
  • Country: my
  • reassessing directives...
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #16 on: March 06, 2011, 03:48:19 pm »
what i learn so far:

r2r ladder:
pro: only one adc needed for 4 switches (maybe up to 6, but i dont think stability is guaranteed for 8 switches)
con: need an adc capable mcu, and adc reading is not as fast as digital input, (1), cannot (2), a bit (3)

charlieplexing:
pro: n*(n-1) switches for n pins (beneficial for larger n>2), (2)
cons: need diodes and (3)

high pin count mcu:
pro: no need (1), just direct register read, hence fast. (2), less (3), more room for processing power/features for higher end mcu.
con: more expensive mcu (by just a few cents or dollars).

(1) extra programming to decode
(2) read simultaneously pressed switches correctly
(3) complexity in circuitry

my 2cnts learning.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19823
  • Country: gb
  • 0999
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #17 on: March 06, 2011, 04:12:43 pm »
Here's how to use 4017 to enable 100 switches to interface with an MCU using just three pins.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11701
  • Country: my
  • reassessing directives...
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #18 on: March 06, 2011, 06:21:26 pm »
ok let me add...
4017s:
pro: unlimited switches, 3 pin mcu only.
con: you need 4017s
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19823
  • Country: gb
  • 0999
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #19 on: March 06, 2011, 07:30:05 pm »
Buy they're so cheap as are the jelly bean transistors - I couldn't find a cheaper MCU with enough pins.
 

Offline abbtech

  • Contributor
  • Posts: 39
    • Alan's Electronic Projects
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #20 on: March 08, 2011, 09:35:11 am »
You could use some 74HS165 chips, costs you a few inputs but you then have unlimited button count possibilities.
Personal projects http://alan-parekh.com
Other cool project ideas http://hackedgadgets.com
 

Offline smackaay

  • Regular Contributor
  • *
  • Posts: 53
    • Steve's Junk
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #21 on: March 13, 2011, 10:46:26 pm »
My favorite solution has always been to use a separate MCU with no frills and gimmicks like a pic16f505. You can use a matrix for the keys and use internal values to produce a debouncing algorithm that acts to produce a threshold for the switches. you can then use a serial out interface and tell the master MCU which keys have been pressed and un-pressed.
Come see my boring site - http://smackaay.com/
 

Offline bilko

  • Frequent Contributor
  • **
  • Posts: 405
  • Country: 00
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #22 on: March 31, 2011, 11:34:45 pm »
Use a $3 pc keyboard and decode the serial stream. Strip the keys and use the matrix
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: "Tricks" to connect multiple push switches with minimum i/o usage.
« Reply #23 on: April 11, 2011, 07:42:15 pm »
Check this switch matrix out: http://ww1.microchip.com/downloads/en/AppNotes/01081a.pdf
Of course you can use it directly with a PIC.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf