Read 6 Push Buttons using only 3 I/O pins (and no other part

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
wholder
 
Posts: 59
Joined: Mon Mar 16, 2009 2:09 pm

Read 6 Push Buttons using only 3 I/O pins (and no other part

Post by wholder »

I recently came up with a way to read the state of 6 push buttons using only three I/O pins and wanted to share it. You may find this especially interesting for pin-limited boards, such as the Gemma and Trinket. My idea may have been invented before but, so far, I've not found a reference that describes the same technique, so I've shamelessly named it WaynePlexing after the Charlieplexing (http://en.wikipedia.org/wiki/Charlieplexing) method often used with LEDs. To see how my idea works, see my writeup at:

https://sites.google.com/site/waynehold ... ng-buttons

Or, if you have seen this technique used before, please leave a comment and dash all my dreams of short-lived fame and glory.

Wayne

User avatar
lburnham
 
Posts: 23
Joined: Wed Jul 16, 2014 10:56 am

Re: Read 6 Push Buttons using only 3 I/O pins (and no other

Post by lburnham »

Can pin d1 be used as an input on the gemma?

User avatar
lburnham
 
Posts: 23
Joined: Wed Jul 16, 2014 10:56 am

Re: Read 6 Push Buttons using only 3 I/O pins (and no other

Post by lburnham »

"All the GPIO pins can be used as digital inputs, digital outputs, for LEDs, buttons and switches etc"
Just noticed this.

User avatar
SeiRruf
 
Posts: 82
Joined: Thu Sep 04, 2014 3:07 am

Re: Read 6 Push Buttons using only 3 I/O pins (and no other

Post by SeiRruf »

This is a very excellent, awesome idea for those who absolutely need more buttons but have limited pins. I think I'd personally rather stick with the Analog approach, where you can hook a number of buttons using only one pin and a few resistors. But this is definitely something to keep in mind.

One thing though, I noticed for this to work, you have to short pins to each other. Without a 10K resistor in between the circuit, wouldn't this eventually if not right away damage the arduino? Speaking from this reference schematic (below)

Image
Cited from: ruggedcircuits.com/10-ways-to-destroy-an-arduino

Just something I'm pondering on.

User avatar
wholder
 
Posts: 59
Joined: Mon Mar 16, 2009 2:09 pm

Re: Read 6 Push Buttons using only 3 I/O pins (and no other

Post by wholder »

Thanks for the reply. No resistor is needed and there is no danger of shorting two pins as long as the programming is handled correctly. The trick that makes this work is the AVR family's ability to switch the pin's function as Input vs Output independently from its state (High vs Low.) The code flips these in a particular order (see my article) to prevent a pin from ever being set as an output in the high state. At any given time, a pin can be an Input with the pull up resistor engaged, or an output that's in the Low state.

Wayne

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”