Using more buttons than avail. inputs,identifiable

Similar topics are out here already, yet no topic I found has the exact same requirements and therefor I have not found a solution yet... Here's the thing: I'm building a MIDI controller for which I need about 20 pushbuttons, and then some potmeters to control certain variables. There's not enough input pins to do that, so should I do something like charlie/multiplexing (is that possible on inputs too)? And if so, does that mess with latency? I want a latency as low as possible, because it's used to play music. Also (obviously) I need to be able to identify not only certain buttons, but also all possible combinations, so from what I gather putting multiple buttons on one pin with some different resistors isn't possible (or at best going to be a mathematical mess). Any thoughts?

Or you could use a Mega.

Yeah, I've thought about that, but I really can't justify the extra cost of that for just a couple of more pins (I don't need more than 30). And even if I could, I can't afford it...

How many simultaneous presses do you need to detect?

Just use a shift register or two:-

each one gives you 8 inputs at the cost of only 3 arduino pins. The latency will not be an issue especially in comparison with the built in latency of MIDI itself.

21... Is that impossible? I read something about i/o extender chips, but I don't really know anything about pros and cons of those in my situation, and I couldn't really find much about that either. EDIT: Thanks for that post Mike. So the latency is not big enough to worry about with that? I'll go for that then, and let you know how it goes. I'm building something similar to an EWI (electronic wind instrument), so I need quite a number of buttons, some potmeters for tuning, transposing, midi voice selection and maybe midi channel selection. Then a microphone to detect blowing and volume, and an FSR or two on the mouthpiece for bending and vibrato and all. If I had only got the buttons I'd be able to use the analog pins as digital pins and I could just manage... Your solution seems like the solution I need though, so I'll buy the components I need and let you know :)

Little update: my local hardware store only carries 2 shift registers, CD4015 (dual 4 bit) and 74HC595 (8 bit + latch output, whatever that may be). Can I use these too?

Don't forget you can hook up multiple push buttons (or whatever) to a single analog input pin with a series of resistors, and you can determine which button is pressed by the voltage coming in

you could do it with a 5x4 matrix! 4 outputs to drive the columns, and 5 inputs for the rows, then cycle through the columns in a loop. then depending which column is selected and which inputs are on gives you which buttons are being pressed. its not instant, but would be near enough! all that for 9 i/o pins!

No the 74HC595 is a serial in parallel out, you need a parallel in serial out. The 4015 is the same. This type of shift register is for getting more outputs. You need the one for getting more inputs.

The other thing you could try is the MCP23016, this gives 16 inputs on the I2C bus and has the advantage that you only need to monitor one pin to see if any of the 16 has changes. There is a playground article on this with some example code. It connects to analogue pins 4 & 5.

If you use a matrix like phill suggests you need diodes in line with the switches. The down side is that it won't detect two or more buttons being held down at the same time.

Yes you can use resistors and an analogue pin but I wouldn't go for more that 6 on any analogue pin or you will have trouble in unscrambling when more than one is pressed at once.

I respectfully disagree with both those staunents.

For what reason do you need diodes? and whats to stop you from detecting more than one button at the same time? Ok, techically you couldn’t detect buttons on other columns than the one selected, but effectively this doesn’t matter, as you’d be cycling through them so fast.

please forgive some of my unique words, its the predictive text on my phone!

First of all: thanks for all the suggestions! I've gotten a bunch of SN74HC165N's, and I'm gonna play with those and see how well it works. But smart as I am, I forgot to buy enough pull-down resistors, and I haven't got the right resistors to hook my MIDI-port up, so the real fun is delayed to tuesday. Once I get the basics working, I'll post my schematics and source around here, along with some pictures later. Am I building the world's first open source Electronic Wind Instrument? :P

Ok, a little additional question: I'm about to go to the hardware store again today, and I was wondering: with shift-registers, I will still need the same amount of pull-down resistors, right? So 2 per switch, as mentioned here: .

Not with a shift register. I would miss out the 100R series resistor, that is just over pedantic protection. With a shift register I would use the switch connected between the input and ground with a 10K (or so) pull up to 5V.

If you pull down on TTL circuits you need to do it at about 100R to 470R, the 10K mentioned in the web page is only for CMOS inputs.

From what you say I gather this: I let go of the 100ohm resistors. Then, in order to have a HIGH signal when a button is pressed and LOW when the button is not pressed, I use a pulldown resistor from 100R to 470R for each button I attach to the shift register. Is that right?

Yes but why are you so hung up on having a high when the button is pressed and a low when it is not. That is not the way grown ups look at things.

Pull down resistors take up more power than pull ups on TTL circuits that's why you should avoid them when ever possible.

Don’t the SN74HC165N’s that graey has only need < a microAmp to pull the inputs high or low?

Grumpy_Mike: I didn't know that, it doesn't matter in my situation, it just sounded more logical to me, HIGH when the button is pressed, but if pull up's take less power I'll go for LOW when the button is pressed, it matters nothing.

EmilyJane (or anyone else who knows): can you explain what you mean? I’ve been trying to find out myself (google etc), but with no succes…