I want to use the ADG731 32 ch multiplexer to read 32 potentiometers, I have wired everything and it works but it doesn't works as fast as I would want.

The problem is that If I turn a potentiometer between the range of 10-90% of the rotation, the analog reading is so slow, for example, if I have my POT at 0, and i turn it to 50%, it goes so slow until it reach the 512 value(like an hysteresis effect), BUT, if I turn the potentiometer back to 0 or up to 1023 it makes the reading as quick as I would expect.

So in resume it reads slowly the values except the edges values.

This is my code(I have set it to read only one potentiometer at pin S16 to test how the ADG731 works:

#include <SPI.h>

void loadDrain(void);
const int slaveSelectPin = 53;
void setup() {
  pinMode(slaveSelectPin, OUTPUT);

void loop() {

void loadDrain(){
  SPI.beginTransaction(SPISettings(30000000, MSBFIRST, SPI_MODE2));
  digitalWrite(slaveSelectPin, LOW);
  digitalWrite(slaveSelectPin, HIGH);
  Serial.println(analogRead(A0) >> 3);
  • You should remove the multiplexer from the circuit to see if that is the culprit. (I'm guessing not.) I'd try wiring 1 pot directly to the analog input pin and seeing if the results are still slow to register.
    – Duncan C
    Mar 21, 2019 at 13:01
  • BTW, why do you issue the SPI commands to select the specific pot every time, even though in your test you're reading the same pot every time?
    – Duncan C
    Mar 21, 2019 at 13:01
  • @DuncanC without the MUX it reads properly; Because you must select what channel of the MUX you want to read thru SPI. And now I am only reading one because I only want to read one pot to test if it works correctly and the when I have it working correctly I will add the other 31 Mar 21, 2019 at 13:28
  • What value (ohms) pots are you using?
    – Gerben
    Mar 21, 2019 at 16:25
  • @Gerben 10K ohms Mar 21, 2019 at 21:13

3 Answers 3


Take a deep look into the library you are using to read the POT. Most HW and / or SW will take many readings & average them to remove the randomness and improve the accuracy of the ADC HW. It could be that your setup is so noisy that the SW is compensating by taking even more readings to average. Hats off the the SW developer who had the foresight to adapt the code to noisier situations. If true, and you think that too much automation, remember you are using the Arduino platform where the libraries are designed to make things simple by abstracting (hiding) the hardware details.

  • to read the pot I am using the analogRead() standart function, can you give me more information about what you say please, it is interesting to analyze Mar 21, 2019 at 13:30
  • Remember that the libraries are re-written for each different processor. What source code you look at depends on the processor. The point of the libraries is to abstract the differences of each processor such that the Arduino code doesn't have to change or doesn't have to change much when ported to different platforms (processors).
    – st2000
    Mar 21, 2019 at 13:36

Some things look odd:

Why do this every time? You only need to set these up one time in setup():

SPI.beginTransaction(SPISettings(30000000, MSBFIRST, SPI_MODE2));

Most 16 MHz Arduinos, including the Mega you appear to be using, won't do 3 MHz, choices are 8 MHz, 4,MHz, 2 MHz, 1 MHz and 3 or 4 more slower speeds.

The chip seems to support higher speeds, 8 MHz should work:

fSCLK 30 MHz max SCLK Cycle Frequency

So run it faster to same on time.

Why take a 10-bit reading and shift it down to 7?

Serial.println(analogRead(A0) >> 3);

You could speed up the reads by doing an 8-bit read instead of 10-bit, and use a faster Serial speed, up to 115200, to send the results out.

Instead of digitalWrite() to control the slaveSelect pin, you could use direct port manipulation to toggle that pin. You can write a 1 to the Input port to toggle the output bit. From the Atmega2560 datasheet:

Toggling the Pin

Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port.


You can modify beginT and endT // test SPI slave n=1
SPI.beginTransaction(1, SPISettings(30000000, MSBFIRST, SPI_MODE2)); SPI.transfer(00001111); SPI.endTransaction(1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.