Arduino UNO As A MIDI Keyboard

Hello Guys,
I'm an equipment designer and I created this MIDI Keyboard
I made it depending on Arduino UNO chip and 2 CD74HC4067 multiplexers for a total of 32 buttons and I added 3 analog inputs for the two wheels and the foot pedal
I'm facing a problem with the code as many things aren't functioning as expected ..
I want to program the left potentiometer to be a pitch wheel and work just fine as the Modulation Wheel and the octave buttons and the ( Record - Play - Stop ) Buttons on the device and I want the left two buttons to switch between instruments and the UNO to be recognized as a midi controller
Here's the device :smiley:

and here's the code :smiley:

#include <Control_Surface.h>

USBMIDI_Interface midi;

CD74HC4067 M1 = { 6, {5, 4, 3, 2} }; 
CD74HC4067 M2 = { 7, {5, 4, 3, 2} };

 NoteButton buttons[] = {
    { M1.pin(0), {48, CHANNEL_1} }, 
    { M1.pin(1), {49, CHANNEL_1} },
    { M1.pin(2), {50, CHANNEL_1} },
    { M1.pin(3), {51, CHANNEL_1} },
    { M1.pin(4), {52, CHANNEL_1} },
    { M1.pin(5), {53, CHANNEL_1} },
    { M1.pin(6), {54, CHANNEL_1} },
    { M1.pin(7), {55, CHANNEL_1} },
    { M1.pin(8), {56, CHANNEL_1} }, 
    { M1.pin(9), {57, CHANNEL_1} },
    { M1.pin(10), {58, CHANNEL_1} },
    { M1.pin(11), {59, CHANNEL_1} },
    { M1.pin(12), {60, CHANNEL_1} },
    { M1.pin(13), {61, CHANNEL_1} },
    { M1.pin(14), {62, CHANNEL_1} },
    { M1.pin(15), {63, CHANNEL_1} },

    { M2.pin(0), {64, CHANNEL_1} }, 
    { M2.pin(1), {65, CHANNEL_1} },
    { M2.pin(2), {66, CHANNEL_1} },
    { M2.pin(3), {67, CHANNEL_1} },
    { M2.pin(4), {68, CHANNEL_1} },
    { M2.pin(5), {69, CHANNEL_1} },
    { M2.pin(6), {70, CHANNEL_1} },
    { M2.pin(7), {71, CHANNEL_1} },
    { M2.pin(8), {72, CHANNEL_1} }, 

};

CCPotentiometer Potentiometers[] = {
  { A0, {MIDI_CC::Modulation_Wheel , CHANNEL_1} }, //Wheel 1
  { A1, {MIDI_CC::Breath_Controller  , CHANNEL_1} }, //Wheel 2
  { A2, {MIDI_CC::Foot_Controller , CHANNEL_1} }, //PEDAL
};

CCButton Buttons[] = {
    { M2.pin(9), {MIDI_CC::General_Purpose_Controller_2, CHANNEL_1} }, 
    { M2.pin(10), {MIDI_CC::General_Purpose_Controller_3, CHANNEL_1} }, 
    { M2.pin(11), {MIDI_CC::General_Purpose_Controller_4, CHANNEL_1} }, 
    { M2.pin(12), {MIDI_CC::General_Purpose_Controller_5, CHANNEL_1} }, 
    { M2.pin(13), {MIDI_CC::General_Purpose_Controller_6, CHANNEL_1} }, 
    { M2.pin(14), {MIDI_CC::General_Purpose_Controller_7, CHANNEL_1} }, 
    { M2.pin(15), {MIDI_CC::General_Purpose_Controller_8, CHANNEL_1} }, 

};
void setup() {
  Control_Surface.begin();
}
 
void loop() {
  Control_Surface.loop();
}

This is one of the most important pieces in my studio and I need to get it done right
thanks In Advance.

The Arduino UNO doesn't have a native USB interface. It uses the ATmega16u2 to convert between Serial and USB. There are two ways to get it to act as a USB device. You can load special firmware on the ATmega16u2, or you can use a soft-USB library and add a USB cable to the required pins.

Do the instructions for the Control_Surface library mention either of those options?

we should ask @PieterP

If you have a studio, you probably have a few more USB-Midi devices (or at least one,) which is all you need really.

I checked the control surface library and it says that Arduino UNO can be recognized as a midi device using the USBMIDI_Interface midi; in the code .. the chip is recognized as a serial device however it's an original one not a Chinese clone

I'm waiting for his reply actually .. It works somehow but I need some clear instructions because YouTube is useless and nothing is clear

I don't have a studio but I use those devices in live performances I use a midi keyboard and a drum machine B2B with my soundcard that gives 4 decks stereo outputs ..

Do you have the D+ wire of your USB cable connected to Pin 2 and the D- wire of your USB cable connected to pin 7?

1 Like

No .. (2 - 3 - 4 - 5) pins are the (S0 - S1 - S2 - S3) of the MUX and 6 & 7 are signal pins from the MUX ... A0 ,A1 & A2 are analog pins of the pots

You will have to move those functions off of Pin 2 and Pin 7 so you can use the USB library's default pins or you have to figure out how to re-configure the USB library to use different pins. I think the library requires Pin 2 or Pin 3 so it can use the External Interrupts. You could move S1 to Pin 8 and the signal pin from Pin 7 to Pin 9 or A3.

I saw a way of changing the software to Hiduino on youtube without connecting any pins to the chip it was normally through the USB socket

Yep i've looked at that link also. Should work on an UNO, But before you do that, you will need to make sure that the rest of your sketch works properly the way you want it, since you will need a programmer to update that code after you have gone through the process. I never did, and i either just hook into my main midi chain in my studio or i use an Arduino that does have native USB support, like a micro (or a leonardo i think never sure i use micros )
true Midi does have some advantages, the length of the cable you can use is one of them

And that has a Midi port ?

Arduino UNO & MEGA has a native USB support too but it has a certain way of coding
I don't wanna use Hairless midi or any other stupid software

no .. only 8 inputs & 8 outputs all audio

HIDUINO takes advantage of Arduino boards where a second AVR chip is used as the USB controller, so it won't work with single chip variants (e.g. Leonardo), nor older boards that use an FTDI chip as USB controller (e.g. Duemilanove). Many cheap Arduino knockoffs that pretend to be an Uno or Mega also might not work, since they tend to use the (slighly) cheaper FTDI chips.

Remember when I said:

The loading of special firmware is what they did. What you are doing is "use a soft-USB library and add a USB cable to the required pins".

1 Like

Not the same way. It has a separate chip for USB.

Of course not, I am still a little puzzled but some things. If you want to use Midi, get Midi ! it is a fantastic protocol !
Even if you want to keep using the UNO, turn it into a Midi device and get a Micro to act a 1x1 midi port (or just get one of those of course, but they cost E30,- over here and a micro i can get for E3,- )
That is the way to keep a dynamic work environment.

1 Like

Where does it say that?

Please see Control Surface: MIDI over USB

If you want to use native MIDI over USB support, you'll have to get a different type of Arduino.

:smile:

I've just rechecked the link and I can use the UNO as midi by flashing the code first using the
USBMIDI_Interface midi;
then flashing the midi firmware and then it will be recognized as a midi device automatically


.......
what I need now is assigning buttons to take the right action because only note buttons and Modulation wheel are working fine while the rest aren't doing the right thing and the Unstoppable messages don't stop however I'm using capacitors this time in every single part as you told me before in the MEGA project

Somebody please help me ...

Which messages?

inputs are sending noise to the software however I'm using capacitors everywhere
I think it's a problem with the code

No, I mean which messages? Which CC#, which channel, which pin?