# control surface two multiplexers 4051 - midi controller

**URL:** <https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397>\
**Category:** Audio\
**Created:** [August 23, 2020, 1:01pm UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397 "2020-08-23T13:01:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pagarreton](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@pagarreton](https://forum.arduino.cc/u/pagarreton)\
**Post date:** [August 23, 2020, 1:01pm UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/1 "2020-08-23T13:01:04Z")

</div>

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](https://tttapa.github.io/Control-Surface-doc/Doxygen/index.html) 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.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 23, 2020, 5:57pm UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/2 "2020-08-23T17:57:03Z")

</div>

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.

* * *

![](https://europe1.discourse-cdn.com/arduino/original/4X/c/a/4/ca4c01a634142061b16f771da65a0d29f1648353.jpeg)

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [August 25, 2020, 10:42am UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/3 "2020-08-25T10:42:52Z")

</div>

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:

```cpp
// 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:

```cpp
// 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

---

<div class="post-metadata">

**Author:** ![pagarreton](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@pagarreton](https://forum.arduino.cc/u/pagarreton)\
**Post date:** [September 1, 2020, 1:25pm UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/4 "2020-09-01T13:25:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Robobuns](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Robobuns](https://forum.arduino.cc/u/Robobuns)\
**Post date:** [October 19, 2020, 10:42pm UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/5 "2020-10-19T22:42:53Z")

</div>

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!

```cpp
#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(); }

```

![](https://europe1.discourse-cdn.com/arduino/original/4X/0/9/9/0999ae049f588cc5a1a19e035bb1988aa63c8897.jpeg)

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [October 20, 2020, 12:08am UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/6 "2020-10-20T00:08:00Z")

</div>

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](https://tttapa.github.io/Control-Surface-doc/Doxygen/d6/dc6/md_pages_Basics.html). 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](https://tttapa.github.io/Control-Surface-doc/Doxygen/d4/dbe/namespaceMIDI__CC.html))

---

<div class="post-metadata">

**Author:** ![Robobuns](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Robobuns](https://forum.arduino.cc/u/Robobuns)\
**Post date:** [October 20, 2020, 12:14am UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/7 "2020-10-20T00:14:24Z")

</div>

Thank you!!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 4:28am UTC](https://forum.arduino.cc/t/control-surface-two-multiplexers-4051-midi-controller/671397/8 "2021-05-06T04:28:16Z")

</div>

Closed on May 6, 2021, 4:28am UTC


