[SOLVED] 40 channel 4051 multiplexer analog ins affect neighbours values

hello,

i'm using 5 slave 4051 and 1 master 4051 to build a 40 channel multiplexer. 40 potentiometers (100k) are connected to the analog ins on each 4051.

the arduino is reading all the inputs, but is messing aroung with neighbour-inputs. e.g.: when i turn potentiometer #32 from 0 to 1023, then the value of potentiometer #31 is changing to (~)760... and the other way round. on different potentiometers the similar situation, sometimes more sometimes less affection...

each potentiometer is getting its ground and +5v from the arduino, the middle pins are connected to the slave 4051 analog inputs, each output of an slave 4051 is connected to the master 4051 analog input, just like in the basic description: http://playground.arduino.cc/learning/4051

Any idea how to clear the values?

I'm using this mux example to read out the values:

#include <analogmuxdemux.h>

#define READPIN 2 //analog in
#define NO_PINS 40 //40 inputs

// master selects
#define M_S0 10 //master digital pin
#define M_S1 11 //master digital pin
#define M_S2 12 //master digital pin

// slave selects
#define S_S0 2 //slave digital pin
#define S_S1 3 //slave digital pin
#define S_S2 4 //slave digital pin

AnalogMux amx(M_S0,M_S1,M_S2, S_S0,S_S1,S_S2, READPIN);

void setup() { 
    // check in serial monitor what is happening
    Serial.begin(9600);
    Serial.println("Starting 4051 analog reader...");
    delay(1000);
}

void loop() {

  // go through each pin on the muxer in turn and just print out it's pin number
  // and it's reading then wait a bit and do it again
    
    for (int pinno=0; pinno< NO_PINS; pinno++) {
      amx.SelectPin(pinno);
        uint16_t reading = amx.AnalogRead();
        Serial.print("Pin: ");
        Serial.print(pinno);
        Serial.print(" Value: ");
        Serial.print(reading);
        Serial.println();             
    }
    Serial.println("---");
    delay(1000);

}

Your problem is:-

40 potentiometers (100k) are connected to the analog ins on each 4051

You should have used 10K pots so that the impedance is lowered both for the multiplexer and the A/D.

What you can try is reading each channel twice and only using the second result. This allows extra sample acquisition time.

So this would look like:-

amx.SelectPin(pinno);
        uint16_t reading = amx.AnalogRead();
        reading = amx.AnalogRead();

However why on earth you are using a library like <analogmuxdemux.h> I don't know, it is simple enough to write code for this, and it might stop this fix from working.

What you can try is reading each channel twice and only using the second result. This allows extra sample acquisition time.

this i will check out back at home!

However why on earth you are using a library like <analogmuxdemux.h> I don't know, it is simple enough to write code for this, and it might stop this fix from working.

thought it would be faster then writing a own buggy one :slight_smile: so ok, i'm going to write it from scratch if this fix^^ isn't wiring.

Checked it. It really doesn't matter if its an 100k or 10k pot, I've tested them both.
The solution was so simple: I tested the 40 analog ins each only with one pot. Connecting all pots to the 40 inputs has removed the affection on the other neighbour inputs by approx 99%... Oh my.

To remove the remaining 1%, try inserting a small delay (e.g. 10us to 100us) between these two lines:

amx.SelectPin(pinno);
uint16_t reading = amx.AnalogRead();

tmk_009:
Checked it. It really doesn't matter if its an 100k or 10k pot, I've tested them both.
The solution was so simple: I tested the 40 analog ins each only with one pot. Connecting all pots to the 40 inputs has removed the affection on the other neighbour inputs by approx 99%... Oh my.

See what you get if you don't describe what you have fully. I would have told you about un terminated inputs. :slight_smile:
Try the reading twice bit with all the inputs connected.

thank you both guys. step by step i'm getting into it. i'll post the results later!

thank you guys! everything works like a charm! no errors, no bleedings. the values are accurate, even with 100k pots and 4051 multiplexers.

it took some time, i had to resolder the pot matrix, somewhere there was a tiny bugs messing up the whole thing... now i can go further to the next step: playing around with midi values by turning a knob in the matrix.

Do you have diagrams(drawing) for this project,I`m interesting for this?Thanks

I hope you are not asking this to solve your forklift battery problem.
http://forum.arduino.cc/index.php?topic=378959.0
Those chips can only handle inputs <= 18volt.
Ok to measure only the lowest 6 cells.

A 4067 has double the inputs of a 4051
http://bildr.org/2011/02/cd74hc4067-arduino/
Leo..