1

I realize this gets asked a lot, but I feel like I've applied the most common fixes without success. I have 10 10k potentiometers plugged in to an arduino via a custom shield. 2 are wired directly to the MC via A2 and A3. The other 8 are plugged in via a 74HC4051 multiplexer. The 2 plugged in directly work great. The other 8 show a ton of cross talk and don't seem to vary as much as they should. Here is some example output on the arduino serial plotter:

enter image description here

Things I have tried:

  1. I put a delay between the pin selection and the read.
  2. I'm reading twice (with a delay in between) and discarding the first read.

I'd use an MCP2308 if I were doing this again, but in the mean time is there anything else I can try?

Here is my schematic:

enter image description here

Each pot is plugged in to 5V and ground, with the wiper wired directly to the pin, all via jumper cables to the shield. Here's a picture of how this works (apologies for the mess):

Board Picture

The pin blocks have, per row, one pin each feeding in to a multiplexer input, and another attached to the GND and +5V planes on the PCB. These are attached to +5V and GND on the arduino:

enter image description here

Here is my code:

const int selectPins[3] = {8, 12, 13}; // S0, S1, S2
const int zInput = A1; // Connect common (Z) to A1 (analog input)
const int DIMp = A2;
const int bDIMp = A3;
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);
  pinMode(DIMp, INPUT);
  pinMode(bDIMp, INPUT);
}

// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectAMuxPin(byte pin)
{
  for (int i=0; i<3; i++)
  {
    if (pin & (1<<i))
      digitalWrite(selectPins[i], HIGH);
    else
      digitalWrite(selectPins[i], LOW);
  }
}

void loop() 
{
  // Loop through the hard wired dimmers
  Serial.print(String(analogRead(DIMp))+" ");
  Serial.print(String(analogRead(bDIMp))+" ");
  // Loop through all eight pins.
  for (byte pin=0; pin<=7; pin++)
  {
    selectAMuxPin(pin); // Select one at a time
    delayMicroseconds(500); // delay after pin select
    int inputValueb = analogRead(zInput); // read Z
    delayMicroseconds(150); //delay after first read
    inputValueb = analogRead(zInput); // read Z again
    Serial.print(String(inputValueb) + " ");
  }
  Serial.println();
}
12
  • "Z1" is connected to A0 but you are reading from A1?
    – Majenko
    Nov 17 '19 at 22:26
  • it is difficult to guess the anything else I can try because you did not say what you already tried
    – jsotola
    Nov 17 '19 at 22:26
  • Sorry - the Z1 is a mistake because I removed some code related to the second chip. I tried adding a delay between reads, and I tried reading twice and throwing out the first read.
    – mrpeverill
    Nov 18 '19 at 0:04
  • Please edit your question, informations in the comments are very hard to find. Nov 18 '19 at 7:39
  • I'd start with decoupling capacitor for 4051. Next step would be reading 0V channel before reading analog input channel (but that's not possible by analogRead), to remove charge of sampling capacitor.
    – KIIV
    Nov 18 '19 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.