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.
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.
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);
}
}]
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?
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.