Hi Everyone
I'm trying to get familiar with multiplexing, and I've been following this tutorial by Götz Müller-Dürholt (it's in German, so I might have missed a few points).
I've copied his circuit and code, though I've renamed some variables and added some more info to the serial print for the sake of comparing HIGH and LOW select pins with Y-pins and returned values.
But it's not working quite as it should.
The values returned are stable, but I'm getting duplicate readings on pin (=count) 0 and 1, on pin 2 and 3 and on pin 4 and 5 (if I connect one pot to Y3, I'm getting a duplicate reading on pin 6 and 7). Teoretically I should just get three different reading on pin 0, 1 and 2 and pin 3, 4, 5, 6 and 7 should return "0", since nothing is connected to them.
If I turn my pots fast, the serial monitor shows that the values on the "paired" y-pins is infact individual and not just "mirrored", because the values changes in steps, but its pretty clear that the second pin in the pair gets it's value from the same pot as the first pin in the pair. I hope this makes sense, if not, please see the attachement with some read outs boxed in.
There's more If I connect any pot to Y4, Y5, Y6 or Y7, it doesn't affect the read outs at all. It's like Y4 - 7 doesn't excist.
I'm using Arduino Uno and the multiplexer is a CD4051BE, so it should be pretty straight forward, but I'm lost. Any help would be appreciated
int Val = 0;
int count = 0;
int bit1 = 0;
int bit2 = 0;
int bit3 = 0;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop () {
for ( count = 0 ; count <= 7; count++ ) {
bit1 = bitRead(count, 0);
bit2 = bitRead(count, 1);
bit3 = bitRead(count, 2);
digitalWrite(2, bit1);
digitalWrite(3, bit2);
digitalWrite(4, bit3);
Val = analogRead(A0);
Serial.print(bit1);
Serial.print(bit2);
Serial.print(bit3);
Serial.print(" ");
Serial.print("=");
Serial.print(" ");
Serial.print("Y");
Serial.print(count);
Serial.print(": ");
Serial.print(Val);
Serial.print("\t");
}
Serial.println("");
}