I have this small board which runs 2 latching switches and 6 pots through a 4051 multiplexer into an arduino uno.
The switches appear to work perfectly but I'm having issues with the potentiometers as they appear to suffer from interference with one another whilst also converging down to ~0 over long periods of time.
I've tried using an external power supply for the uno and playing around with adding in delays but it appears the power supply did nothing and the delays only prolong the inevitable.
The code I'm currently using is basically a copy of the sparkfun guide but i've added it below.
Where I imagine the issues are originating are the PCB itself which I've attached png's of. Each pot runs through a 100nf cap which was recommended elsewhere as filtering but perhaps this is the crux of my issue? as I have seen examples without using caps before the input of the MUX.
Any help in the right direction would be much appreciated.
[code]const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4
const int zInput = A5; // Connect common (Z) to A5 (analog input)
void setup()
{
Serial.begin(9600); // Initialize the serial port
// Set up the select pins as outputs:
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], HIGH);
}
pinMode(zInput, INPUT); // Set up Z as an input
pinMode(A0, INPUT); // Set up Z as an input
// Print the header:
Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7\tGND");
Serial.println("---\t---\t---\t---\t---\t---\t---\t---\t---");
}
void loop()
{
// Loop through all eight pins.
for (byte pin=0; pin<=7; pin++)
{
selectMuxPin(pin); // Select one at a time
int inputValue = analogRead(A0);
delay(100);
inputValue = analogRead(A5); // and read Z
Serial.print(String(inputValue) + "\t");
}
Serial.println();
}
// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}[/code]