8 Channel Arduino MIDI Switch
Recently I started testing the Arduino microcontroller platform. I ordered some Arduino Nano clones for about 7,- EUR. They work great – USB connectivity is onboard, so there is no need for programmers like with the PIC controllers; you can directly upload sketches from your PC to the Arduino. The Arduino IDE (Integrated Development Environment) is available for free (arduino.cc), so it is really easy to get your first programs running. It soon turned out that this platform is a great starting point for developing MIDI applications/hardware. Especially for DIY!
My first MIDI devices were based on the PIC microcontroller. I started programming the PICs with assembler, which is quite abstract and not really effective, especially if you’re not a pro… At least the PIC-based Mitch (MIDI Switch) is outdated (hard- and software). Time to move on – here comes the Arduino MIDI Switch!
The Arduino MIDI switch for guitar amp/effect switching is my first complete Arduino project. It receives MIDI program change messages from any MIDI pedal/device and can store switch settings for eight outputs with each program. You can set the MIDI receive channel (1-16); this setting will be saved, so it is persistent when switching on/off the device. The switch can be operated from only two push buttons. These buttons have different functions depending on a long/short press. There is a small 128×64 OLED display showing all relevant info, like current MIDI program number, MIDI channel, operating mode, etc.
Software for the Arduino platform is written in C++, which is a high-level language, so reading and writing code is more intuitive (there are also tools to program PICs in high-level languages – but that’s a different topic). Many Arduino projects deal with input/output processing (sensors, interfaces, displays, switches), there are many libraries with useful functions already available. The Arduino IDE comes with (basic) examples.
My software makes use of several Arduino libraries; if you decide to program your Arduino with this software, you have to download/install those libraries first, otherwise you will not be able to compile and upload my code:
- Software serial library (included in Arduino IDE by default)
- Text only Arduino library for SSD1306 OLED displays (https://github.com/greiman/SSD1306Ascii)
- Arduino OneButton library (https://github.com/mathertel/OneButton)
How to use the MIDI switch:
- Connect a MIDI device (any device sending MIDI program changes)
- Set the MIDI channel: Button 2 *long press* (repeated *long press* increases channel)
- Send program change on correct channel; MIDI in LED lights up shortly, display shows current program number
- Set outputs for current MIDI program number: Button 1 *long press* starts edit mode (edit mode LED lights up, display shows message)
- Select outputs: Button 1 *short press* cycles through switch index (1-8, shown on display)
- Toggle outputs (on/off): Button 2 *short press* changes output state of selected output (on/off shown on display)
- Exit edit mode/save settings: Button 1 *long press* (edit mode LED turns off)
Download for the source of the current software version (with CC function) is available here: MIDI_Switch_v12_2020-10
Download for the source of the older version (without CC function) is available here: MIDI_Switch_v10_2020-04
(Note: The version without CC function will not receive any further updates)
Hi Jens,
I have a question about the midi switcher.
Now that you have added the option that it can also respond to CC messages is great. This is exactly what I am looking for.
I’ve been testing this but now I’m running into something.
I use the Ground Control Pro foot switch.
This allows me to use the instant access function.
With this I can send CC messages. But what strikes me is that there is a delay for switching the outputs with this option. Suppose I have all outputs high in a preset. And in the next preset I make all the outputs low, then the outputs are low one by one. Instead of everything at once.
This works fine when I use can PC messages. But not with CC messages.
Is there a way to make this respond faster?
See the videos below.
Switching with PC messages:
https://youtu.be/fSnq-rs6iMg
Switching with CC messages:
https://youtu.be/JdWkbTLVre4
Regards,
Rico Coolen
Hey Jens. Thanks for your quick response.
Yes, what you say often suffices and is that perfect for that. So with cc command turn an fx on or off.
But in the way that I am testing, I can make presets very quickly with the ground control, without having to set anything on the receiver. I think that works great.
And so by using 2 of these midi switchers I can perform 16 functions.
In principle this could replace 2 gcx units.
And because I don’t do much with the display because when everything is set (address and cc values), I no longer need the display immediately.
So I’m definitely going to test that ff by commenting those lines.
If that works, I am super helped and will continue testing with it.
Hi Rico,
ok, I see what you mean. PC and CC commands are handled differently in the code. My idea of the CC function is that you change only single outputs at once, e.g. switch an amp channel or FX loop. But of course your idea of controlling a whole setup with CCs is perfectly fine. The Ground control is a complex device that can send lots of commands with just one button press. So one thing is to check if it is really only sending out those CC commands. I had a quick look at the code of the MIDI switch. After a CC command has been received, the corresponding output will be immediately set, and then the display will be updated. I f you send multiple CC commands, the MIDI switch will set the output for CC command #1, then update the display, then set the output for command #2, and then again update the display, and so on. Display routines take some time, maybe this adds up to the delay like we see it in the video. You might test the following: Comment or delete lines 270,271,272 (refreshdisplay, displayReset, displayResetTimestamp) in the code, compile/upload and test. The display won’t show CCs then, but you can test if the outputs respond faster this way.
Regards
Jens
I already had a discussion with a Ground Control user some time ago. The MIDI switch behaved strangely until he did a reset on his controller. But it might also be the case that the MIDI switch is too slow to respond to so many consecutive CC commands. What happens if you send only singe CC commands? Does the MIDI switch always reliably recognize them? If you send me your email with your next comment (won’t be published), I’ll try to send you a test version with some changes in the code. But this will take a couple of days.
Just tested, and that will do the trick.
So I commented those 3 lines.
But what I encounter now (and it was before) is that not all outputs always seem to respond.
I also made a video of this.
With switch 1 I send all outputs high.
With switch 2 I send the first 4 outputs high.
With switch 3 I send the last 4 outputs high.
What can be seen from 0:05 is that I switch to the last 4 outputs. However, output 1 still remains high. When I press switch 3 again, it switches off the first output.
And then at 0:23 I switch to switch 2, where the first 4 outputs should go high, however only output 4 switches. Even when I press this switch again, it does not switch.
Only after the 3rd time does it work.
When I test again after that, it seems to be fine again. So it’s really sporadic. Any idea where this could go wrong ??
https://youtu.be/3r-MN2SLKKM
Hi Jens, I just tested it and it also goes wrong with single cc commands.
I assume you are familiar with the Ground Control?
But it seems to work fine when I call the commands with the instant access button. So on the fly on and off. But when I program a number of instant access buttons under a preset that have to be high, things sometimes go wrong.
And then it doesn’t matter if it is 1 output, or all 8. Sometimes he hiccups once.
It would be great if we could fix this.
Thanks for thinking along.
I think I was able to reproduce your problem with a test setup, but it is software based on Win10 and I don’t know if it sends out the MIDI data like the GC does (or what the GC might do in the background); I’m not all familiar with the GC – nice device, but never got my hands on it. Anyway, I will make some changes to the code and send you an updated version so you can test with it. At least my changes fixed things in my test setup, but I still have to take a closer look and do some testing.
That sounds really good.
I’ll wait for your email and then start testing it.
Just tested which midi info I see on my computer.
I have programmed 4 buttons.
Button 1 all 8 outputs low.
Knob 2 first 4 outputs high.
Knob 3 last 4 outputs high.
Knob 4 all outputs high.
TIMESTAMP IN PORT STATUS DATA1 DATA2 CHAN NOTE EVENT
0000283D 1 — C0 00 — 1 — PC: Acc. Grand Piano
0000283E 1 — BF 50 00 16 — Control Change
0000283F 1 — BF 51 00 16 — Control Change
00002840 1 — BF 52 00 16 — Control Change
00002841 1 — BF 53 00 16 — Control Change
00002842 1 — BF 54 00 16 — CC: Portamento Ctrl
00002843 1 — BF 55 00 16 — Control Change
00002844 1 — BF 56 00 16 — Control Change
00002845 1 — BF 57 00 16 — Control Change
00002F01 1 — C0 01 — 1 — PC: Brite Acc. Piano
00002F02 1 — BF 50 7F 16 — Control Change
00002F04 1 — BF 51 7F 16 — Control Change
00002F05 1 — BF 52 7F 16 — Control Change
00002F06 1 — BF 53 7F 16 — Control Change
00002F07 1 — BF 54 00 16 — CC: Portamento Ctrl
00002F08 1 — BF 55 00 16 — Control Change
00002F09 1 — BF 56 00 16 — Control Change
00002F0A 1 — BF 57 00 16 — Control Change
00003CB5 1 — C0 02 — 1 — PC: Elec Grand Piano
00003CB6 1 — BF 50 00 16 — Control Change
00003CB7 1 — BF 51 00 16 — Control Change
00003CB8 1 — BF 52 00 16 — Control Change
00003CB9 1 — BF 53 00 16 — Control Change
00003CBA 1 — BF 54 7F 16 — CC: Portamento Ctrl
00003CBB 1 — BF 55 7F 16 — Control Change
00003CBD 1 — BF 56 7F 16 — Control Change
00003CBE 1 — BF 57 7F 16 — Control Change
00003F38 1 — C0 03 — 1 — PC: Honky-Tonk Piano
00003F39 1 — BF 50 7F 16 — Control Change
00003F3A 1 — BF 51 7F 16 — Control Change
00003F3B 1 — BF 52 7F 16 — Control Change
00003F3C 1 — BF 53 7F 16 — Control Change
00003F3D 1 — BF 54 7F 16 — CC: Portamento Ctrl
00003F3E 1 — BF 55 7F 16 — Control Change
00003F40 1 — BF 56 7F 16 — Control Change
00003F41 1 — BF 57 7F 16 — Control Change
Hi Rico,
cannot spend as much time on this as I would like to in the moment, but you can give this version a try (one major change in MIDI routine):
https://www.jimkim.de/wp-content/uploads/2021/02/MIDI_Switch_v12_2021-02_FastMidiLibrary.zip
Hi Jens,
First and foremost – thanks for the wonderfull page and the information sharing – I find it really geat and generous!
So I started work on the MIDI Switcher based in your code and schematics about a year ago and after a few days I had to put it down because of other interrups, but yesterday I revisited it again.
So since the beginning I am having a problem with the correct detection of the MIDI PCs. I am using as a MIDI Source the BOSS GT-100. So all the other stuff works fantastic ( Display, relay control, switches), but when it comes to the correct reception of the MIDI messges, I literaly hit a rock – in most of the cases it is barery working(in the others not at all), recognizing one out of 5 or 6 PCs. So I even tried a couple of other IC that the 6N138 (of course with the appropriate resistors), but this did not help.
Yesterday I tried both the updated old version without the CCs and the new version – unfortunately no luck. I suspected a bad connectoon on the breadboard, so I soldiered a small board only with the input on it so to day (6N138, the two resistors and the diode), but the reliability remained the same.
So I wanted to contact you and ask you if you have any idea how I can procede furhter to find the root cause of my problem – is there some debugging, tracing which can be used to determin what the arduino is seeing as a message in real time?
If needed I can upload video and or photos to dropox.
Thanks very much in advance and best regards,
Chavdar
Hi Chavdar,
cannot spend as much time on this as I would like to in the moment, but you can give this version a try (one major change in MIDI routine):
https://www.jimkim.de/wp-content/uploads/2021/02/MIDI_Switch_v12_2021-02_FastMidiLibrary.zip
Jens,
You’re a genius.
As far as I have been able to test now, it completely works. All outputs switch to the correct CC command.
Thank you very much for the time you put in. I can now continue designing the PCB of my switcher and if you are interested, I can show you the result later.
Thanks again for sharing this beautiful project.
Oh and regarding Chavdar’s question, I don’t have this problem. Not even with the old version of the switcher. Are you sure that your cables are good, or that the MIDI controller is sending out the correct signal?
Are you on the right midi channel?
Rico, I’m happy that it is working now! And I’m not a genius – I only fixed my own design error. When you develop as a hobby, you sometimes don’t see other use cases, and you can only test with a very limited number of devices. The older version worked for me, but obviously there are cases where it did not. I flushed the MIDI input buffer after every command, which caused problems when a sequence of many commands was being received.
I would be very interested in learning more about your project. 16 outputs is a lot, what do you do with them? If you like, send me some pictures and a description. I will put it on my website, maybe others are interested in your version, too. The more I think about the way you use the MIDI switch (only use CCs and do the programming completely on the Ground Control), the more I like it!
Well with the looper / switcher that I am now building, can switch 16 devices. This can be effects, using the appropriate send return jacks.
But I can also switch amplifier channels / send-return loops with it.
I can also choose an output to switch between 2 guitars and 1 amp, for example. Or just 1 guitar and 2 amplifiers.
All this by only connecting patch cables correctly.
The looper / switcher will soon offer me many options, so I now want to assume 16 outputs (especially since the GCP supports this by default).
Maybe an exaggeration, but we’ll see.
When I am ready, I will send you some info and images.
Hi Rico, Hi Jens,
Thank you for the support and the help!
@Rico: Yes, the setup is in order, because I already control 2 MIDI capable Amps with this cable and Boss GT-100 without any problems. The channel was also set right, like I wrote above, sometimes it got some of the PCs, but mostly it did not.
But…… it does not matter now!!!!!
@Jens: Rico said you are a genuis, Jens, I second that!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
After updating to the newest version, that you pointed me to, PCs work like charm now!!!!!!
I have still to try the CCs, but for my application I do not really need them and Rico already
So I guess it has something to do with the boss Midi implementation, although my amps had not problem with that.
Hey Chavdar, if you like, send some pics and a description of your project. I would be very interested in your version.
Hu Jens,
Sure It will be my pleasure. Right now there isn’t much to photograph – I have a breadboard with a Nano, displax a relay and couple of other stuff ( resistors, relay control, ..) just as a proof of concept.
The plan is to create a 16x relay switching station with a couple of MIDI Thrus and probably a phantom power supply for the MIDI IN. This will require of course two arduinos.
This will be the corner stone of midifying my setup and the main amp control machine
Hi Jens,
I have another question. I’ve picked up my switcher project again. Everything seems to work fine.
As I mentioned before, I switch with my Ground Control Pro with CC commands.
I use the following CC commands:
Board 1:
Loop #1 = controller #80
Loop #2 = controller #81
Loop #3 = controller #82
Loop #4 = controller #83
Loop #5 = controller #84
Loop #6 = controller #85
Loop #7 = controller #86
Loop #8 = controller #87
Board 2:
Loop #9 = controller #88
Loop #10 = controller #89
Loop #11 = controller #90
Loop #12 = controller #91
Loop #13 = controller #92
Loop #14 = controller #93
Loop #15 = controller #94
Loop #16 = controller #95
But what happens now. When I assign CC95 in the program, during every midi command that comes in, the following text appears on the screen:
Ctrl:Val 095:000 or Ctrl:Val 095:127.
But it only does this when value CC95 is assigned. I have not seen this happen with any other value.
Then it just remains:
Channel 16 PC:CC.
Any idea how I can remedy this?
Hi Rico,
if the MIDI switch switches outputs like you expect it to do, then this is the default behaviour. “Channel 16 PC:CC” means that the MIDI switch is set to channel 16 and that program change commands AND control change commands are active. If CC commands are active, the switch will display the last CC command that has been received (if a correspondig controller number is assigned in the setup) and it will display the last controller value (000/127 in your case). For matters of performance previous values might not be displayed if a lot of values have to be processed in a short time (display routines are slow) – in your setup, a lot of CC commands (16) will be sent from the Ground control with every patch, so only the last one will be displayed (CC95, like listed in your setup above). So from my point of view, everything works just fine 🙂
BTW: In the meantime, I also became the proud owner of a Ground Control Pro. Got it used for a good price.
Okay completely clear. Then I’ll leave it that way.
I wasn’t sure if this was the intent.
Good to hear you also have a GCP.
I’m curious about your experiences with it.
By the way, thanks for the quick response.
Hi There,
How hard is it to add switch functions to A0,A3,A6,A7… basically I was to incorporate this idea into an actual tube amp using momo switches to trigger the channels but it is slightly difficult to understand… I wouldnt mind help in understanding
Basically it is not that hard at all. Define addtitional buttons and actions based on your needs. You than need to write functions which will be executed on corresponding button presses. There maybe some more aspects that you will have to deal with when saving settings or loading initial switch states. My version is designed in a way so that only a minimum number of switches is needed. I think your aim is to control a number of outputs directly.
Hi Jens, thank you for sharing this wonderful project. I’ll be making a 5 loop switch using your code base, and I’m looking at including a digital potentiometer for a future expression output function. I need to free up pins 10(SS) and 11(MOSI) for use by the digital potentiometer, and in turn relocate the MIDI_LED and EDIT_LED to other unused digital pins.
Is this as simple as declaring these changed output pins like below:
int outputPins[] = {
2, 3, 4, 5, 6
const int outputCount = 5; // the number of output pins
#define MIDI_LED 8
#define EDIT_LED 9
// MIDI controller number assignment (controller number output pin)
int outputPinsControllerNumber[] = {
0, 0, 0, 0, 0
For the moment the additional digipot will be a future feature that I’ll program as I learn more. But I was hoping that by doing the above I’ll have a working loop switch for the interim!
Hi Dan, it has been some time since I last had a detailed look at my code :-). But yes, I think it should be possible the way that you have in mind. You could also consider to use two of the remaining analog pins, which can also be used as digital pins if I remember that correctly (and thereby keep 8 outputs). But this comes without any guarantee, please check the Arduino Nano documentation first.
Hi Jens,
Thanks for the response. I’ll do a bit of reading regarding using the other unused pins, and then do a bit of testing when my Arduino arrives.
Thanks,
Dan.
Hi, I’ve now set up everything on a breadboard and have been testing pretty heavily this afternoon. I’ve found an issue were the newest code, MIDI_Switch_v12_2021-02_FastMidiLibrary, crashes consistently when spammed with CC messages. I’m using the mountain utilities midi tools software testing the CC with the fader. I’m sure it is fine if just sending single CC values at a time to change the state. I reverted back to MIDI_Switch_v12_2020-10 and the program/nano don’t seem to crash when spammed in the same way with CC messages. I’ll just use this as my code base as I can just use PC if I need to change multiple outputs.
On a side note, I had no worries with re-assigning pins as above. I ditched the idea of using a digipot and instead programmed in 5 momentary switches assigned to each loop. What I have programmed seems to work fine, however I’m having to send the device into Edit mode to get the switching to happen. Looks like I can set the switch index, but the switch change won’t happen unless it’s in edit mode? If this is the case, I was going to look at programming a non blocking delay/timer to exit out of edit mode after 3-5 seconds. Any advice would be awesome if this is a silly way to do it!
Hi,
any update on Arduino MIDI controller pedal for guitar FX 🙂
Hi David, are you asking for the control pedal (https://www.jimkim.de/guitar-projects/arduino-midi-controller-pedal-for-guitar-fx/)? Well, basically the source code is finished, apart from the expression pedal function (continuous controller); I’m short on time at the moment, so there is no definite roadmap for this project. I might publish the current software version as is (=work in progress), though.
Hi is there picture how to connect analog things: input guitar, output, 8x guitar fx pedals snd return? In shematics I don’t see this or not understand as newbie. Thanks.
Hi Newbie, the projects on this site are not meant as “kits” in the sense of getting a detailed build plan for a complete device. Especially the MIDI projects are fully functional MIDI control units, but need some additional components based on your specific needs (e.g. audio loops, switch outputs with relays). This should not be too complicated, but this task is up to you. Go here (https://www.jimkim.de/guitar-projects/switching-guitar-audio-signals-with-relays/) for a starting point, and you will most likely find many more ideas concerning audio signal switching on other websites.
Working on a version of this that would fit in a Gorva C65 w/4 switches. Would love to figure out how to add a midi clock -> analog tap tempo output for controlling non midi gear (delays and modulations). Is this something you’ve looked into by chance?
Will report back on the success of the 4x switch version. Thanks for posting and definitely put up a donation page!
Hey Will, actually I’m working on a tempo related project: an external MIDI tremolo that sends volume control change messages via MIDI to my Eleven Rack, in order to create a tempo controlled tremolo/slicer effect – the “unique” function is a footswitch that enables me to re-sync the tremolo effect to the beat, because when playing live there is always some slight tempo deviation, even if the drummer is on a click. But that is not what you are looking for 🙂 Anyway, when starting my project I had a brief look at the MIDI tap tempo specification of my eleven Rack. Tap tempo control via MIDI is done with control change messages; I do not know if this is some kind of standard and how other devices deal with this. As the MIDI switch can convert CC messages to switch outputs, this may be the basic principle to deal with this, but most likely it will not be an ideal setup (mechanical relay not the best solution for this, and maybe you will get unwanted dividers (quarters, eigths, etc.)). If you have any MIDI device that can be configured to send tap tempo CC messages, you can test the basic functionality and see how it turns out.
Hi, Great project, I downloaded the MIDI_Switch_v12_2020-10 project and it seems that there are no files #include “OneButton.h”, #include “SSD1306Ascii.h” and #include “SSD1306AsciiWire.h” is this normal?
Thanks for help
Hey! Please read the instructions on my page. You have to install those libraries in your Arduino IDE; you can find them in the library manager.