Midi controller, how many inputs are possible?

Hi, I am new to Ardunio, I just bought a Ardunio Duemilanove and made this project:

I want to expand on it and add more pots (faders and knobs) and buttons but the way the project is wired I cant because there is no more input pins in the Ardunio


Is there anyway to do this? Do i need an Ardunio mega?
Is there a better way to do this?

You can use external analog multiplexers to sample more analog inputs. You need some output pins to address the multiplexer(s).

How many analog inputs do you want?

How many switch inputs do you want?

Do you have any other I/O requirements? LEDs? Serial to/from a PC? Midi input? Midi output? Mass storage?

Once you decide way you want to build we can help you figure out a way to build it.

Thanks so much for the reply and info!!
I'm glad to hear I can add more.

I would like replicate most of the function of the Pioneer DJM-900 mixer

I don't need absolutely everything, but most things so:

20 switch inputs
30 analog inputs

No other requirements atm, in the future I would like to use LEDs and an LCD but I need to find out how to control them with my software first (Traktor)

The CD4051-style analog multiplexer chip has 8 inputs and 1 output. You can connect 4 of them to 4 of the Arduino's analog input pins. That will get you 34 analog inputs (32 through the multiplexers and 2 unused on the Arduino). You will need three data pins (say, D2, D3, and D4) to address the multiplexers.

You can connect CD4021-style shift registers to add groups of 8 inputs using only three more data pins (say, D5, D6, and D7):

Three shift registers will give you 24 switch inputs and, like the multiplexers, you can add more. That still leaves the Serial I/O pins (D0 and D1) the SPI pins (D10-D13) the I2C pins (A4 and A5) and a couple of spare data pins (D8 and D9).

unsigned int analogInput[8*4];
byte switches0, switches1, switches2;

const int multiplexerAddressPin0 = 2;
const int multiplexerAddressPin1 = 3;
const int multiplexerAddressPin2 = 4;
const int shiftinData = 5;
const int shiftinClock = 6;
const int shiftinLatch = 7;


void loop()
    {
    for (int channel=0; channel < 8; channel++)
        {
        setMultiplexerAddress(channel);
        analogInput[channel*4+0] = analogRead(A0);
        analogInput[channel*4+1] = analogRead(A1);
        analogInput[channel*4+2] = analogRead(A2);
        analogInput[channel*4+3] = analogRead(A3);
        }

    digitalWrite(shiftinLatch, HIGH); // Make sure the latch is high
    digitalWrite(shiftinLatch, LOW); // Latch the data on the falling edge
    switches0 = shiftin(shiftinData, shiftinClock);  // First shift register
    switches1 = shiftin(shiftinData, shiftinClock);  // Second shift register
    switches2 = shiftin(shiftinData, shiftinClock);  // Third shift register
    }

void setMultiplexerAddress(int channel)
    {
    digitalWrite(multiplexerAddressPin0, channel & 1);
    digitalWrite(multiplexerAddressPin1, channel & 2);
    digitalWrite(multiplexerAddressPin2, channel & 4);
    }

That's great, thanks buddy.

If I do that I will only be able to use 1 input at a time?

For example, will I be able to use two pots on the CD4051 chip simultaneously?
Will I be able to use two switches on the CD4021 chip simultaneously?

Siddy:
For example, will I be able to use two pots on the CD4051 chip simultaneously?
Will I be able to use two switches on the CD4021 chip simultaneously?

Depends what you mean by 'simultaneously'. Ruight now you can't access the existing inputs simultaneously, because you only have one CPU and it can only think about one thing at a time; also, you only have one A-to-D converter which you're sharing between all the analogue pins. The suggested solution would be no better or worse in that respect; you could read any input whenever you wanted to and it would be up to you to design your sketch to check them all regularly.

Thanks for the reply PeterH but I don't really understand what you said. Maybe simultaneously was the wrong word to use. What I mean is, can I turn two pots at the same time? Can I press and hold one button and then during that time press another button and will it all work?

can I turn two pots at the same time?

Yes

Can I press and hold one button and then during that time press another button

Yes

Have you seen this:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
It shows how to multiplex analogue inputs.

Big grin :smiley: