Multiple Multplexer CDHC4067

Hi
I want to connect some multiplexer to my Arduino.
There are S0-S3, EN and SIG

First question is can i connect all S0-S3 together and control them only with the SIG pins?

What would be the coding for that? I found some Librarys for the Multiplexer but with no information how to conenct them together.
I would like to use for example this code:

#include "Type4067Mux.h"

/*
 * Creates a Type4067Mux instance.
 *
 * 1st-3rd arguments initialize SIG pin (digital input on Arduino PIN 3).
 * 4th-7th arguments are the Arduino PINs to which the S0-S3 pins connect.
 */
Type4067Mux mux(3, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(4, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(5, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(6, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(7, INPUT, DIGITAL, 8, 9, 10, 11);

void setup() {
  // Initializes serial port.
  Serial.begin(9600);
  // Waits for serial port to connect (needed for Leonardo only).
  while (!Serial)
    ;
}

/*
 * Reads the 16 channels and reports on the serial monitor if the corresponding
 * push button is pressed.
 */
void loop() {
  byte data;
  for (byte i = 0; i < 16; ++i) {
    // Reads from channel i and returns HIGH or LOW.
    data = mux.read(i);

    Serial.print("Push button at channel ");
    Serial.print(i);
    Serial.print(" is ");
    if (data == HIGH) {
      Serial.println("not pressed");
    } else if (data == LOW) {
      Serial.println("pressed");
    }
  }
  Serial.println();

  delay(1500);
}

gazy98:
Hi
I want to connect some multiplexer to my Arduino.
There are S0-S3, EN and SIG

First question is can i connect all S0-S3 together and control them only with the SIG pins?

Dont see the point of your question! S0-S3 let you select the CHANNEL you want SIG to switch to… IMHO the answer is clearly NO!

this link(bildr Muxing Around With The CD74HC4067 + Arduino - bildr) seems to give a decent illustation of the set up

As you see here, the EN is put to ground. If you are going to use multiple chips, if it was me, I would wire EN of each chip to a different digital pin to select the chip I want to SIG to be switched to.

S0-S3 and SIG of the chips would be wired to the SAME pins on the arduino.

Here is the example code (I tidied it up a bit) from the site (compiles, NOT TESTED!):

/*CD74HC4067 example code
 * 
 * This example code loops through each channel of the CD74HC4067, reads the value, then prints the value in the serial monitor.
 * 
*/
//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//Mux in “SIG” pin
int SIG_pin = 0;

void setup() {
  //Initialise the muxChannel selection pins
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  //initialise serial COM
  Serial.begin(9600);
}

void loop() {

  //Loop through and read all 16 values
  for (int i = 0; i < 16; i ++) {
    Serial.print("Value at channel ");
    Serial.print(i);
    Serial.print("is : ");
    Serial.println(readMux(i));
    delay(1000);
  }
}
int readMux(int channel) {
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4] = { {0, 0, 0, 0}, //channel 0
                          {1, 0, 0, 0}, //channel 1
                          {0, 1, 0, 0}, //channel 2
                          {1, 1, 0, 0}, //channel 3
                          {0, 0, 1, 0}, //channel 4
                          {1, 0, 1, 0}, //channel 5
                          {0, 1, 1, 0}, //channel 6
                          {1, 1, 1, 0}, //channel 7
                          {0, 0, 0, 1}, //channel 8
                          {1, 0, 0, 1}, //channel 9
                          {0, 1, 0, 1}, //channel 10
                          {1, 1, 0, 1}, //channel 11
                          {0, 0, 1, 1}, //channel 12
                          {1, 0, 1, 1}, //channel 13
                          {0, 1, 1, 1}, //channel 14
                          {1, 1, 1, 1}  //channel 15
                        };

  //set the 4 muxChannel selection pins to switch to desired muxChannel
  for (int i = 0; i < 4; i ++) {
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}

Hope the helps…

Thank you for your answer. The problem is that for example i have 5 MUX and to each of the MUX i connect 16 Buttons. If i Press Button 1 on MUX1 i want to recieve for example "B1M1 = Pressed" and for the other MUX also.

So i cant just turn them off and on. Or do i missunderstand you?

The important thing is that in this case i have to wire each MUX with his own s0,s1,s2,s3, and SIG Pin.
But i want define 4 Pins of arduino to be s0-s3 and connect all of the MUX to this. And also each MUX has its own SIG pin.

Hope now its more clear.

gazy98:
Thank you for your answer. The problem is that for example i have 5 MUX and to each of the MUX i connect 16 Buttons. If i Press Button 1 on MUX1 i want to recieve for example "B1M1 = Pressed" and for the other MUX also.

So i cant just turn them off and on. Or do i missunderstand you?

The important thing is that in this case i have to wire each MUX with his own s0,s1,s2,s3, and SIG Pin.
But i want define 4 Pins of arduino to be s0-s3 and connect all of the MUX to this. And also each MUX has its own SIG pin.

Hope now its more clear.

Unfortunately to much clearer for me... sorry but I found it difficult to read your english (maybe english is not your native language)

in any case: this is what I explain in reply #1. hopefully the picture below illustrates it better:

so in the code in reply #1 , you would need to add an additional 'for' loop to enable/disable each chip.

EN LOW = chip enabled
EN HIGH = chip disabled

then each time EN is enabled, loop though the 16 channels to check if a button is pressed.

Hope that makes it clearer for you....

gazy98:
First question is can i connect all S0-S3 together and control them only with the SIG pins?

Yes, you can use one set of select/address outputs for all multiplexers. I would recommend connecting each SIG pin to a separate input. You can wire the ENA signals to keep the multiplexers enabled all the time.

gazy98:
What would be the coding for that?
I would like to use for example this code:

#include "Type4067Mux.h"

Type4067Mux mux(3, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(4, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(5, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(6, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux(7, INPUT, DIGITAL, 8, 9, 10, 11);

You can’t have all of the objects named ‘mux’. You can either give them separate names or put them in an array:

#include "Type4067Mux.h"
Type4067Mux mux0(3, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux1(4, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux2(5, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux3(6, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux mux3(7, INPUT, DIGITAL, 8, 9, 10, 11);
Type4067Mux muxs[] = 
{
  Type4067Mux(3, INPUT, DIGITAL, 8, 9, 10, 11),
  Type4067Mux(4, INPUT, DIGITAL, 8, 9, 10, 11),
  Type4067Mux(5, INPUT, DIGITAL, 8, 9, 10, 11),
  Type4067Mux(6, INPUT, DIGITAL, 8, 9, 10, 11),
  Type4067Mux(7, INPUT, DIGITAL, 8, 9, 10, 11)
};

Then you can read all 80 channels with:

void setup() {
  // Initializes serial port.
  Serial.begin(9600);
  // Waits for serial port to connect (needed for Leonardo only).
  while (!Serial)
    ;
}

/*
 * Reads the 16 channels and reports on the serial monitor if the corresponding
 * push button is pressed.
 */
void loop() {
for (mux=0; mux < MuxCount; mux++)
{

  byte data;
  for (byte i = 0; i < 16; ++i) {
    // Reads from channel i and returns HIGH or LOW.
    data = muxs[mux].read(i);

    Serial.print("Push button at muxs[");
    Serial.print(mux);
    Serial.print("] channel ");
    Serial.print(i);
    Serial.print(" is ");
    if (data == HIGH) {
      Serial.println("not pressed");
    } else if (data == LOW) {
      Serial.println("pressed");
    }
  }
  Serial.println();

  delay(1500);
}

"The problem is that for example i have 5 MUX and to each of the MUX i connect 16 Buttons. If i Press Button 1 on MUX1 i want to recieve for example "B1M1 = Pressed" and for the other MUX also."

Most likely you will need to constantly scan thru the multiplexer lines to detect a button press. There are different ways to wire the multiplex chips, depending on which chips are used. The below might be a typical wiring setup.