Help Reading multiplexer pins

Hi all,

i have just reccieved Some bits from mouser.

PCA9535D I2C Multiplexer MC14067 Mux Demux

with the MC14067 i know how to connect it to the arduino but i cant figure out how to read the inputs!

I have seem examples from the website, but ho do i read the values of each pin indiviually?

thanks in advance

Darrell

It has lots of inputs and one output. Connect the output to the analogue input pin of your choice.

The select lines (or control lines) should be connected to arduino digital output pins. Then set these output pins to some binary value and the input corresponding to that binary value is switched through to the output and you can read it with the analogue read.

These are analogue multiplexers so I assume you want to look at analogue signals not digital ones.

I have wired up the multiplexer, that's not the problem!

I can't find an example anywhere of how how to get readings!

I have x4 10k faders and 4 1k pots.

the goal is to be able to detect the change of resistance and pass the valuesi on using midi.

I can't find an example anywhere of how how to get readings!

val = analogRead(pin);

?? what is the problem?

my problem is I cant figure out how to read the multiplexer pins.

I can't find an example that explains how it's done step by step.

Sorry but if you have wired the multiplexer's output to the analogue input. And you have wired the multiplexer's control lines to arduino outputs and you have wired the pots to the multiplexers inputs then:-

// select the multiplexer input number 0
digitalWrite(controlPin0, LOW);
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, LOW);
val0 = analogRead(0);   // now read the value
// select the multiplexer input number 1
digitalWrite(controlPin0, HIGH);
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, LOW);
val1 = analogRead(0);  // now read the value
// select the multiplexer input number 2
digitalWrite(controlPin0, LOW);
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, LOW);
val2 = analogRead(0);  // now read the value

// and so on

when you get it you can put it into a loop using fewer instructions.

Sorry to revive an old post but i’ve read the “faq” and viewed many posts in the entire forum, many times without success, and i think this post is the better to ask for help, so…
First of all, sorry if i made a mistake writing this, i’m Chilean…
Well, the goal is the same as many people, piezo+arduino+midi. The arduino+midi is an old story so i don’t have problem in this part, but the problem are piezos+arduino, and looking for a way to control the piezo signal i found in the web an electrical sketch (i cann’t put the link cause it’s my first post), and now i can process perfectly 6 pads (duemilanove), but trying to mux more than those 6 pads in a MC14067BCP i get signal in many inputs, depending on the strike volume.
I know that i must connect the mux to one analog input, selecting digitally the channel to read and from arduino to read the analog input (in my case it should be analogRead(0) cause i have just one mux) .
This is the code (spikenzielabs adapted version)…

unsigned char PadNote[] = {38,46,48,74,75,76,77,78}; 

int PadCutOff[]     = {0,0,0,0,0,0,0,0};

int MaxPlayTime[]   = {80,80,80,80,80,80,80,80};

#define  midichannel      0;                       

boolean activePad[] = {0,0,0,0,0,0,0,0};

int PinPlayTime[]   = {0,0,0,0,0,0,0,0};

unsigned char status_;

int pin = 0;     
int hitavg = 0;

int ds[][4]={  {LOW,LOW,LOW,LOW},
               {HIGH,LOW,LOW,LOW},
               {LOW,HIGH,LOW,LOW},
               {HIGH,HIGH,LOW,LOW},
               {LOW,LOW,HIGH,LOW},
               {HIGH,LOW,HIGH,LOW},
               {LOW,HIGH,HIGH,LOW},
               {HIGH,HIGH,HIGH,LOW} };

void setup() {
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  Serial.begin(31250);
}

int analogRead_(int i){
  digitalWrite(5, ds[i][3] );
  digitalWrite(4, ds[i][2] );
  digitalWrite(3, ds[i][1] );
  digitalWrite(2, ds[i][0] );
  return analogRead(0);
}

void loop() {
  for( pin=0; pin < 8; pin++){
    hitavg = analogRead_(pin);
    PinPlayTime[pin]++;
    if((hitavg > PadCutOff[pin])) {
      if( !activePad[pin] ) {
        MIDI_TX(144,PadNote[pin],hitavg); 
        PinPlayTime[pin] = 0;
        activePad[pin] = true;
      }
    } else if( activePad[pin] && (PinPlayTime[pin] > MaxPlayTime[pin])) {
        activePad[pin] = false;
        MIDI_TX(128,PadNote[pin],127); 
    }
  } 
}

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
  status_ = MESSAGE + midichannel;
  Serial.print(status_,BYTE);
  Serial.print(PITCH,BYTE);
  Serial.print(VELOCITY,BYTE);
}

In the mux, the pin 24 goes to arduino 5v, pins 12,15 go to arduino ground, 10,11,14,13 go to arduino digitals 2,3,4,5 respectively, pin 1 to arduino analog 0, the pin 9 goes to the output of the circuit (piezo+diodes+resistor+etc.) and finally this circuit ground to arduino ground. So having just one pad, i get signals on all the mux analog inputs not only in the input 0, even when the signal doesn’t go over 50. It’s so random that sometimes analog 0 gets 6 and in the next read analog 1 gets 2 or 1, sometimes analog 0 gets 127 then the same input gets 26 and then the analog 1 gets 1. I’ve tried putting delays (micros and millis), i tried putting a 10k resistor between de piezo circuit and the mux analog 0, and i tried putting the mux inhibit pin 15 to the arduino 5v (10k resistor between them) as i read in a forum, and i tried putting the unused analog pins to ground, but nothing. And believe me when i bypass the mux, connecting every circuit to the arduino analogs everything is ok. So my problem is the mux.
I’m not an electrical but i know that maybe somewhere a made a mistake in the circuit or in the code, so any help ? is this mux too lower to be used in a drum ?
Thanks in advance.

So having just one pad, i get signals on all the mux analog inputs not only in the input 0, even when the signal doesn't go over 50

That is because the input impedance on the A/D is too high. make the pull down lower. You could also read the input twice with a delay in between. Discard the first reading and use the second one. The delay allows the input capacitor in the A/D to match the input level through the high impedance.

Have a look at the code in this project:- http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html It shows you how to read a multiplexer.

Thanks Grummpy_Mike, but putting delays and discarding the first signal didn't work. The circuits are like this: http://leucos.lstilde.org/wp/2009/06/piezo-transducer-signal-conditioning/ Can you help me to "make the pull down lower" please, my electrical knowledge is too poor. Thanks again.

but putting delays and discarding the first signal didn't work.

Can you post the snippet of code (the function) where you tried this so I can see if you did it right.

Re: Help Reading multiplexer pins
Reply #11 - 25.06.2010 at 19:44:52 | | Remove
first try…

int analogRead_(int i){
digitalWrite(5, ds*[3] );*
digitalWrite(4, ds*[2] );*
digitalWrite(3, ds*[1] );*
digitalWrite(2, ds*[0] );*
delay(1);
analogRead(0);
delay(1);
return analogRead(0);
}

and the second try…

int analogRead_(int i){
digitalWrite(5, ds*[3] );*
digitalWrite(4, ds*[2] );*
digitalWrite(3, ds*[1] );*
digitalWrite(2, ds*[0] );*
delay(1);
analogRead(0);
digitalWrite(5, ds*[3] );*
digitalWrite(4, ds*[2] );*
digitalWrite(3, ds*[1] );*
digitalWrite(2, ds*[0] );*
delay(1);
return analogRead(0);
}

but nothing… it just take more time for the reading, and of course i get less signals. I think that the problem is the other side (the circuits), but my electrical knowledge is too poor as you know…
Thanks

There is not enough delay to charge the capacitor in your sketch.

Scswift has just come up with a cunning way of doing this. Take an unused analogue input and wire a 10K pull down resistor to it. Then read this unused channel first before reading the want you want.

Sorry again to re-reviving an old post but i think it would help to someone else with a similar problem (or maybe the same). Anyway you gonna love this ... Fighting again with my "midi drum circuits" frustrated again with the unwanted midi signals... a little fuzz (pelusa in spanish) fall down over the mux, and when i blow some air to get it out, it magically began to sound beatifully... waaaaaaaaaaaa, the mux is overheating !? I've tested many times and when it begins to sound unwanted midi signals i just blow cool air over the mux and it works like a charm. So in my new sketch i'm going to include a cooler... Of course i will post the result... Thanks again guys...