DIY outdoor midi controller. Dynamic MIDI keyboard on PIC16F84

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 the Guitar Rig Kontrol 3, cost about 13,000 rubles, and only have floor-standing performance. That is, it is very problematic to quickly change the positions of several regulators.

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

Initial requirements: 2-7 faders, the same number of rotary potentiometers / encoders, about 10 buttons, USB connection.

Then I began to select components. I chose Arduino because of its availability, in principle, you can use the same ATmega32u4, STM, or another controller. Found faders and buttons at your local radio store. The encoder and potentiometers have already been purchased. Found tumblers in the garage. I decided to make the case from the top cover of the DVD player.

Components:

  • Arduino UNO R3 1 pc.
  • Faders sp3-25a 5 pcs.
  • Mouth. potentiometers 3 pcs.
  • Encoder 1 pc.
  • Push buttons pbs-26b 16 pcs.
  • DVD cover 1 pc.
  • Toggle switches 2pcs.

First, I bent the body and sawed through the holes for the faders with a drill:

Then I drilled holes for toggle switches and a mouth. potentiometers, marked the position of the buttons. Since I did not have a drill for 19 (and the corresponding chuck for a drill), I drilled the holes for the buttons by 13 and then increased it with a sweep.

The base is ready, now you can think about 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, which makes it a USB-HID MIDI device. All we have to do is send MIDI data over the UART at 31250 baud. In order not to clutter up the source code with definitions 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.
Shield diagram:

As you can see from the diagram, the buttons are connected according to the matrix scheme. The built-in pull-up resistors of the ATmega328 are used, so the logic is inverse.

Button initialization

for (byte i \u003d 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 \u003d 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 them to the buttons.

The potentiometers are connected via a 4052b multiplexer to the ADC inputs.

Reading potentiometer positions

for (byte chn \u003d 0; chn< 4; chn++) //-Цикл чтения значений потенциометров { set_mp_chn(chn); //--Задаём параметры мультиплексора val=analogRead(0) / 8; //--Считываем значение с канала X if (abs(val-PrVal) > 5) // - If the current value is ex. from the past (// - more than 5, then send a new value MIDI.sendControlChange (chn, val, 1); PrVal \u003d val;) val \u003d analogRead (1) / 8; // - Read the value from channel Y in the same way as X if (abs (val-PrVal)\u003e 5) (MIDI.sendControlChange (chn + 4, val, 1); PrVal \u003d val;))


The encoder is hung up on a hardware interrupt.

Encoder reading

void enc () // Processing the encoder (currenttime \u003d millis (); if (abs (ltime-currenttime)\u003e 50) // anti-bounce (b \u003d digitalRead (4); if (b \u003d\u003d HIGH && eval<=122) eval=eval+5; else if (b == LOW && eval>\u003d 5) eval \u003d eval-5; MIDI.sendControlChange (9, eval, 1); ltime \u003d millis (); ))


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

Finished shield:



To upload the firmware to the ATmega32u4, I briefly short-circuited 2 ICSP pins, then used Flip. Later I connected a button to these pins.

The firmware is working, it remains to screw the walls and the front panel. Since I laid out everything in place, it took more time to draw the bar than everything else. It looked like this:

  • 1. Graph paper was set as the background of the picture
  • 2. Holes were marked
  • 3. Received was printed
  • 4. All holes were cut
  • 5. All elements were unscrewed and removed
  • 6. The panel was installed, all buttons / potentiometers were installed in place
  • 7. There were inconsistencies between the template and the body
  • 8. Go to step 2 until all holes match
The panel is made of millimeter PET, printed and laminated with a film, laser cut holes using a cdr file. All this from Irkutsk advertisers cost me only 240 rubles.

Sawed out the side walls from plywood.

Current device view:

Component cost:

  • Arduino UNO R3 320 р.
  • Faders sp3-25a 5x9 \u003d 45 p.
  • Mouth. potentiometers + knobs 85 r.
  • Encoder 15 p.
  • Buttons pbs-26b 16x19 \u003d 304 p.
  • Panel 240 r.
  • Multiplexer 16 r.
  • Plywood, textolite, toggle switch, DVD case - in my case for free.
Total: 1025 rubles.

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

There are plans to cover the plywood with stain and cut the bottom cover out of the plexiglass. Also add an expansion port for connecting a floor controller.

Arduino code and github seal.

Basically, the article is designed for guitarists and others like them, since few people need a foot controller, turn on the additional keyboard, bind the keys and go. Although this control may be quite appropriate for DJs. But it works best for Guitar Rig and TH1. In general, today we will collect something similar to:

And so, first you need to collect the necessary parts. Here is a small list of them:

Housing. The first and most basic thing is that it is difficult to find the right one. I bought a cue case for this case.
- USB keyboard, preferably not very old, because wiring may not work.
- Keys (the ones I picked up): PBS-16B (FEET), SPA-101B4 (DOPs), PBS-15B push ON (ON). All without fixation. You can buy it in Chip and Deep.
- Wires. Many single cores. I think twisted pair is best for this. 2 meters behind the eyes. Only unwinding is inconvenient.
- Well, I think almost everyone has a soldering iron who has decided to assemble this device.
- Tools for making holes in the housing. Someone is much more, you can even use a self-tapping screw, and then rule with a knife, but again I think everyone has a drill.

Well, let's get started. The first thing to do is to outline and drill holes in the case:

Now let's get down to the more harmful part of making our footswitch. We solder the wires in accordance with the diagram, do not forget to hang identification sheets with the numbers of the inputs at the entrance from the keyboard:

You should end up with something like this:

Now the very jewelry process of soldering to the controller from the USB keyboard will begin. Note that if you are lucky enough to buy / find / take away a keyboard with such a controller as in the diagram attached above, then you cannot do without a soldering station. You can attach the board to the case with almost any improvised means, liquid nails, self-tapping screws, superglue, silicone, and in general, if you don’t wake up too much, then it keeps on like that, but depends on the case, the twisted pair tightly presses the board.

We make cosmetic improvements, whoever wants to, solder a diode to the case from NUB LOCK "and ... He will make a hole for the wire and rewire the USB cable. Well, there will be enough imagination for that. The end result:

Phase 2. Configuring the software. I hope this will not be a problem for everyone who has made this device. For Guitar Rig, everything is easier than ever, turn on the NUM Lock, turn on the rig, open OPTIONS - CONTROLLER, press MENU, look for the required action, kick the Learn key and select the appropriate button on our controller. Then click on Add Controller and carry out the same operations again. And so on until we type everything that is needed or the keys run out. You can also assign a key to almost any action in the 3rd rig, right-click on the object and click on Learn again.

But now, if you are interested in setting up all this brainchild for the Midi team, you will have to have a little more fun.
So we need software that binds keys to midi commands. And there is such a program, although I have not met any analogues, since there is no need to treat greed. It is called the Virtual Midi Controller, the key action is configured in the C IN tab, installation - Setup - Next - Next. Here's a link .


Together with it, a virtual MIDI cable is also installed, so you don't have to make unnecessary gestures. For the very lazy, I spread the bank preset for the footswitch: bank - they should replace the file in the root of the program folder, by default C: \\ Program Files \\ Virtual Midi Controller \\, after exiting VMC. For convenience, check the Run In Background checkbox in SETUP and poke the letter K in the main VMC window, after which the program will receive commands in minimized mode. Now, to exit the program, you need to eliminate it in the tray. And from now on you can control both Nuendo and Sonar from the footswitch. And of course TH1 also grabs our keyboard through the midi.

If you have any questions, please contact ...

Next planned projects:
- Guitar shielding.
- DIY combo.

I wish you success in your musical activity ...

A MIDI controller is a device that converts a specific physical process into a set of digital MIDI commands. A physical process can be anything from pressing a key with your finger to turning the volume knob. The received command stream is transmitted via the MIDI protocol to other devices - a computer, hardware samplers, synthesizers or external sequencers and decoded there in a certain way. The most common type of MIDI controller is the MIDI keyboard, which is the electronic counterpart of a piano keyboard. There are also many other types of controllers, including electronic drum kits.

On the modern market there is a huge number of various MIDI controllers for electronic installations, differing in all sorts of criteria, such as price, quality, technical characteristics, etc. There are also several finished user devices that are implemented as commercial projects (eDrum, megaDrum). But, despite all this, the desire to create such a device with our own hands still lives in the minds of the modern Kulibins.

So, several years ago, with a slight delay, I fired up the creation of such a device, since I took part in a musical group of a heavy direction. We played hard rock, or rather something like brutaldeath, goregrind, grindcore. I played electric guitar. Earlier we bought a Sonor drum kit and made noise in the garage in the evenings. Later, they asked us from the garage, and the question arose about the premises. Not finding anything worthwhile, we decided to rehearse at home, which immediately led to a conflict with our neighbors. Here the question arose about electronic drums.

In parallel with playing live instruments, I was writing electronic music and using VST instruments and plug-ins, in particular, for creating drums, I preferred Addictive drums and ezDrums, which have the ability to work with a MIDI interface. Without even googling this topic, I plunged headlong into the development of my own MIDI controller on an affordable ATMega32 microcontroller in a DIP package, which had 8 ADC channels on board. I didn't want to fence the circuit, and I decided to limit myself to 8 inputs. Since the ATMega32 does not have a hardware usb, I used a standard connection to a computer via virtual usb. After fiddling with programming for several days, I managed to start the device. Imagine my surprise when on the Internet I found a ready-made device with a circuit and firmware (MegaDrum). But everything that is not done is for the best.


Full USB

By profession I am a programmer, but by occupation I am an electronic programmer, a candidate of technical sciences, and as my former scientific supervisor used to say - a Swiss, and a reaper, and a dude on a pipe. As is often the case, I got hung up on AVRs, not because I had feelings for them, but because they were completely satisfied with their technical characteristics at work. But the time came when they began to be missed. And then stm32 came to replace, among other things, having a full-fledged usb interface on board. It was then that the idea came to make a full-fledged MIDI controller. In addition, I already had experience with the MIDI interface.

Where to begin? We didn't have stm32 in DIP packages (if they exist at all), so the idea to solder on the circuit board immediately disappeared. It was then that cheap debug boards based on stm32 microcontrollers, such as DISCOVERY, began to appear. And now I am the happy owner of the STM32F407DISCOVERY debug board, which also includes an ST-Link programmer. The STM32F407 processor has 16 ADC channels, although 4 channels are occupied for peripherals, which are simply stuffed with a debug board. But for my purposes 12 channels were enough.


After spending some time studying the Keil programming environment, the STM32F407 microprocessor architecture, as well as standard peripheral libraries for working with USB, I put in a program for polling all ADC channels using a direct memory access channel, as well as a composite USB device that includes MIDI Audio Device and HID to change device settings.

As sensors for the drums, I used the ZP-1 piezo bell, which could be bought in a store for a low price.


I took the strapping scheme from MegaDrum.


I wrote the control program in Delphi with a margin of 16 channels. In principle, the number of channels of the device can be increased to infinity, by supplementing the circuit with analog multiplexers, as is done in Megadrum, but 16 channels are enough for our purposes, since we are not such advanced musicians. And for a beginner drummer, that many drums will be just for the eyes.


The device has been tested on both Windows and Linux using the Renoise tracker. No special problems were found in the work.
But I decided not to dwell on this result. The STM32F407 is a pretty sophisticated processor, so it's relatively expensive. It was cheaper to make a device based on STM32F103. Ebay came to the rescue. I bought a debug board with STM32F103RBT6 on board.


True, it does not include a built-in programmer. I was lucky, since I still have the ST-Link programmer from my previous work.


I had to completely rewrite the firmware, since the operating principles of 407 and 103 processors, although not radically, are different.
Then I came across a debug board on the Internet, which cost a penny at all, and decided that in this way it was possible to reduce the cost of components to a minimum.

I have long wanted to wake up the composer in myself and start creating my own electronic music. However, I was (to say the least) discouraged by the high prices for MIDI controllers. But after looking around the Internet, I got the idea to create my own controller, using Arduino Uno and conductive paints for this!

Let's start)

Step 1: selection of parts

You can slightly move away from the material described and the MIDI controller you have assembled will still work (by "slightly move away" I mean that you can install a resistor with a slightly different value or leave one of the pins disconnected).

From electronics we need:

  • 1 Arduino Uno with usb cable;

  • 1 can of conductive paint;

  • 1 mounting plate 5 × 7 cm;

  • 3 buttons;

  • resistors with a resistance of 2.2 kOhm;

  • 1 LED;

  • resistors with a resistance of 10 kOhm;

  • 1 LDR sensor;

  • resistors with a resistance of 4.7kOhm;

  • 1 jumper;

  • 12 pcs 2.7 MΩ resistors;

  • 30 straight pins;

  • 12 bent pins;

  • 12 adapters;

  • 12 paper clips.

In addition to electronics, the following tools are also required:

  • Soldering iron and solder;
  • Nippers;
  • Soldering stand (third hand);
  • Multimeter;
  • Multiple wires and / or thin metal wire.

Step 2: solder the pins

Let's start creating the board by soldering the pins. We will place bent pins in the center of the first row on the board. They will subsequently serve as "sensitive" outputs to which the keyboard will be connected.

After installing the pins, notice that the short leads are sticking out of the board. We press on them so that everything goes flush. Now we solder them and immediately check the connections for a short circuit.

Note: Do not solder the pins for too long, or they will heat up and melt the plastic.

For the next stage, we will place straight combs in slots Arduino... Place the board on top of the pins that are inserted into the Arduino. This action required little force as the pins are not perfectly aligned with the board holes.

After successfully positioning the board on the pins, make sure the pins are flush with the top edge of the board. Then they can be soldered.

Step 3: solder the jumpers

Now remove the Arduino board and flip it over. We will solder the jumpers to which the components will be attached in the future. There are two ways to do this:

  • Fill all the necessary holes with solder, and then connect them to each other.
  • Use thin wire.

I advise you to use the second method as it is easier and faster. If you choose this method, position the wire on the board as shown.

  • The red dot means - we solder the wire into the hole.
  • Yellow dot - connect a thin wire to a pin on the other side of the board (as in the third image).

As you can see, I messed up the bottom left corner a bit when I applied too much solder, so watch out!

Tip: If you do not have thin wire, use the cutoffs of the leads of the resistors used.

Step 4: solder the sensor-capacitive resistors

We install the components, namely 2.7 resistorsthat will perform sensory-capacitive functions.

Note: If you want to know more about the theoretical background and practical application of capacitive touch sensors, I suggest you check out the following links:

Let's arrange one 2.7 resistorfrom the bottom of the rightmost bent pin and push the legs through the holes (as in the first image). Now turn the board over and push one lead of the resistor back into the next hole (as shown in the second image). Solder the lower leg of the resistor to the hole and the upper leg of the resistor to the pin. Then attach 7 cm wireonto this pin (as seen in the third image).

Let's repeat the process with all the resistors and wires, soldering them in place. The bottom legs of the resistors should form one long connection.

Advice: Choose alternating colors for the wires - this will make it easier to connect in the following steps.

Step 5: soldering the buttons

Let's start by placing the buttons and resistors on the board like in the first and second images. In my case, I used 2.2 kΩ resistors, but any resistor with a value between 2kΩ and 10kΩ can be used.

Let's turn the board over and solder everything into place. Image 3 explains what different connections you will need to make:

  • blue dot - denotes a button leg that needs to be soldered to the board;
  • pink dot - denotes the resistor leg, which must be soldered to the board;
  • red line means - you should solder two points into one connection;
  • the black line denotes a wire that will run from one leg of the button through a hole in the board, which then connects to the pin on the other side.

If everything is wired correctly, the two left-most buttons will allow octave changes., while the rightmost button will enableLDR sensor.

Step 6: solder the LDR and LED

After the buttons are soldered, we continue with the installation of LDR, LED and corresponding resistors. Before doing this, it is wise to experiment with the resistor values \u200b\u200bthat will go to the LED. Perhaps my denomination is too high to turn on your LED. Experiment a bit to find the correct resistor value.

Tip: Any resistor between 330Ohm and 5kOhm would be a good solution for 5mmLED.

Now let's place LED, LDR and resistors ( 4.7 K forLDR) in the right places. Let's turn the board over and solder everything. The third picture will explain what the different connections should be made:

  • brown dots - LDR pins, which should be soldered to the board;
  • pink dot - resistor leg, which should be soldered to the board;
  • orange dots - LED leads, which must be soldered to the board;
  • red stripe - you need to solder two points into one connection;
  • the black stripe is the wire that will go from the resistor output through the board hole, which will then be connected to the pin.

Note: Before soldering the LED, make sure the polarity of the LED is correct. The positive lead of the LED should be connected to a resistor and the negative lead to ground.

Step 7: test all connections

Now is a good time to test if the connections of the buttons, LDR and LED are successfully soldered. This is the last opportunity to fix bugs, I advise you to download the attached code and run the program. and download Arduino_Test_Fixture_Code to the Arduino board.

If everything goes well and the test is complete, you can move on to the next step. If not, double-check the soldered connections on the board. It is better to keep a multimeter at hand, I say this from my own bitter experience.

Step 8: finishing work with the board

Let's start by mounting the wires into the holes as seen in the first image. It is convenient to use two wires of different colors in this step.

Flip the board over and cut the wires to the desired length. We solder them to the pins that go into the Arduino connectors. Before you start using MIDI controller, first you need to test its connections with a test sketch. Upload your sketch, open the serial port and touch the sensing pins on the board. If you see the text 'Note x is active' for each pin while touching, all pins are working correctly.

Step 9: Convert Arduino to MIDI Device

Once the board is ready, it's time to convert the Arduino to a MIDI controller that will be recognized by music programs like Ableton and Fl Studio or even other MIDI devices. The process consists of two steps:

  1. Change the current firmware on the Arduino Uno to MIDI compatible programs;
  2. Upload your MIDI sketch to Arduino.

Let's start with the first point. By condition loaded into Arduino firmwareusb serial portwhich allows the Arduino to communicate with the PC and the Arduino IDE. With a new program DualMoco, a second mode will be added, which will allow the Arduino to act as MIDI devices.

We will use the FLIP program and follow the instructions to change the Arduino firmware. You will find a working file in the archive in the Firmware folder - the DualMoco.hex file.

After uploading new firmware, reconnect Arduino to PC. If all goes well, the Arduino should not be detected by the Arduino IDE because the new program is in ( MIDImode). Open a music program that is capable of recording MIDI and check that the Arduino is named MIDI/ MOCOforLUFAwas displayed above the MIDI settings, as you can see in the 1st image.

Step 10: making the final preparations

Feature DualMocothat she has a second mode - usb serial port, which allows you to download sketches from the Arduino IDE, just like with normal firmware. To put the Arduino in the second mode, connect the two ISCP pins together as shown in image 1 and 2. You can either use a piece of wire or a small jumper as shown in the images. Now unplug the USB cable from the Arduino for a few seconds and reconnect it, the Arduino should show up in the Arduino IDE.

Note: When you want to switch fromusb-serial port inMIDI mode, remove the jumper fromISCP pins as shown in the third image and reconnectArduino to PC.

It's time to upload a valid sketch to the Arduino, Arduino_Final_Code... Download it, translate Arduino to usbserial port mode and load the code. If you need to fine tune the threshold, experiment with the values THRESHOLD and RES ... After everything works as expected, change the current line 17, from:

boolean midiMode \u003d false; // if midiMode \u003d false, the Arduino will act as a usb-to-serial device

boolean midiMode \u003d true; // if midiMode \u003d true, the Arduino will act as a native MIDI device.

After making the final changes to the code, it's time to test your music program that can support MIDI devices. First, let's put the Arduino into MIDI mode, for this:

  1. Let's upload the final code to Arduino.
  2. Let's take out the USB cable from the Arduino.
  3. Switch the Arduino to MIDI mode by removing the jumper from the ISCP pins.
  4. Install the USB cable into the Arduino.

If everything went well, open the music program and start touching the pins. Magic sounds should sound….

Step 11: solder the paper clips onto the jumpers

After the Arduino board is completely finished, it's time to focus on the keyboard and how to connect it to the board. There are millions of options to do this, but I chose staples that will be fixed to colored paper (they are easy to fasten and can be reused).

The process of soldering paper clips to wires is pretty simple:

  1. Cut off the plug on one side of the wire;
  2. We strip the wire from insulation by 5 mm;
  3. We solder the stripped wire to a paper clip;
  4. Repeat for all 12 staples.

Note: Staples should not be covered with any coating (paint or plastic).

Step 12: paint over the template

While you can only play the Arduino MIDI keyboard by touching paper clips, it's much more fun to make your own stencil and use it. Colored the printed template. The template is in the archive with projects.

Coloring the template is pretty easy, just make sure to leave some space between the lines and use the correct paint, otherwise nothing will work. After the paint is dry, attach paper clips to the "keys" and you can start making music.

Thanks for attention!)