Sunday, 10 July 2016

Arduino MIDI Controller: Multiplexers

More, More, More!!


Over the last couple of tutorials we have been building up a MIDI Controller using a trusty Arduino UNO board. So far, we've learned how to connect buttons and potentiometers to the controller and generally had a lot of fun.

"But Dave!! I want to build a custom controller with a zillion pots and buttons! The UNO only has six measily analog inputs and a handful of digital ports! What can I do????"

Never fear! We can add lots of controls to our project with the help of Multiplexers.

Watch This!



What is a Mux?


A Multiplexer is a chip with multiple inputs that can be individually connected to a single output. By sending different combinations of signals to some control pins, each button or pot connected can be read by a single pin on the Arduino. The video explains this in detail.

We will be looking at two popular multiplexers in this lesson. The first is the 74HC4051 which has 8 inputs. The second is the 74HC4067 which has a impressive 16 inputs.

The Software


The Midi Controller program we have used in previous lessons can handle either type of multiplexer with some simple configuration. The video will show you how. Download the software HERE if you don't have it yet.

Stuff you need (With Amazon links)


Here are the parts you will need to do the experiment:

Arduino UNO or Arduino UNO (Official Adafruit Version)

2 x 10K Potentiometers (Linear taper) - Inexpensive
or model used in video

2 x Push Button Switch

74HC4051 Multiplexer (8 Input)
74HC4067 Multiplexer (16 Input)

Breadboard (63 pin width)

MIDI Jack

2 x 220 Ohm Resistors

Jumper Wires

MIDI Cable




12 comments:

  1. Hi!
    How to install leds for the buttons, if i want that when I push the button the led is lightning?
    Thanks You! :)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. How do I put 2 74hc4067? They are connected in series or parallel?

    ReplyDelete
  4. I can not use more buttons in ... Y2... Y7 imputs. I need to change something to use only buttons?

    ReplyDelete
  5. I used buttons Yo, Y1, Y2, Y3 but not get in the other Imputs.

    ReplyDelete
  6. Can I use Analog and Digital at the same time with this Program?

    ReplyDelete
  7. Hi. Many Tks for this blog and this prog.
    May I share my experiment.
    Yes you can use analog and digital at the same time but it has to be one DEMUX board for each.
    I have manage to use up to 3 full DEMUX board but the arduino won't cope a fourth full used board due to lack of memory.
    My project is a 30 fader midi interface for a lighting program.
    RGDS.

    ReplyDelete
  8. FYI modified Controller.cpp for the MEGA on pin 22-25:
    #if defined(__AVR_ATmega2560__)
    void Button::muxUpdate()
    {
    // set S pins on MUX in correct value to read value : eg read Y2: S2-S1-S0 = B010
    // pins used on MEGA: 22 (PA0), 23 (PA1), 24 (PA2), (25 (PA3))
    // set MUX S-pins LOW
    if (_numMuxPins > 8) PORTA = PORTA & B11110000;
    else PORTA = PORTA & B11111000;

    // add value of temp to PORTA (= add value of the required channel, so set the correct pins)
    PORTA = PORTA | _muxpin;
    }

    #elif defined(__AVR_ATmega328P__)

    void Button::muxUpdate()
    {
    byte temp = _muxpin;
    temp = temp << 2;
    if (_numMuxPins > 8) PORTD = PORTD & B11000011;
    else PORTD = PORTD & B11100011;
    PORTD = PORTD | temp;
    }
    #endif

    ReplyDelete
  9. Hi. I'm trying to make this work with arduino pro micro (compatible with leonardo). It's based on ATmega 32u4. With Arcore midi library it can send midi signals via usb. This is working perfectly:) But there is little problem with reading mux inputs. One potentiometer/button triggers all signals at one time. Rest of potentiometers/buttons do nothing. Anyone can help with this?:) Ive checked connections 100 times, and it should be working. I think something in the code must be changed, but many attempts faild...

    ReplyDelete