📜 ⬆️ ⬇️

USB MIDI controller on Arduino

image

Once again, playing the guitar and controlling the sound through Peavey ReValver and other Amplitube, I thought about purchasing a MIDI controller. Branded devices, like Guitar Rig Kontrol 3, cost about 13,000 rubles, and have only outdoor performance. That is, to quickly change the position of several regulators is very problematic.

Various DJ controllers looked more interesting due to the abundance of faders and encoders. It was decided to combine business with pleasure and make the MIDI controller itself.

Initial requirements: 2-7 faders, as many rotary potentiometers / encoders, about 10 buttons, USB connection.
')
Then I began to choose components. Arduino chose because of availability, in principle, you can use the same ATmega32u4, STM, or another controller. Faders and buttons found in the local radio store. Encoder and potentiometers have already been purchased. Toggle switches found in the garage. Case decided to make a top cover of the DVD player.

Accessories:


At first I bent the casing and sawed through it a hole in the fader holes:

image

Then he drilled holes for toggle switches and a mouth. potentiometers, marked the position of the buttons. Since I did not have any drills at 19 (and I didn’t have the corresponding chuck for the drill), I drilled holes for the buttons at 13 and then increased the sweep.



The base is ready, now you can think how to connect all this stuff to the Arduino. While studying this issue I came across a wonderful project HIDUINO . This is the firmware for the ATmega16u2 on board the Arduino, thanks to which the device is defined as a USB-HID MIDI device. All we have to do is send MIDI data over the UART at 31,250 baud. In order not to clutter up the sources with defines with MIDI event codes, I used this library .

Since I used Arduino, I decided to make a shield to which all the peripherals will already be connected.
Schild scheme:

image

As can be seen from the scheme of the button connected in a matrix scheme. The built-in pull-up resistors are ATmega328, so the logic is inverse.

Button Initialization
for(byte i = 0; i < COLS; i++){ //--      pinMode(colPins[i], OUTPUT); //--   . 1 digitalWrite(colPins[i], HIGH); } for(byte i = 0; i < ROWS; i++){ //--     --------- pinMode(rowPins[i], INPUT); //--     -- digitalWrite(rowPins[i], HIGH); } 

Reading values
  for(byte i = 0; i < COLS; i++) //-   ----- { digitalWrite(colPins[i], LOW); //--    0--- for(byte j = 0; j < ROWS; j++) //--   -- { //--     -- dval=digitalRead(rowPins[j]); if ( dval == LOW && buttonState[i][j] == HIGH ) MIDI.sendNoteOn(kpdNote[j][i],127,1); if ( dval == HIGH && buttonState[i][j] == LOW ) MIDI.sendNoteOff(kpdNote[j][i],127,1); buttonState[i][j] = dval; } digitalWrite(colPins[i], HIGH); } 



I forgot to place diodes on the seal, I had to solder to the buttons.

Potentiometers are connected through the multiplexer 4052b to the inputs of the ADC.

Potentiometer reading
  for(byte chn = 0; chn < 4; chn++) //-    { set_mp_chn(chn); //--   val=analogRead(0) / 8; //--    X if (abs(val-PrVal[chn]) > 5) //--   .   { //--   5,     MIDI.sendControlChange(chn,val,1); PrVal[chn]=val; } val=analogRead(1) / 8; //--    Y  X if (abs(val-PrVal[chn+4]) > 5) { MIDI.sendControlChange(chn+4,val,1); PrVal[chn+4]=val; } } 


Encoder hung on hardware interrupt.

Encoder reading
 void enc() //   { currenttime=millis(); if (abs(ltime-currenttime)>50) //  { b=digitalRead(4); if (b == HIGH && eval<=122) eval=eval+5; else if (b == LOW && eval>=5) eval=eval-5; MIDI.sendControlChange(9,eval,1); ltime = millis(); } } 


He made a printed circuit board in the Sprint layout, then made it with the good old LUTs using self-adhesive film and ferric chloride. The quality of soldering suffers from terrible solder.

Ready Shield:




To fill the firmware in ATmega32u4, I briefly closed 2 ICSP pins, then used Flip . Later connected to these pins button.



The firmware works, it remains to fasten the walls and the front panel. As I marked everything in place, it took more time to draw the panel than on everything else. It looked like this:

The panel is made of millimeter PET, covered with film with a print and lamination, the holes were cut with a laser on the cdr file. Irkutsk advertisers cost me only 240 rubles.



The side walls cut out of plywood.

View of the device at the moment:





Cost of components:

Total: 1025 rubles.

The controller copes with the tasks assigned to it and steers the sound in almost any audio processing program.

Plans to cover plywood with stain and cut the bottom cover from plexiglass. Also add an expansion port for connecting a floor controller.

Code for Arduino and signet on github: https://github.com/vlr-baik/MyMidi

Materials on the topic


Source: https://habr.com/ru/post/257717/


All Articles