control surface two multiplexers 4051 - midi controller

I am creating a simple 16 potentiometers midi controller with the amazing Control Surface Library.
I am using the example code found here Control surface example and I am successfully receiving 8 potentiometer as midi usb with an Arduino micro.

My question is how can I add a second multiplexer with 8 extra potentiometers?
The 4051 multiplexer is connected to the digital pins 3,4,5 and is connected to the A0 input. Should I connect the second multiplexer to the same digital pins and the A1?

Any help would be appreciated.

Pin 6 on the 74HCT4051 is the enable pin.

Connect one mux enable to D7 and the other mux enable to D8.

Only A0 would be used.


But, you can forget about the enables and have one mux go to A0 and the other to A1.


D3, D4 and D5 go to each mux.


larryd already explained the hardware part, I'll add some code examples:

If you have enough analog input pins available on the Arduino, it's easiest to just connect each multiplexer to a different analog input pin. You can share the address lines. In your code, you could use something like this:

// Instantiate an analog multiplexer
CD74HC4051 mux1 = {
  A0,       // Analog input pin
  {3, 4, 5} // Address pins S0, S1, S2
};
// And another one, with the same address pins but a different input
CD74HC4051 mux2 = {
  A1,       // Analog input pin
  {3, 4, 5} // Address pins S0, S1, S2
};
 
// Create an array of potentiometers that send out MIDI Control Change messages 
// when you turn the potentiometers connected to the 8 input pins of the muxes.
CCPotentiometer volumePotentiometers[] = {
  { mux1.pin(0), { MIDI_CC::Channel_Volume, CHANNEL_1 } },
  { mux1.pin(1), { MIDI_CC::Channel_Volume, CHANNEL_2 } },
  // ...
  { mux2.pin(0), { MIDI_CC::Channel_Volume, CHANNEL_9 } },
  { mux2.pin(1), { MIDI_CC::Channel_Volume, CHANNEL_10 } },
  // ...
};

If you only have one analog input to work with, you can use the enable pins of the multiplexers:

// Instantiate an analog multiplexer
CD74HC4051 mux1 = {
  A0,        // Analog input pin
  {3, 4, 5}, // Address pins S0, S1, S2
  6,         // Enable pin
};
// And another one, with the same address and input pins but a different enable pin
CD74HC4051 mux2 = {
  A0,        // Analog input pin
  {3, 4, 5}, // Address pins S0, S1, S2
  7,         // Enable pin
};

Pieter

Thank you very much for the answers! I will continue with the project during the next days and I will share the results.

This is an amazing library!

Hello! I have used the example above to run two multiplexers.

My problem is, that both multiplexers seem to share the same channels.

When I try to name the channels beyond 16, it says channel was not declared.

what should i do, here?

Thanks!

#include <Control_Surface.h>

//USBMIDI_Interface midi;

HairlessMIDI_Interface midi;

//StreamDebugMIDI_Interface;

//CCPotentiometer pot = { A0, MIDI_CC::General_Purpose_Controller_1 };

CD74HC4067 mux = { A0, {3, 4, 5, 6, } };
CD74HC4067 mux2 = { A1, {3, 4, 5, 6, } };

CCPotentiometer volumePotentiometers[] = {
    //{ mux.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_1} },
    //{ mux.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_2} },
      //{ mux.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_3} },
      //{ mux.pin(3), {MIDI_CC::Channel_Volume, CHANNEL_4} },
     //{ mux.pin(4), {MIDI_CC::Channel_Volume, CHANNEL_5} },
    //{ mux.pin(5), {MIDI_CC::Channel_Volume, CHANNEL_6} },
    //{ mux.pin(6), {MIDI_CC::Channel_Volume, CHANNEL_7} },
    //{ mux.pin(7), {MIDI_CC::Channel_Volume, CHANNEL_8} },
    //{ mux.pin(8), {MIDI_CC::Channel_Volume, CHANNEL_9} },
   //{ mux.pin(9), {MIDI_CC::Channel_Volume, CHANNEL_10} },
   //{ mux.pin(10), {MIDI_CC::Channel_Volume, CHANNEL_11} },
    //{ mux.pin(11), {MIDI_CC::Channel_Volume, CHANNEL_12} },
    //{ mux.pin(12), {MIDI_CC::Channel_Volume, CHANNEL_13} },
    //{ mux.pin(13), {MIDI_CC::Channel_Volume, CHANNEL_14} },
    //{ mux.pin(14), {MIDI_CC::Channel_Volume, CHANNEL_15} },
    //{ mux.pin(15), {MIDI_CC::Channel_Volume, CHANNEL_16} },

//
          
    { mux2.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_17} },
    //{ mux2.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_18} },
      //{ mux2.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_19} },
      //{ mux2.pin(3), {MIDI_CC::Channel_Volume, CHANNEL_20} },
     //{ mux2.pin(4), {MIDI_CC::Channel_Volume, CHANNEL_21} },
    //{ mux2.pin(5), {MIDI_CC::Channel_Volume, CHANNEL_22} },
    //{ mux2.pin(6), {MIDI_CC::Channel_Volume, CHANNEL_23} },
    //{ mux2.pin(7), {MIDI_CC::Channel_Volume, CHANNEL_24} },
    //{ mux2.pin(8), {MIDI_CC::Channel_Volume, CHANNEL_25} },
   //{ mux2.pin(9), {MIDI_CC::Channel_Volume, CHANNEL_26} },
   //{ mux2.pin(10), {MIDI_CC::Channel_Volume, CHANNEL_27} },
    //{ mux2.pin(11), {MIDI_CC::Channel_Volume, CHANNEL_28} },
    //{ mux2.pin(12), {MIDI_CC::Channel_Volume, CHANNEL_29} },
    //{ mux2.pin(13), {MIDI_CC::Channel_Volume, CHANNEL_30} },
    //{ mux2.pin(14), {MIDI_CC::Channel_Volume, CHANNEL_31} },
    //{ mux2.pin(15), {MIDI_CC::Channel_Volume, CHANNEL_32} },

};

    
//constexpr analog_t maximumValue = 16383 - 255;
void setup() {
    Control_Surface.begin();
    Serial.begin(115200);
    }
void loop() { Control_Surface.loop(); }

There are no channels beyond channel 16, the MIDI standard only defines 16 channels. If you need more than 16 controllers, they need to have a different controller number, see MIDI Addresses. For control change messages, you can use the addresses (controller numbers) 0 through 119. "Channel Volume" is just one of those 120 controllers. It doesn't matter if you use the number or the name of a controller, e.g. MIDI_CC::Channel_Volume is defined as the constant integer 7. (Control Surface: MIDI_CC Namespace Reference)

Thank you!!