Noisy analog inputs - multiplexer with MIDI control surface

Hi all.

I wanted to test a Pitch Bend potentiometer connected to a Nano ESP32 S3 through a multiplexer (4051) using the Control Surface Library.
It works but it is noisy.

The shift factor is set to 4.
The analog filter type is uint32_t.

This is the sketch:

#include <Control_Surface.h>

USBMIDI_Interface midi;

CD74HC4051 mux1 = {
  1,                // Analog input pin
  {3, 4, 11}.  // Address pins S0, S1, S2
};

//FADERS
PBPotentiometer vol1 {
  mux1.pin(1),        // Analog pin connected to potentiometer
  CHANNEL_1,       // MIDI Channel 
  };

void setup() {
Control_Surface.begin();
 }

void loop() {
  Control_Surface.loop();
}

I tried adding the following extra bit of code:


FilteredAnalog<> analog[1] = {mux1.pin(1)};

void loop() {
  Control_Surface.loop();
   for (int i=0; i<2; i++)
  {
analog[i].update();
Serial.print(analog[i].getRawValue() / 16.f);
Serial.print("\t");
Serial.print(analog[mux1.pin(1)].getValue());
Serial.println();
}

The sketch with the additional code gets compiled but once loaded the Nano keeps rebooting in cycle. This extra bit of code works fine on a Micro Pro.
Strange behaviour indeed.
It seems that the multiplexer somehow bypasses the control surface filtering.

Do you think there is a way to increase further more the filter factor or type?

Thanks a lot for your help!

How about posting an annotated schematic. Show all connections, power sources, grounds and links to technical information on the hardware devices.

No clue as to what you are talking about setting to 4 and uint32_T defines a unsigned 32 bit integer.

Please post clear pictures of your hardware.

The second sketch crashes because you're accessing the analog array out of bounds.

Here's the schematic.

@gilshultz Shift factor and Analog Filter Type can be found in the settings.hpp of the Control Surface library.

@PieterP Thanks for the hint.

Does the same potentiometer work fine without the multiplexer?
What do you get when plotting the raw and filtered values as in Potentiometer reading is unstable on Teensy 4.1 · Issue #726 · tttapa/Control-Surface · GitHub?

Try using 3.3V for VCC/DD, see the VIH values in §6.3 of the datasheet: https://www.ti.com/lit/ds/symlink/cd74hc4051-ep.pdf

You also need decoupling capacitors for VCC/DD, see §11 in the datasheet.

2 Likes

Thanks @PieterP

Does the same potentiometer work fine without the multiplexer?

It does.

Try using 3.3V for VCC/DD, see the VIH values in §6.3 of the datasheet

I tried using 3.3v VCC/DD and decoupling capacitors but it didn't seem to improve much.

At this point I don't think it is hardware related; it could be due to a wrong board selected on IDE.
I installed the esp32 package but there are plenty of models to choose from. The board's manufacturer recommends to use the Arduino Nano ESP32; however if I do so, the sketch gets uploaded but the board turns unresponsive.

Instead I selected the ESP32-S3-USB-OTG which seems to work fine but it bypasses the filtering of the Multiplexer's analog inputs.

What do you mean? The code related to filtering is independent of the platform.

What do you mean? The code related to filtering is independent of the platform.

I noticed that boards from different manufacturer behave differently with the same filtering settings.
Anyway, is there a way to increase further more the filtering?
It is almost ineffective for now and there is almost no delay.

I fixed the sketch above and it works now but it doesn't improve much:

void loop() {
  Control_Surface.loop();
   for (int i=0; i<1; i++)
  {
    analog[i].update();
    Serial.print(analog[i].getRawValue() / 64.f);
    Serial.print("\t");
    Serial.print(analog[mux2.pin(1)].getValue());
    Serial.println();
}
}

Thank you!

Could you be more specific? Which manufacturers are you talking about? What are the exact settings I should select in the IDE to reproduce these different behaviors?

Sure, you can increase the filter shift factor even further. Switching the filter type to uint64_t won't have any noticeable effect, though.

This is not correct. Try this:

#include <Control_Surface.h>

constexpr uint8_t filter_shift_factor = 4;
using filter_type = uint32_t;
CD74HC4051 mux1 {1, {3, 4, 11}};
FilteredAnalog<10, filter_shift_factor, filter_type> analog {mux1.pin(1)};
Timer<millis> print_interval {20};

void setup() {
  Serial.begin(115200);
  Control_Surface.begin();
}

void loop() {
  analog.update();
  if (print_interval) {
    Serial.print(analog.getRawValue() * 100.f / analog.getMaxRawValue());
    Serial.print("\t");
    Serial.print(analog.getFloatValue() * 100.f);
    Serial.println();
  }
}

The sketch itself won't change the behavior, it is meant to visualize the un-filtered and filtered signals. Please post a screenshot of the serial plotter using this sketch, similar to this one:

Please also post a photo of your actual hardware

Thanks for your answer @PieterP.

It worked with the last bit of sketch you sent.
I'm afraid I'm unable to use the serial plotter as the board needs to be "offilne" in order to work. On the contrary, in order to upload a sketch, I have to call the bootloader mode (Pin B1 to GND and press reset button), which would make the board nonoperational.

Anyway, the filter now works but it leaves a 1sec of delay which means I have to play a little bit more with the filter settings.
Interestedly, I noticed that the Partition Scheme on IDE needs to be set to 16M otherwise the analog filter doesn't work.

See IDE's board settings attached:
Screenshot 2024-09-04 at 14.58.20

Thank you!

Then there seems to be something seriously wrong ... Could you post the exact code you are using, and the steps to reproduce/observe this issue?

What do you mean?

Let me recap.
Here's the sketch:

#include <Encoder.h>
#include <Control_Surface.h>


constexpr uint8_t filter_shift_factor = 4;
using filter_type = uint32_t;

USBMIDI_Interface midi;

using namespace MIDI_Notes;


CD74HC4051 mux1 {1, {3, 4, 11}};

FilteredAnalog<10, filter_shift_factor, filter_type> analog {mux1.pin(1)};
Timer<millis> print_interval {20};

//FADERS
PBPotentiometer vol1 {
  mux1.pin(1),
  CHANNEL_1,
  };

void setup() {

 Serial.begin(115200);
  
FilteredAnalog<>::getMaxRawValue();

RelativeCCSender::setMode(relativeCCmode::MACKIE_CONTROL_RELATIVE);

  Control_Surface.begin(); 
}

void loop() {
  Control_Surface.loop();

     analog.update();
  if (print_interval) {
    Serial.print(analog.getRawValue() * 100.f / analog.getMaxRawValue());
    Serial.print("\t");
    Serial.print(analog.getFloatValue() * 100.f);
    Serial.println();
}
}

The schematic:
image

IDE's settings:

Screenshot 2024-09-04 at 14.58.20

In order to upload the sketch I need to set the board to bootloader mode (B1 to GND) which makes the board inoperative BUT visible to IDE. After uploading the sketch I need to disconnect B1 to ground and reset via the onboard button. IDE won't detect the board anymore BUT it would be operative and recognised by Midi Monitor as a MIDI source.

I installed the esp32 package. The board's manufacturer recommends to use the Arduino Nano ESP32; however if I do so, the sketch gets uploaded but the board seems unresponsive.

Instead I selected the ESP32-S3-USB-OTG which seems to work fine if the Partition Scheme is set to 16M, otherwise the analog filter wouldn't work.

Thank you!

Edit: I just found this: Is there a partition scheme option for ESP32? - #7 by ptillisch

I'll try with the Dev Module board and see how it goes.

Hi @emanuino.

Due to the name being fairly generic, it isn't clear but the "ESP32-S3-USB-OTG" board definition is provided to add support for a specific development board:

https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s3/esp32-s3-usb-otg/user_guide.html

As mentioned in the post you linked, you can typically achieve a configuration equivalent to any of the model-specific board definitions by selecting the general purpose "dev module" board definition (in this case, "ESP32S3 Dev Module"), and then adjusting the various custom board options menus you will find under Arduino IDE's Tools menu after selecting that board.