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




30 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
    Replies
    1. How can i use it?

      Delete
    2. I guess by replacing (in Controller.cpp):

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


      WITH:

      #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



      Delete
    3. And then placing the mux S0 to S3 on pin: 22, 23 , 24 , 25

      I'll let you know for sure after I get my mega in the mail :P

      Delete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Thanks for this well-explained video tutorial! I don't know enough about C to figure out whether your controller library can be modified to allow "coarse" (7-bit) NPRN parameters to be assigned to pots / buttons on this shield project.

    However, it seems if an NRPN flag is added to the "command" variable, and if the "note number" / "byte command" variables can hold a 14-bit value for the number of the NRPN parameter to change, then a routine could be added to issue the 9 bytes that make up the NPRN parameter change command (CC / #99 / MSB of NPRN parameter / CC/ #98 / LSB of NPRN parameter / CC/ #6 / 7-bit parameter value to send).

    Is this possible?

    ReplyDelete
  11. Thanks notesandvolts for this tutorial! and thanks again!

    ReplyDelete
  12. hi, i dont understand why but i can't manage to get more pots on multiplexer going right. I use Arduino atmega2560 i did everything as in the tutorial and when i connect more than one pot to it, change program, and suddently it does not work. The first one what was working like a charm when was single on multiplexer after connecting second one start giving random CC number and channel too, the second one does not react at all.

    ReplyDelete
    Replies
    1. Hi Neytal Dub,

      Kind of have the same problem with the Arduino Uno. The Mux seems to send a lot of noisy data. Did you manage to solve that issue ? Dave, have you ever encountered such situation ?

      Thank you for the great tutorials btw !

      Delete
    2. Hi,
      I have the same issue with the signal out of the multplexer. I don't know how to correct it. I tryed resistors IN or OUT, nothing works.
      I have 2 midi signals, one when I push and one when I released the button. I don't understand that too.
      If you have informations, I take !

      Thanks a lot for the tutorials Dave

      Delete
  13. This has been the tutorial I have dreamed of for midi on arduino. The only issue I'm having is it doesn't appear the arduino is storing the sketch. I can upload the sketch and it functions correctly. Once I disconnect the USB cable and reconnect, the sketch does not boot. Google says I have a bad bootloader, however any arduino example sketch uploads and stores like normal. The program doesn't appear to be too big. What am I missing? Thanks in advance and love the channel!

    ReplyDelete
    Replies
    1. Fácil de solucionar ese problema, tienes que convertir tu Arduino en un dispositivo HID, BUSCALO EN GOOGLE 'HIDuino' , a mí me funciona excelente.

      Delete
  14. Hi, i wonder if there is a way how increase read of difference between old and new value on pots. So the pot will not react on small changes. the thing is that i have used cca 30 pots on mixconsole but some of them keep sending messages with very small change. I would like to make all of knobs bit less sensitive so when i want to learn midi knob in software it would not get milions of noise signals. I belive that has to do something with sheet controller.cpp but i am not sure witch part is it. Thank you for any idea

    ReplyDelete
  15. hi dave,
    i'm using 27 potentiomete and 16 buttons to arduino uno
    but how can connect 27 pots via two 4067 mux and 16 buttons via 4067 mux
    i'm making to control vdj 8.2

    ReplyDelete
  16. Hi Dave, I would like to know if it is possible to connect several multiplexers at the same time, and what modifications would have to be made apart from the array ... I would like to connect as many as possible because I would like to make a midi mixing console

    ReplyDelete
  17. Dalek DIY Arduino MIDI floor keyboard

    Totally based on Notes and Volts awesome work:
    http://www.notesandvolts.com/…/midi-and-arduino-circuit-ana…
    http://www.notesandvolts.com/…/midi-for-arduino-build-midi-…
    http://www.notesandvolts.com/…/arduino-midi-controller-pote…
    http://www.notesandvolts.com/…/arduino-midi-controller-butt…
    http://www.notesandvolts.com/…/arduino-midi-controller-mult…

    Features:

    - Chromatic footswitches (12 notes)
    - Latching retro illuminated sustain footswitch sends MIDI CC 64 and lights when active
    - Latching retro illuminated modulation "wheel" footswitch sends MIDI CC 1 and lights when active
    - External footswitch jack can receive 1 or 2 external non latching button pedals tip to gnd and ring to gnd (mode selectable via internal switch) programmable via Arduino sketch to send any MIDI message
    - External expression pedal jack programmable via Arduino sketch to send any MIDI message
    - Power ON footswitch
    - Power ON LED
    - TX activity LED lights when MIDI messages are sent
    - DuPont jumper cables to Arduino pins and 2.1 DC plug from ON switch to Arduino DC jack allow to extract the board for easy reprogramming.

    Recipe: https://drive.google.com/drive/u/1/folders/148cmGwMxRVZijUVTqGz-qSvRcxxbOWm9?usp=drive_open

    ReplyDelete
  18. hi. im new in arduino and i want to make midi control. i gave arduino mega and i want to make full digital and full analog midi control. can i make full 54 button and 16 fader from arduino mega without multiplexer?
    can i use your sketch for it?
    thankyou and i really hope you replay as son as posible.

    ReplyDelete
    Replies
    1. i have te same question and how to write the code then?

      Delete
  19. hoe gebruik ik de arduino mega met 3 analoge multiplexers met faders en 4 digitale multiplexers met knoppen met deze code als dat kan met deze code
    en bedankt voor de mooie tutorials

    ReplyDelete