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.
