sorry for the cryptic title. tried to fit as much info as possible.
here's the deal: been reading about the 4051 multiplexer solution to get more analog inputs into your arduino. i will use a 4051 as a multiplexer to be able to read 16 piezos (as drum triggers).
however, from all the code/threads i've read, i haven't been able to tell how one multiplexed signal from another. ie, they're all read by the same analogRead, aren't they? how does arduino know which of the 16 piezos hooked up to the 4051 is being triggered?
this is crucial if a user wants to use 16 sensors/pots hooked to 1 input pin - to be able to have the piezos eventually send different midi notes
thanks for your help. any example code would be much appreciated.
You select the input of the multiplexer to look at from the four select pins. If you write out the value on them that value (in binary) is the number of the input that is being looked at.
For example if all the select pins are zero then you will be looking at input zero.
If the least significant bit is high and all the others are zero then you are looking at input one and so on.
Just a note the 4051 only gives you 8 extra analog ins, so you would either need two or the 4067 whic would give you 16.
As Grumpy says, the 4051 (or 4067) doesent tell you anything, you will tell it to connect its one output to any one of its 8 (16) inputs at any given time and then use anallog read to read the sensor conneted to that input.
So you will basically have your Arduino tell the 4051 i want to read sensor 1, then i want to read sensor 2, then .... you get it right ?
i'm not sure i get it. i worry that my goal is unreachable here. i will try to quickly explain my goal:
i want the arduino to be listening to any of the mux's 8 inputs that are receiving a signal.
imagine a series of piezo drum triggers plugged into the inputs of the 4051. the idea is that each piezo would be interpreted send a different midi note (thus triggered different samples, like snare, kick, etc).
is it possible to have arduino listen to the 4051 and establish which input the signal is coming from, and then process the resulting data into a velocitative midi note?
i think i am beginning to understand. i would just have to have arduino glean which 4051 input is being utilized via the binary and then use an "if binary == xxx, then analogRead = drumx"
is this correct?
if so, it sounds like the turnover rate is very fast. will i be able to hook up 2 piezos to the 4051, have them trigger 2 different midi notes (snares, let's say) and then do a rapid roll without confusing the inputs?
and it will be happening much faster than we can react, but its still pretty slow from the cpu's side so it can handle what you got without becoming confused
if you need 16 channels its a OK deal, the DIP version of that chip only cost 2.95$ but since its not a large seller almost everyone is out until April when the next fat batch comes though
but on a personal (vendetta) note, I can not recommend a company who's website is a mine feild of "meh ok deals" and "WTF total rip offs" due to moral obligations
thanks again. i am ordering 10x 4051s. instead of using the 4067 and risking trouble when hitting 2 drums inputs on the same mux at the same time (unlikely as may be given the speed of mux input read switching). instead, i'll run several 4051s on the arduino and evenly distribute non-simultaneous drums across them.
since the open high hat and crash cymbal rarely are triggered simultaneously, for instance, they can live on the same mux. same with others.
i look forward to experimenting with these. both my other arduinos have just used the given 6 inputs and i had to be creative as to how to make that enough.
You can cascade the 4051s, but I'd be wary of what you are doing to the signals. It's analog, not digital, and every active or passive component you put the signal through degrades it one way or another.
You can run 6 of them (6 x 8 inputs) by connecting the select pins together (from 3 digital outputs of the Arduino) and run the analog output of each of the 6 to one of the Arduino analog input pins.
Do watch out for the signal range. Make sure the piezo's can't generate a larger voltage than the Arduino (and the 4051s) can accept. That's +5V for the basic Arduino, and could be 3.3V for a battery powered Arduino. Most piezos I am familiar with can output a much higher voltage when hit hard. You have to decide if you need to scale the actual range, or you need to clip the extremes (or some of both). A zener diode can clip, a voltage divider (two resistors) can scale.
i imagine that instead of cascading the 4051s, i'll simply run 2 of them on 2 separate analog pins. that way the signal is degraded less than if they were one-into-the-other.
regarding the signal range from piezos: i've already got the diodes in my shopping cart. i'd seen that in other arduino midi drum kits.
regarding the speed of mux input cycling and MIDI code generation/slowdown: i am generating one-time note on/off messages with no CC, sysex, or high bit signal. i'm hoping that this is simple enough to provide a fast return.
i am counting on the mux being able to be cycled fast enough based on the following quotes:
It is not possible to read or write more then one pin on the 4051 at the same time, because you can just select one pin at the same time. But you can read and write this pins quite fast. There is no delay needed between selecting and read or writing the pin.
it will be happening much faster than we can react, but its still pretty slow from the cpu's side so it can handle what you got without becoming confused
does anyone know just how fast these things can be told to cycle?
In 8x8 matrix, It will take (720 – 65) nano sec. for waiting 4051's response.
1 cycle for scanning 8x8 matrix takes :
(720ns ) * 8 * 8 = 46080 ns = 0.04608 miliseconds ,at least!
.04 ms is pretty tiny. even physical instruments like pianos have more latency. if it cycles that quickly, i can't possibly miss it - the piezo signal itself will be considerably longer than this.
this is a quote from "todbot" who created something like this:
I'm not sure which analog multiplexer works that you're using. It must have really high input impedance (around 10 Mohms) so you can sense the piezo's output voltage.