DIY USB Midi Controller With Arduino: a Beginner's Guide

by dolcewang in Circuits > Arduino

72234 Views, 272 Favorites, 0 Comments

DIY USB Midi Controller With Arduino: a Beginner's Guide

DIY MIDI Controller [Ableton Demo]

I love MIDI Controllers! They are some of the coolest yet most powerful devices for controlling mixed media - traditionally used to connect to music software (like Ableton Live) to play virtual instruments as well as control effects - but can also be used with VJ software (like Resolume), and even lighting control programs (like Lightjams)!

If you haven't already, check out the above video to see the finished DIY MIDI controller in action with Ableton! ☝️☝️ And as a bonus, here's me VJ'ing using the controller.

The exercise of completing this project helped me to gain the skills to grow from a Novice Tinkerer to at least an Intermediate one. It really got my feet wet in the world of Arduino, electronics, and even some product design. I hope that it would do the same for you!

This project is great for anyone who…

  • … wants to understand what's under the hood for MIDI Controllers
  • … is getting started with Arduino, and looking for a fun project to grow your skills
  • … is on a budget, but still want to build a cool piece of gear (MIDI Controllers can be pretty expensive)
  • … wants to learn more about electronics
  • … would like to learn how to customize your own MIDI Controller layout
  • … is curious about how electronics can make music, effect video, etc...
  • … simply loves MIDI Controllers as much as I do!

So let’s dive in!

Setup

153DE4E2-5E7A-46F9-96FC-065BDEA24A37.JPG
Dolces Choice of Arduino.png

I've broken down the process into several smaller steps below - mostly so that I could also provide more photos and video to fit the Instructables layout.

But firstly, I wanted to just say that building the MIDI Controller comes down to 3 basic categories:

  1. The Enclosure
  2. The Circuit
  3. The Code

Some of you will have strengths in certain categories more than others, so feel free to skip around based on your goals. However, I will be writing this tutorial to an audience who may only have a basic tinkering knowledge of each one, but hopes to grow just as I did!

--

Secondly, it's always a good idea to prototype first. I won't detail all the steps for prototyping to save redundancy, but in reality, I did several prototypes with a breadboard before actually putting it together. This helped me to understand the Circuit and Coding better because those were my areas of weakness. In fact, I started off with a 2 Button, 1 Knob, 1 Fader prototype and worked my way up!

--

Lastly, which Arduino should you choose??

With the wealth of options out there, it can get overwhelming. After testing and analyzing several different Arduinos, I finally decided on the Pro Micro (designed by Spark Fun) for the following reasons:

  • It uses the atmega32u4 microcontroller (Pro Micro, Micro, Leonardo…), which allows for:
    • Easier Programming - right out of the box, it is set up as an “HID device” aka USB keyboard
    • I wanted to use USB for communication rather than the old-school 5-pin MIDI jack, which is the standard setup for UNO and other boards using the atmega328p processor (like Mega, Nano, Bluno…)
    • After you upload your Arduino sketch (the code) to your board, it works right away!
    • The UNO and other atmega328p boards can work through USB via Serial communication... but that means either 2 extra programs are running in the background to translate these different digital languages, which adds more room for error while eating up a bit of your CPU 🙁
      • ...OR you can hack the board, but that method seems even more trouble than it’s worth to even type out. 🙁🙁
  • The Pro Micro is still cheaper than the other options, even with the better microcontroller
  • The size is super compact
  • The number of Analog / Digital pins still suited my design requirements, even while being tiny!
  • I would actually have preferred the Arduino Micro (also atmega32u4), but it’s slightly larger and I didn’t need all the extra pins

For a more thorough comparison of boards, you can check out this link.

With all that said, most beginners use the Arduino UNO for learning, and don’t have access to other boards - so I will add a few notes on how to get the UNO working as well. Although I don’t recommend it for the final product, it is certainly adequate for prototyping and you don’t need to squint as much!

Ok, so now let’s scavenge for some supplies...

Stuff You Will Need

IMG_7293.PNG
IMG_7163.JPG
IMG_7118.JPG
IMG_7147.JPG

Luckily, the Required tools and materials actually needed for this project are pretty basic! However, there are several recommended Optional items that would make your life much easier if you happen to have or want to add your collection.

Also, I found a lot of materials in mom & pop electronics stands while being stranded in Taiwan due to COVID-19 (that is a whole other story!), or at the dollar store. I tried my best to find equivalent Amazon links appropriate items, but please note that I used whatever I could find since there’s no Amazon here. Feel free to adapt as well!

SUPPLIES

TOOLS

Enclosure - Design and Prep

DolceWangLayout_ISO.jpg
2338158B-370B-4D28-9D07-FC86941CE943.JPG
IMG_7131.JPG
IMG_7333.JPG
DolceWangLayout_TOP.jpg
IMG_7137.JPG
LayoutMeasurement_GIF_480.gif

Designing how you want to lay out all your components in advance will save you a ton of headache later on when trying to fit everything into a small Enclosure.

As a prelude to the CAD drawing, I prepped the box with wood stain so I could do the design while it was drying. Water-based stain is really nice so that it doesn't overwhelm you with fumes (unless you like that sort of thing), and it is easier on the skin. Brushing lightly and giving it 2 coats did the trick. Then I let it dry for 24 hours.

Ok, back to the layout!

Here are the steps I took for Design and Prep:

  1. Simply place all the components on the box just to give a visual sense of spacing. You can then roughly measure their locations with a ruler to give you a starting point.
  2. Measure some more! This time with more accuracy. The two main purposes are:
    1. Figure out what size holes you need to cut (Measure all the barrels of the Knobs, Buttons, and LED; and also the Fader slots)
    2. Determine if you can fit everything inside (Measure the outer dimensions of all the components as well as the Pro Micro)
  3. Draw!
    1. I used Sketchup to do my layout, but you can easily use Paint or other software... or better yet, draw it by hand!
    2. Again the two most important views are the Overall Layout (how it all fits), as well as the Cut Holes (where to drill/cut into the box)
  4. Get it on paper to create a pattern ✏️
    1. If you already drew it by hand, awesome! If you did a digital sketch, you can either print it to scale... or be lazy like me and zoom in to scale, then trace the center points of each hole directly on my monitor.
      1. Note: For the Faders, I planned to drill a small hole on the top and bottom of each slot as well, so I only had to mark those center points
    2. Then I did a quick sketch of the hole outlines and wrote in the dimensions
  5. Cut out the pattern, tape it to the top of your enclosure, and then push through each of the center points with a pointy object (in my case, I used tweezers). This will easily mark the placement of where you need to drill directly onto the box!

As a shortcut or reference, you can also download a PDF of my Cut Holes layout from this Instructable. My box was 14x14cm with a 5mm wall. If you have a different sized enclosure, you can do the scale and trace trick according to your dimensions since you only really need the center points. Just make sure everything still fits and that you still write down the hole diameter sizes.

Now on to the drilling!

--

Note: For UNO users, you will be limited to 6 Potentiometers (combination of Knobs and Faders) because the UNO only has 6 Analog pins. Definitely keep this in mind as you design, and especially before you start to drilling... otherwise you will have some gaping holes! Buttons are ok since they use Digital pins. If you are using a different board, double check the number of Analog / Digital pins as well to see your limitations. Here is the pinout diagram for the UNO.

Enclosure - Make Some Holes!

Drill Holes_real_GIF_580.gif
Drilling Pilot Holes.jpg
IMG_7150.JPG
nick.JPG
Drill Holes_Faders_GIF_580.gif
IMG_7169.JPG
Cut hole for USB.png
USB Slot DIagram.png

Hope you are ready to do some damage... but very carefully of course. 😉

  1. The Holes
    1. After using your nifty pattern to locate each center point of the holes, you can use a small drill bit to make pilot holes. I used a 2mm drill bit. This helps to prevent much fraying when using a larger drill bit.
    2. You have some room for error with the holes because the Knobs, Buttons, and LED all have mounting screws that will hide a little of your edge if it's not perfect
    3. When making the larger holes, I used a step drill bit for the same reasons. You can also work your way up to the appropriate diameter
    4. It's important to drill from the top of the Enclosure because the back end will have more fraying after you drill through. That's why we traced the pattern from the top as well.
  2. The Slots
    1. Cutting Fader Slots requires much more precision because the edges will be exposed
    2. My fader slots measured out to be 3mm wide so I used a 3mm drill bit
    3. I then used an X-Acto knife and Metal Ruler to carve out the slots along the tangent of the holes. The thickness of the wood was only 1mm so this worked out great
    4. If you have a thicker piece of wood, then you could be really careful with the hacksaw -- or if you have access to a lasercutter, then you are golden!
  3. USB Hole
    1. You can use the same method of making the Fader Slots to make the USB hole for the Pro Micro - use the 3mm drill bit and X-Acto Knife method.
    2. One tricky thing though, is that the USB port probably won't be long enough to reach the USB cable head on the other side. You could make a larger hole to fit the entire head, but then it would expose the inside of the Enclosure if the cable wasn't plugged in.
    3. Instead, I roughly carved out a slot from the inside, so that the Pro Micro could be pushed into the Enclosure wall, just enough to reach the USB plug.
    4. Definitely check out the photos, as it will illustrate this better!
  4. Sand all the edges
    1. If you cut a small piece of course sandpaper (I used P220) and roll it up, it works really well to get these edges nice and smooth
  5. Touch it up
    1. You can touch up the edges using a small paint brush and wood stain, or even a brown permanent marker if the tone matches
    2. You only need to touch up the fader slots, but I did the holes as well because... why not?
  6. Test the size
    1. Insert one of the components (like a Knob) to check the sizing. If all the steps were taken carefully, it should fit like a glove!

Enclosure - Assembly

Assembly_Draw_GIF_480.gif
10F7D4CE-987B-4D3A-A645-04CDBC63AF65.JPG
baby jenga.JPG
cut wood.png
wood bits.png
IMG_7172.JPG
snaps.png
4B37B238-E77C-494F-8189-1ED529841F04.JPG
Assembly_Mount_GIF_480.gif
IMG_7335.jpg
Rubber Feet.png

Ready to place everything in? Here are some guidelines:

  1. It was helpful to draw the components on the inside of the box to remind myself of where everything should go
  2. Mounting the Knobs, Buttons and LED were very simple because they just use hex screws. Nothing like a good Monkey Wrench to get them nice and tight. Just make sure they are the correct orientation!
    1. I added wooden blocks to either side of the Knobs to keep them from rotating if they got loose.
  3. Fader Mounting was the hardest because I was trying to make the design so that it could also be disassembled
    1. If you don't mind the permanence, you can simply hot glue the faders on!
    2. If you want more flexibility in the future, or just like a challenge, you can easily make some shims with scrap wood and I even used old SIM cards for more precision
    3. Pro Tip: I found a fake baby Jenga set at the dollar store, and have used these wooden pieces for many DIY projects. In this case, I cut them into small blocks with a clamp and hacksaw.
    4. Normal white glue worked well for the wood pieces and SIM cards to lock down the placement of the Faders.
    5. In order to keep it secure from behind, I used small screws and brackets that I found laying around. You can totally be flexible here on the method - just make sure that both the top and bottom are even secure. If they are metallic, it is also a good idea to wrap it in electrical tape or heat shrink tubing for insulation.
  4. Snapping Feature
    1. The wooden blocks also work very well to snap the Top and Bottom halves of the Enclosure in place. Since they are glued flush against the inner perimeter of the box, it keeps the two halves nice and snug. Four of the previously glued pieces used to secure the Knobs and Faders already double as snapping blocks as well (2 on both Left and Right sides)
    2. Then on the Bottom half of the Enclosure, I added a single piece on both the top and bottom edges (see photo)
    3. You can round off the corners of these blocks so that the halves can align more easily
  5. Pro Micro Mounting
    1. Stick some velcro on the back of the Pro Micro as well as its designated area in the Enclosure!
    2. I added a wooden block to secure it into place so it wouldn't get pushed in when the USB cable was plugged in. To make it detachable, I filed out a small rounded groove so that it could also be snapped out of the case as well (see photo)
  6. Add some Rubber Feet!

Now it's time to get a snack before we move on... to... the... Circuit!!

Circuit - Wire It Up!

Dolce MIDI Controller Circuit Diagrams.001.jpeg
Dolce MIDI Controller Circuit Diagrams.003.jpg
Dolce MIDI Controller Circuit Diagrams.002.jpg
Dolce MIDI Controller Circuit Diagrams.004.jpg
Dolce MIDI Controller Circuit Diagrams.005.jpg
HeaderPinSoldering_GIF_420.gif
IMG_7180.JPG
IMG_7203.jpg
AddPotCaps_640.gif

Since I personally get dizzy looking at electrical diagrams, I made several of my own visual diagrams to help break up the wiring process into bite-sized chunks. Please take a look at them, as I think the visuals provide a clearer map to the wiring strategy - better than I could do in writing.

I will also start calling Knobs and Faders: "Pots” (aka Potentiometers). For electronics and coding, they behave the same way, so they have this fancy name.

If you weren't confident in soldering before, this will definitely get you up to snuff!

Here are some helpful tips for this process:

  1. Pro Micro Header Pins
    1. You could solder directly to the board without header pins if you are confident that this Pro Micro will be dedicated to your controller. It can also save space in your Enclosure.
    2. If you want flexibility, solder the header pins onto the side that has all the electronics (usually they are soldered to the other side with pins going down underneath so that you can use it with a breadboard)
      1. Stick the longer end of the header pins into a breadboard
      2. Place the Pro Micro upside down (electronics facing down)
      3. Solder the corners first
      4. Then solder the rest of the pins
  2. Wiring
    1. Follow the visual diagrams to map out your circuit
    2. Start with the Ground (black wire) - what's cool is they can be daisy-chained
    3. Next solder the +5V Power (red wire) - these can also be daisy-chained!
    4. Solder all the Signal wires last - they go directly to your Arduino
      1. Pots go to Analog Pins
      2. Buttons go to Digital Pins
      3. Usually, colors follow the rainbow or from lightest to darkest
    5. Leave some slack so they can be reorganized
    6. It's a good idea to use heat shrink tubing at the soldered joints to prevent shorting out. They can shrink from the heat of your soldering iron.
    7. I used colored jumper wires so I could connect to the header pins easily. Unfortunately, the bare wires inside have a stranded core (hairy), which breaks much easier when soldered. I ended up shortening the wires to length so that they still had female and male tips, and making a loop with the male tip to solder to the components
  3. LED
    1. Don't forget the 330 Ohm Resistor so your LED doesn't burn out! Add to the side of the long leg
    2. Short leg goes to Ground
    3. Long leg goes to Power
  4. Make Your Life Easier With...
    1. Soldering Flux Paste - add a glob with a toothpick, apply it to the joint, get some solder on your iron, and wipe the solder on the flux. It will absorb the solder so you only need one hand!
    2. Helping Hands. Enough said.
  5. Fitting into the Enclosure
    1. If you use header pins, they may be too long for the Enclosure to fit tightly. I bent the pins on one side of the Pro Micro at a 45 degree angle and it worked great!
    2. If you are using jumper wires, you also may need to cut some of the back ends of the plastic female tip to fit better.
  6. Close the Enclosure
    1. Close the two halves and listen to that baby snap in place!
  7. Add the Knob and Fader Caps
    1. Ok, this is not part of the circuit, but better to add them afterward to avoid scratching
  8. Moment of Truth
    1. Plug in your USB cable and see if your LED lights up. If it does, that's a GREAT sign!

Can you believe it? Your MIDI Controller is nearly complete!!

--

Note: For UNO users, Pots will go to Analog Pins A0-A5

Coding

UploadingSketch_GIF_640.gif
Screen Shot 2021-03-29 at 3.39.17 AM.png
Screen Shot 2021-03-29 at 3.27.07 AM.png
Screen Shot 2021-03-29 at 3.13.14 AM.png
Screen Shot 2021-03-29 at 3.13.27 AM.png
Screen Shot 2021-03-29 at 3.13.45 AM.png
Screen Shot 2021-03-29 at 4.03.17 AM.png
Screen Shot 2021-03-29 at 4.03.26 AM.png
Screen Shot 2021-03-29 at 3.11.48 AM.png

Get ready to complete your MIDI Controller!

Fortunately, you won't have to do much programming since I already created the sketch for you! In the best case scenario, you would just need to download the attached file (use the one that says "Atmega32u4" in the name) as well as the MIDIUSB.h library... and you are good to go!

I would like to thank Gustavo Silveira (aka Music Nerd), as the sketch is heavily modified from his version.

If you are new the Arduino environment, then follow these guidelines:

  1. Make sure you have installed the Arduino IDE to upload sketches (code) to your Arduino
  2. Download and Open the sketch I provided: "midi_controller_Micro_Atmega32u4_DW_v2.ino" and Save it to the proper location on your computer
  3. Add the Pro Micro board to your listGo to Arduino < Preferences... (File < Preferences... for PC)
  4. Paste this URL to the Additional Boards Manager URLs text field "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json"
  5. Add the MIDIUSB.h LibraryGo to Tools < Manage Libraries...
  6. Search for "MIDIUSB" by Gary Grewal
  7. Install the latest version
  8. Assign the Pro Micro boardGo to Tools < Boards < Sparkfun AVR Boards... Select Sparkfun Pro Micro
  9. Go to Tools < Processor... Select ATmega32U4 (5V, 16 MHz) -- **Make sure you select the correct voltage, otherwise you will need to reset your Pro Micro
  10. Go to Tools < Port... Select the correct port (mine says /dev/cu.usbmodemMID1, PC will probably say COM)
  11. Click Upload (the Arrow on the top Left corner)
  12. Wait until the bottom status bar shows Upload Complete!

CONGRATULATIONS! YOU MADE IT!!! 🎉🎉🎉🎉🎉

---

If you feel courageous 💪 you can also start changing parameters in the Code, such as Number of Buttons / Pots, Digital / Analog Pin assignments, and even MIDI Notes! (See photos)

---

Note: For UNO and other atmega328 users (Nano, Mega, Beetle...), follow the remaining steps by scrolling down to the Appendix 👇👇👇

Bonus: Map to Ableton and Resolume!

AbletonMidiMapping_GIF_640.gif
Resolume Midi mapping_GIF_640.gif
Screen Shot 2021-03-29 at 4.16.48 AM.png
Screen Shot 2021-03-29 at 1.32.28 PM.png
Screen Shot 2021-03-29 at 1.35.29 PM.png
Screen Shot 2021-03-29 at 1.35.37 PM.png

Now that you are technically done building the MIDI Controller, of course you want to start playing right away!

Many of you are doing this project to use with Ableton Live for music... and some may even want to use with Resolume Arena for VJ'ing! They both have trial versions if you are interested in checking out.

The layout of each software is slightly different so please reference the images attached if needed - however, what's great is the MIDI mapping logic is nearly identical!

Here's how to map the controller if you don't know how:

  1. Open up Ableton or Resolume with your MIDI Controller connected
    1. In Ableton, you should see the yellow MIDI light flicker (top right corner) when you press the buttons or turn / slide the Knobs / Faders!
  2. Go to Live / Arena < Preferences... (File < Preferences... on PC)
    1. On the MIDI Tab, you should see your Pro Micro listed under as "SparkFun Pro Micro"!
      1. Ableton - Under Input, Turn ON both the Track (for instruments) and Remote (for mapping)
      2. Resolume - Turn on Input
  3. Map the Controller
    1. Close the Preferences window
    2. Open the MIDI Map Mode
      1. Ableton - Click "MIDI" on the upper right corner to start mapping
      2. Resolume - Go to Shortcuts < Edit Midi...
    3. Purple (Ableton) or Green (Resolume) areas indicate parameters you can map the controller to
    4. Click on any parameter (like a Clip, an Effect, Volume, etc), then move a Knob or Fader, or push a Button -- whichever control you would like to map the parameter to
    5. The control is now mapped!
    6. Repeat until all the controls are mapped
    7. Close MIDI Map Mode (Same as Opening)

Now you can use your controller to make music AND be a VJ!!!!

Final Thoughts

Dolce MIDI Controller Graphic.png

A BIG pat on the back for everyone who has made it this far. It really takes some diligence to get all the details finished, but it's well worth it in the end! 👍🎊🎊🎵

I hope you can expand on this tutorial and really make it your own. Can't wait to see what you all come up with! As for me, I am already chomping at the bit to turn this into a Bluetooth controller... 😃

Until next time!

- Dolce

APPENDIX

Screen Shot 2021-03-29 at 3.41.53 PM.png
Screen Shot 2021-03-29 at 3.42.02 PM.png
IAC Driver.png
Screen Shot 2021-03-29 at 3.47.32 PM.png
Midi Note Chart.png

Here you will find a few more resources, including the final steps of how to get the Arduino UNO working!

--

Coding for Arduino UNO (and other atmega 328 boards)

UNOs and other atmega328 boards (like Nano, Mega, Bluno...) can only use Serial Communication via the USB port, rather than direct MIDI communication. That adds a few more steps... but never fear! It still works!

  1. Download the "Midi_Controller_Atmega328_Uno_DW_v2.ino" File (attached)
  2. I have already modified the sketch for 6 Pots and 4 Buttons
  3. Install the MIDI library (different from Pro Micro!)
  4. Upload the Sketch!
  5. Go to Tools < Boards < Arduino AVR Boards... Select Arduino UNO (or your board)
  6. Go to Tools < Port... Select the correct port (mine says /dev/cu.usbmodem14621, PC will probably say COM)
  7. Click Upload (Arrow icon on Top Left corner)
  8. Wait until the bottom status bar shows Upload Complete
  9. Install Hairless MIDI to Serial Bridge - Mac + PC friendly - allows Serial <-> MIDI to talk back and forth
  10. Update: Looks like this app won't work with Mac Catalina+ anymore... found a potential Python alternative
  11. Install / Setup a Virtual MIDI Bus - essentially a digital MIDI cable to connect different software on your computerFor Mac, this is already a default feature! It's called IAC Driver (see attached image)
  12. Search and Open your Audio MIDI Setup Application
  13. If the MIDI Studio window isn't already open, go to Window < MIDI Studio
  14. Double click the IAC Driver icon - the uploaded image says "IAC Dude" because I had renamed it 😎
  15. Check off "Device is Online" to enable it; You can also change the Device Name
  16. For PC, Install LoopMidi
  17. Open Hairless MIDICheck off Serial <-> MIDI Bridge On
  18. Under Serial Port, Select USB ACM
  19. Under MIDI Out, Select your IAC Driver (Mac) or LoopMidi (PC) virtual bus
  20. You should see the green lights flickering - that means it's working!
  21. *Note, you will need to disable Hairless if you want to upload a sketch to your Arduino again
  22. Now your IAC Driver (Mac) or LoopMidi (PC) bus will show up as the MIDI input device on Ableton or other software you may be using!!
  23. Have fun!!!

--

MIDI Monitor - for Mac users, this is a really handy software that just lets you visually see what your controls are doing

--

If would like to assign specific MIDI notes to your controller (say you wanted to build keyboard instrument instead), I also attached a useful MIDI Note Chart