4051 mux daisy chain?

Sorry about that. I have attached the image

volatile uint32_t s0,s1,s2,s3,s4,s5;
int addressA =3; //s0
int addressB =4; //s1
int addressC =5; //s2
int addressD =6; //s3
int addressE =7; //s4
int addressF =8;  //s5
void setup() {
Serial.begin(9600);
pinMode(addressA,OUTPUT);
  pinMode(addressB,OUTPUT);
  pinMode(addressC,OUTPUT);
  pinMode(addressD,OUTPUT);
  pinMode(addressE,OUTPUT);
  pinMode(addressF,OUTPUT);
  pinMode(A0,INPUT);
}

void loop() {
 
  write_address(0,0,1,1,0,0);  // Read ch12


Serial.println(analogRead(A0));
delay(10);
}


   void write_address(int8_t s0,int8_t s1, int8_t s2,int8_t s3,int8_t s4, int8_t s5)
  {
     digitalWrite(addressA,s0);
     digitalWrite(addressB,s1);
     digitalWrite(addressC,s2);
     digitalWrite(addressD,s3);
     digitalWrite(addressE,s4);
     digitalWrite(addressF,s5);
  }

I can't immediately see a problem with your sketch or schematic.

How are you testing? When you say that channels over 7 give zero, are you feeding a non-zero signal into every other channel? Could it be that the MUX is selecting a channel you did not expect and you don't have an input voltage on the channel it has selected?

Try swapping some of the mux chips around, to check if you have any faulty chips.

Whatever is wrong, it can't be because the signal is passing through 2 MUX chips. If that were the problem, channels 1 to 7 would not work either.

I am feeding analog signal into one channel at a time. Not all channels are hooked up with inputs, i have not tested that yet. But perhaps it could be unexpectedly selecting a vacant channel due to a broken MUX in the chain. I will investigate that further and let you know.

I was wondering if you ever got the 64 inputs to work? I trying to do the same thing?

Are you using 8 chips, each one feeding into an analog input of a Mega or 1284P board or an surface mount 328P which has all 8 analog inputs available?
If not, post a schematic of what you do have.

This is the Schematic I found, but I am using a Uno

That should also work for Uno.

Add a 0.1uF cap from the Vcc pin of each device to Gnd.
Be aware that you are adding 50 to 260 ohm of series resistance to each signal you are looking at with the cascading arrangement.
Using regular analogRead() for the 64 signals will take 7mS just in conversion time for the 64 signals, plus some time to set up the 2 sets of 8 addresses (outer bank address 0, inner bank 0 to 7, outer bank address 1, inner bank 0 to 7, etc. thru outer bank address 7, inner bank 0 to 7).

I think I may have worded my question wrong. I was referring to the programming for run master, slave with the 4051 and being able to read the analog signal.

@canuseebg, What question is that?
You jumped into page 2 of this thread with the schematic showing a Promini and 8 4051s. A promini is programmed the same as an Uno, just packaged differently. You haven't asked a question yet.

I want to read 64 inputs using one master 4051 and 8 4051 slaves, and I can across this post which the 64 inputs were discussed and I was wondering if the codes posted solved their problem,

I have a code I am working on than I found on the internet that I have been trying to modify for my use, and I am having I problem with the reading  64 inputs  for analog voltage using the schematic I posted earlier.

the code is print random numbers and not voltages

[code//I have multiple wires (64 of these) which values I want to read voltage.
//I am using a master multiplexer HC4051 connected to 8 slave multiplexers
// 74XX4051 ADDRESS PINS :
int M_S0 = 2;
int M_S1 = 3;
int M_S2 = 4;

int S_S0 = 7;
int S_S1 = 6;
int S_S2 = 5;
int analogPin = A0;
int Z =0;
int MUX64[64] = {0};

void setup() {
      // CONFIGURE ADDRESS PINS
    pinMode(M_S0, OUTPUT);
    pinMode(M_S1, OUTPUT);
    pinMode(M_S2, OUTPUT);
    pinMode(S_S0, OUTPUT);
    pinMode(S_S1, OUTPUT);
    pinMode(S_S2, OUTPUT);
    pinMode(Z, OUTPUT);
  Serial.begin(9600);   
  
}

void loop() {
 
   // LOOP THROUGH ALL THE ADDRESSES OF THE MASTER 
    for (int i = 0; i < 64; i++) {
        
    digitalWrite(M_S2, HIGH && (i & 0b1000000));
    digitalWrite(M_S1, HIGH && (i & 0b100000));
    digitalWrite(M_S0, HIGH && (i & 0b010000));        
    digitalWrite(S_S2, HIGH && (i & 0b000100));
    digitalWrite(S_S1, HIGH && (i & 0b000010));
    digitalWrite(S_S0, HIGH && (i & 0b000001));
    delay(1);
    
    Z = analogRead(analogPin);   
    
    
     

    Serial.print("Input ");
    Serial.print(i);
    Serial.print(": ");
    Serial.print(Z);
    Serial.println(" v ");
    delay(100); 
}

}]

Why do you have this if you using the pin for analogRead() ?

int Z =0;

pinMode(Z, OUTPUT); << sets D0 as output - but you are using D0 for Serial. Delete this line.

Z = analogRead(analogPin);
Serial.print(Z);

Give Z a different, more meaningful name.

What is your analog source? Does it have enough drive to overcome resistance of two 4051s?

I am using 5 volt for the voltage on the Inputs it reads on one 4051.

Updated the code.

//I have multiple wires (64 of these) which values I want to read voltage.
//I am using a master multiplexer HC4051 connected to 8 slave multiplexers
// 74XX4051 ADDRESS PINS :
int M_S0 = 2;
int M_S1 = 3;
int M_S2 = 4;

int S_S0 = 7;
int S_S1 = 6;
int S_S2 = 5;
int analogPin = A0;
int ReadVolt = 0;
int MUX64[64] = {0};

void setup() {
      // CONFIGURE ADDRESS PINS
    pinMode(M_S0, OUTPUT);
    pinMode(M_S1, OUTPUT);
    pinMode(M_S2, OUTPUT);
    pinMode(S_S0, OUTPUT);
    pinMode(S_S1, OUTPUT);
    pinMode(S_S2, OUTPUT);
    
  Serial.begin(9600);   
  
}

void loop() {
 
   // LOOP THROUGH ALL THE ADDRESSES OF THE MASTER 
    for (int i = 0; i < 64; i++) {
        
    digitalWrite(M_S2, HIGH && (i & 0b1000000));
    digitalWrite(M_S1, HIGH && (i & 0b100000));
    digitalWrite(M_S0, HIGH && (i & 0b010000));        
    digitalWrite(S_S2, HIGH && (i & 0b000100));
    digitalWrite(S_S1, HIGH && (i & 0b000010));
    digitalWrite(S_S0, HIGH && (i & 0b000001));
    delay(1);
    
    ReadVolt = analogRead(analogPin);   
    
    
     

    Serial.print("Input ");
    Serial.print(i);
    Serial.print(": ");
    Serial.print(ReadVolt);
    Serial.println(" v ");
    delay(100); 
}

}
    digitalWrite(M_S2, HIGH && (i & 0b1000000));
    digitalWrite(M_S1, HIGH && (i & 0b100000));
    digitalWrite(M_S0, HIGH && (i & 0b010000));        
    digitalWrite(S_S2, HIGH && (i & 0b000100));
    digitalWrite(S_S1, HIGH && (i & 0b000010));
    digitalWrite(S_S0, HIGH && (i & 0b000001));

Can you explain how this part works? I am not seeing how it creates
000 and 000, 001, 010, 011, 100, 101, 110, 111
001 and 000, 001, 010, 011, 100, 101, 110, 111
010 and 000, 001, 010, 011, 100, 101, 110, 111
etc thru
111 and 000, 001, 010, 011, 100, 101, 110, 111
for the 2 sets of address lines.
Maybe it works fine, I'm just not following what it does.
I would try a longer delay and confirm the address lines with a meter, or some LEDs to start so you can see them visually quickly.
Maybe there's a wiring error somewhere.
Which 4051 part are you using?

I found this part of the code here.

I have checked on the first slave and will be working on the other 7 later. I will use LED's as suggested

PaulRB:

To PaulRB and others following this thread.
I would like to thank you all, I made a prototype based on what I have read here and on the schematics by PaulRB - that I would like to acknowledge in full.

Here you can find pictures and a description of what I achieved thanks to your competence.

http://www.cesarebrizio.it/Arduino/DIP_Switch_ROM.html

Again thank you and all the best to everyone,
Cesare

on the schematics by PaulRB

I did not post the schematic (except to imbed it into a post for easy viewing). Someone else should get the credit.