Hi, i'm a noob to arduino and to this forum. And i'm from germany so excuse me if my english is bad. First of all: I LOVE THIS! Arduino seems to be really great. But:
I want to build a complex midi Controller with about 60 Faders or knobs, a few buttons and a few velocity sensitive drum trigger pads. As far as i know i would need one analog input for every fader, pad and knob, right? But all those Arduino boards only have 6 analog inputs. So how can i reach my goal? :-?
(Sorry if anyone asked a similar question before but i didn't find anything via the board search...)
Down below just suggest using an analog multiplexer like 4051 or a separate 16CH ADC (AD7490) interfaced with SPI.
hallo,
fuer die fader (potis ?) koenntest du einen analog multiplexer verwenden z.b. den 4051. (4051 und AVR Atmega8 - Mikrocontroller.net).
da kannst du mit 3 digital pins einen analogen pin auf 8 erweitern. um allerdings auf 60 zu kommen bedarf das etwas mehr arbeit.
vielleicht lohnt sich dann auch schon ein eigener ADC welcher ueber SPI angeschlossen wird. z.b. (AD7490 Datasheet and Product Info | Analog Devices). fuer 4 von denen braeuchtest du nur 7 digitale pins. data-out, data-in, clock, chip select 1-4.
fuer den anfang ist aber die 4051 methode einfacher zu verstehen und umzusetzen.
I will try to answer in english because some non germans might be intersted in this too. Ok:
if i would try it with multiplexer or adc will i be able to use these analog inputs simultaneously? how does it work? will i have to tell (program) arduino to step through the channels at a given frequency?
could i use 2 arduinos resulting in one unit with more channels?
where can i learn how to connect all this? (i'd really like to understand what i'm doing but i don't know where to start)
Ok, forget my last post, i just found the 4051 article in the playground ;D As i understand you can loop thru the multiplexer channels. But here we have the next question: How fast can arduino do this? Fast enough to have the feeling that there is no delay when you change the value of a fader/knob? Another question: what kind of fader/potentiometer will i have to use? 100kOhm?
I made a setup with two 4051 mux IC's and 16 slide potentiometers. I could read all 16 pots and put the 16 values in a string and send that string out the serial port to a PC program i wrote in 10 ms. I did not try any faster but it could probably be done faster with direct port manipulation in stard of Arduinos Digital read / write which is quite slow.
I used the code from the 4051 example in the playground as the base of my work, only made a few changes.
If you need 60 pots then you would need 8 4051's that might ad some more delay than in my case.
hmmm. In the ATmega168 data sheet there's some info about ADC conversion times per channel, but that depends on some frequency divider settings. Let's see what's used in the arduino code...
ok, in ../hardware/cores/arduino/wiring.c the prescaler for the ADC is set to 128. the cpu data sheet says something about 13 ADC clock cycles per conversion, so 13*128 = 1664 cpu clock cycles. so if I'm not mistaken one pin's conversion should take 100µs.
does anybody know if this really correct ?
switching the pins to control the 4051 is quite fast if you manipulate the I/O port directly.
there's a tutorial for this in the playground. the only problem with this is that "arduino pins" and "cpu ports" overlap
( http://www.arduino.cc/en/Hacking/PinMapping ).
you could switch the pins like this. this should be as fast as the hardware can:
int analog_fader_input_pin = 0; // analog pin 0
byte pin_A = 5; // digital pin 5 --> PORTD pin 5, 5th bit in the byte value of PORTD
byte pin_B = 6; // 6 --> PORTD pin 6
byte pin_C = 7; // 7 --> PORTD pin 7
int data[8] = {0,0,0,0,0,0,0,0}; // array to store 8 analog values from the 4051 mux chip.
void setup(void) {
// pinMode(...,INPUT); not needed for analog input pins
pinMode(pin_A,OUTPUT);
pinMode(pin_B,OUTPUT);
pinMode(pin_C,OUTPUT);
}
void loop(void) {
read_mux();
// do other stuff with the data...
}
void read_mux(void) {
byte BCD_counter;
for(BCD_counter = 0; BCD_counter < 8; BCD_counter++) { // Binary Coded Digit --> 4051 channel select pins A,B,C
PORTD = (PORTD & B00011111) + (BCD_counter << 5); // keep the lower bits 4...0 and add BCD_counter shifted 5 bits to the left to get to bits 7...5
data[BCD_counter] = analogRead(analog_fader_input_pin); // read analog fader value (0...1023) and store it in an array
}
}
thx, sounds good. just ordered my first arduino board and i guess i'll just try the 8 x 4051 setup. the only problem i see are the pads/buttons. when i hook up a button that should be recognized as 'on' as long as i press it there will be the risk that i press the button while arduino is reading all the other channels and release it before the channel of the button is read. in this case the button won't be recognized, right?
yeah, that's really cheap. I'll definitly try this. how high should the resistance of the potentiometers be? i read about a kit that comes with 10k potis. is that ok?
I bought some 10k slidepots (cheap) from Germany from www.pollin.de, it was a couple of yeras ago so i don't know if they still have them.
I think that Arduino can scan the 4051's so fast that there wil still be time to read the switches as well. Otherwise you could use an interupt for one or two very important switches, to give them "priority" over other controls.
The bigg issue will be the velocity sensitive pads
thx for all the info to both of you. i can't wait to play with my arduino. i'll first try to get the 4051 thing working. i think the velocity sensitive pads could be done with piezos? we'll see. guess i'll come with more questions soon
I've set my ADC's to 16 cpu cycles per clock cycle for a drum trigger system and it seemed to work well. For every ADC read, it takes about 250 cpu cycles (tested experimentally).
You got 60 analog switches and a response of 20ms (50 checks per second) should be good enough. To get constant values from your ADC switches I think you'd need to take at least 5 readings and make an average. Multiplying all that you get:
250 * 60 * 50 * 5 = 3.75 Million cycles, which is well below the 16Mhz capacity of the Arduino, so you should be ok.
For the velocity sensitive pads, you should definitely go for piezos. I've done a short program for that, but it's quite cpu-hungry at 1Mhz per channel. It's pretty precise, but I'm sure you could do something easier if you search on the net.