Arduino USB MIDI Mux Pot Controller

The other application I wanted for my Arduino USB MIDI Mux Step Sequencer is as a general purpose MIDI controller.  In this case with 16 potentiometers mapped to MIDI CC messages.

This is building on the following previous projects:

Some other related projects:

Warning! I strongly recommend using an old or second hand keyboard for your MIDI experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

The Circuit

This is using the same circuit as before, once again with my Arduino Uno programmed as a class compliant USB MIDI device.  But I’m setting this up to allow me to change the synthesis parameters for my “Bare Metal” Raspberry Pi “Mini Synth”.  I also want to play it too, but I can’t have two USB MIDI devices plugged into my Raspberry Pi apparently – I tried it and it didn’t work, but I haven’t looked closely at the code to see why.

So instead, I’m using my Raspberry Pi v1 Model B Synth Board to provide a serial MIDI interface to my Raspberry Pi as well.  The final setup for me looks like the following.

Arduino USB MIDI Mux Controller - Connections

Here I’m using my Pico Toy MIDI Keyboard in “serial MIDI” mode and my Arduino Mux pot controller in USB MIDI mode.

The Code

The basic idea for the code is that each potentiometer has an associated MIDI control change message and if that potentiometer is turned the corresponding MIDI control message is generated and sent.  The full range of the potentiometers (0 to 1023) has to be mapped onto the more limited range of the MIDI CC messages (0 to 127).  The actual scanning of the potentiometers uses the same multiplexer code that I’ve used before.

I have a structure at the start of the code that defines which MIDI CC messages will link with which potentiometer.  The following is configured for my “bare metal mini synth” (see below), but you can use any useful CC control change messages here.

// Map potentiometers onto MIDI CC messages
uint8_t midiCC[NUM_POTS] = {
/* 00 */ 3,
/* 01 */ 74,
/* 02 */ 7,
/* 03 */ 89,
/* 04 */ 9,
/* 05 */ 20,
/* 06 */ 85,
/* 07 */ 91,
/* 08 */ 76,
/* 09 */ 21,
/* 10 */ 86,
/* 11 */ 94,
/* 12 */ 77,
/* 13 */ 22,
/* 14 */ 87,
/* 15 */ 71,
};

The actual scanning is done in the loop() scanning one potentiometer each time through the loop.  Whilst not strictly necessary it means that if any other code is added to the loop it won’t be waiting for all 16 potentiometers to be read before running.

Find it on GitHub here.

Bare Metal Mini Synth MIDI CC Map

The “mini synth” application I’m using, by Rene Stange, already supports the idea of controlling any aspect of a patch via MIDI CC messages.  There is a configuration file – midi-cc.txt – on the Raspberry Pi’s SD card that has a list of all the CC messages for each synthesis parameter and is read on power up.

I’ve kept the “obvious” CC mappings (that were suggested originally) and mapped the other parameters to various unused or “general use” CC messages as shown below.

#
# MIDI CC Mapping
#
LFOVCOWaveform=9
LFOVCOFrequency=76
VCOWaveform=3
VCOModulationVolume=77
VCODetune=94
LFOVCFWaveform=20
LFOVCFFrequency=21
VCFCutoffFrequency=74
VCFResonance=71
EGVCFAttack=23
EGVCFDecay=24
EGVCFSustain=25
EGVCFRelease=26
VCFModulationVolume=22
LFOVCAWaveform=85
LFOVCAFrequency=86
EGVCAAttack=73
EGVCADecay=75
EGVCASustain=88
EGVCARelease=72
VCAModulationVolume=87
ReverbDecay=89
ReverbVolume=91
SynthVolume=7

When linked with my CC MIDI map in the Arduino, this should give me the following map of parameters to my 16 pots.

Arduino USB MIDI Mux Controller - Pot CC Map

I didn’t have enough pots to include mappings for the two envelope generators, but the system will still support a mouse alongside the USB MIDI controller, so I can just use that for now.

One thing I wasn’t sure about initially – I didn’t know if I’d have to set the parameters with exact numbers in the MIDI CC messages – so for example, the main VCO wave can have the values 0 to 6 and that is all.  This would have required special knowledge of the application within the Arduino which limits the usefulness quite a lot.

Thankfully this isn’t necessary as the mini synth code will take a MIDI CC parameter’s full range of 0 to 127 and map it onto whatever parameter range makes sense within the synth taking into account ranges that are both smaller and larger than the MIDI 0 to 127.

This also means I don’t need to worry about “LSB/MSB” encoding the MIDI messages.  This is a way of using two 7-bit MIDI messages to give a 14-bit value in total.  This will use two MIDI messages but does allow parameters to have a range of 0 to 16383. But that is also quite a lot more complicated to code up at both ends!  But as some of the parameter ranges for the synth settings were larger than 127, I was starting to wonder if it would be required, but it is all taken care of.

The downside is that some of the resolution for larger ranges is lost – so for example, when the detune setting is change, it can take a value from 0 to100 (no detune) to 200.  But the equivalent MIDI messages will go from 0 to 63 (no detune) to 127.

Closing Thoughts

This really starts to show what the “bare metal Raspberry Pi mini synth” can do. Having actual knobs to twiddle makes adjusting the patches so much easier!  In fact it isn’t much more of a step to start imagining a custom control panel for the synth…

But in terms of playing around with Arduino Uno USB MIDI I think I’ve shown plenty of opportunities now.  It would now be a pretty small step to build any kind of USB MIDI controller from an Uno should the need arise.

Kevin

IMG_5977

8 thoughts on “Arduino USB MIDI Mux Pot Controller

  1. Thanx u verry much for the great tutorial, had help me a lot. It’s working on my mega board with de mocoLufa “hack” on Bitwig, Reaper and Ableton. I’m tryng to build a 48 pot midi controller, i’m wondering if there is a way to add 2 more 4067 muxs to this program. I tried copyng and editing your code but didn’t work : (

    Obrigado from São Paulo, Brasil!!!

    Like

    1. Ah yes, as it happens I did an update to one of my MIDI controller projects to show how it could be extended using multiple 4067 or 4051. The trick is to use the same control (digital) pins, but connect each one up to a different analog input.

      There are some details here: https://diyelectromusic.wordpress.com/2022/05/05/arduino-midi-multi-mux-controller/

      Have a look and see if that helps. If not, give me a shout back and we can talk more about exactly what you’re trying to do.

      (I’ve now updated the post to include a link to this newer project too)

      Good luck!
      Kevin

      Like

      1. Ola Kevin, the multi-mux-controller it’s working perfectly! Tomorrow i’ĺl try it with 4 muxes.

        MUCHAS GRACIAS!!!!!!!!!!!!!!!!

        Like

      1. Hi Kevin, tried the same code for buttons and didn’t worked. : (

        Tried the same connection with the “control surface” code and worked fine, so i guess the hardware is ok. I will love to finish the project with your code, because a find it simpler, lighter, better, prettier…. hahahahah. Do you have any idea where i can start to search for a solution? MUCHISIMAS GRACIAS!!!!!!!!!!!!!!

        Like

      2. Ah, no sorry, I don’t have any code for multiplexing buttons, but I’d imagine it would be very similar… just with a single analog on/off value being read instead of the 0 to 1023 values…

        But no, I don’t have code for that at present.

        Liked by 1 person

Leave a comment