I was looking for an USB MIDI controller device (or interface) for music applications like piano or organ keyboard or pedalboard. After some research, I wanted to go to a more "homemade" solution. My choice has finally been oriented to a microcontroller board development like the Arduino boards and I choose a Teensy Development Board as it can natively use an USB MIDI library (teensy web site).

It was very useful to make some tests with MIDI softwares and write some MIDI "hello world" software (via some sketches of the arduino IDE). But as I want to keep board "free" and I don't want to sacrifice it in a permanant device, I looked into a cheaper solution.

My Goal:

- make it cheap / low cost
- with the easier architecture possible (only one MCU)
- can communicate through the USB port directly (whithout a MIDI-to-USB conversion step)
- recognise by a Computer as a stand alone MIDI device
- easy to build (at worst, a soldering iron)
- powered by the USB port with no external power source

The result:

It looks like an Arduino on a Breadboard based on an Atmega328p MCU (atmel site), communicate directly through the USB port thanks to the V-USB software-only implementation (V-USB site), and cost only about 8€ (10$) to build (for electronical components)

Step 1: Architecture / Principe

The device has no aditionnal chip and communicate directly through the USB port.

I use the analogic/digital inputs to generate events. The management of these events and the conversion in the USB MIDI messages are treated by the software embed in the Atmega MCU.

Step 2: My Own AVR USB Device

My kit is based on the USnooBie development Kit (USnooBie):

The USnooBie is a microcontroller kit that does not require any sort of AVR programmer or USB-to-serial converters to load and run compiled code. It's hardware design allows the user to develop low cost USB devices with Atmel's AVR ATmega microcontrollers. It can also be used to develop projects which are not USB devices. It is even compatible with Arduino.

I have adapted the schematics and remove the voltage regulator and kept only the zener diodes to limit the D+ and D- voltage (see the schematics image). All these specifications are detailed on the V-USB Obdev site (V-USB Obdev)

The needed components are the following:
- 1x Atmega328p
- 1x USB connector
- 1x 12MHz crystal
- 2x 3.6V zener diode
- 2x 22pF ceramic capacitor
- 1x 100nF ceramic capacitor
- 1x 4.7μF electrolytic capacitor
- 1x 1.5kΩ resistor
- 2x 68Ω resistor
- 2x mini push button switch

The first success step is to turn the device in the USBasp mode by activating the bootloader.

The use of the bootloader is not mandatory but it is very useful as il allows to flash the future SW directly through the USB port (FTDI or AVR Programmer are not needed any more)

Step 3: Programming the Midi Software

The bootloader mode allows to consider the device as an USBasp programmer. In this mode, you are able to upload softwares directly to the MCU without an extra FTDI or Programmer. This mode is also compatible with the Arduino IDE (exemple).

In my case, I didn't succeed to use directly any MIDI library with Arduino IDE sketches, so I came through a more basic way (with AVRdude command lines) and I was inspired by 2 work:

I made some modifications in the C code to make it compatible with the Atmega328 MCU (pin numbers, analogic/numeric - input/output, etc.) and the USnooBie configuration (mainly the D+ and D- pin assignment).

Once the USB divice is reseted, it is recognized as an Audio Device.

Step 4: The Result

You can see the result in this short video.

The device is recognized as a MIDI controller.

In my case, I assigned it to a Piano keyboard and I send “Note On” and “Note Off” MIDI message by pressing and releasing some switches.

<p>Hello.</p><p>Will this work on OS X (El Capitan, Sierra)?</p><p>I would only need two midi buttons with the Momentary (push?) mode.</p><p>Button pressed is midi ON, button released is midi OFF.</p><p>Thank you,</p><p>Roger</p>
<p>Step 1, wrong Input description!</p>
<p>Hello everyone, I having a problem installing everything, the drivers, v-usb, and i don't know how to do it properly, could anyone help me? There is any video or a very detail tutorial in order to install the software and the drivers? Im using Linux</p><p>Thank you</p>
Hey, just here to tell you that I see a tiny mistake which I can't look away from.<br>In your last image you switched inputs.<br>General buttons, as I know, are digital and potentiometers are analog. Not otherwise, even though it would kind-of be able to work, but not as intended.
<p>Don't see source code(( Can I see source?</p>
<p>it is the same that the Thorsten Source Code : <a href="http://electronicsodyssey.blogspot.fr/2011/10/atmel-attiny45-attiny85-based-usb-midi.html" rel="nofollow"> http://electronicsodyssey.blogspot.fr/2011/10/atm...</a></p><p>Just add inputs</p>
<p>Thank you!))</p>
<p>Nice tutorial! I've been looking for! But, can I add more button? because in your demo you only have 5 button I want have 12 button. but how can I do it?</p>
<p>Just add in a shift register.</p>
<p>Would you care to explain please, how exactly is this done? For example using CD4067s - those are widely available, inexpensive and suitable AFAIK, I just have no idea how to implement it in the circuit above. Thanks!</p>
<p>you will find a lot of exemples on the Internet :</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/nXl4fb_LbcI" width="500"></iframe></p>
<p>Hola estoy intentando hacer un acordion Midi pero no se mucho de Atmel studio y no se como hacer el bootloader para que el atmega328 sea reconocido como un dispositivo Midi no se si podrias subir el Hex para cargarselo a mi atmega </p><p>Saludso desde Tijuana</p>
<p>Hi,</p><p>my HEX is linked to my project (a test with 7 keys). It is just a proof of concept and is not applicable directly</p>
<p>Hey friend.! Can you please re-make the circuit. I want to build it like module. So, your new circuit will specify which pin is analog in/digital in and outs. Like an arduino have</p>
<p>Hi,</p><p>You can find the pins caracteristics from the Atmega Datasheet like this : </p><p>http://www.hobbytronics.co.uk/image/data/tutorial/arduino-hardcore/atmega328-arduino-pinout.jpg</p>
<p>Just the tutorial I've been looking for! Definitely gonna make use of this.</p>
<p>Hi,</p><p>Very interesting! I am now planning to make a digital keyboard using a &quot;real&quot; harpsichord keyboard (i.e., one made by a professional harpsichord builder).</p><p>I am looking for an appropriate type of midi sensor system; Perhaps yours would be good for such a purpose? If you think you may be interested in a business collaboration (no need for investment on your part), please contact me:</p><p>David Bolton</p><p>dboltoncreations AT gmail.com</p><p>Have a nice day!</p><p>David</p>
<p>Hi David,</p><p>Mostly in this device, people are using reed switches. It is robust and quiet.<br>I <br> understand that with harpsichord you have to manage the velocity ? <br>(like a piano keyboard). In this case, you will need 2 switches per key <br>to calculate the typing speed. Then the speed is sent through the midi <br>message to the computer, to a harpsichord simulator software.</p><p>Regards,</p><p>AA</p>
Hi AA,<br><br>With the harpsichord, you really don't need velocity, but the keyboard should be able to detect velocity, so that it will able be able to play piano samples, etc.<br><br>Thanks for your advice: I will do some research on reed switches.<br>&iquest;Hablas espa&ntilde;ol? &iquest;En qu&eacute; pais vives? Es que yo 19 a&ntilde;os en Espa&ntilde;a.<br><br>Have a nice day, wherever you are!<br><br>David
<p>Ho yes of course, the strings are plucked :-|</p><p>Then for the main purpose, with no velocity, it is quiet easy. You will need to make a 8x8 matrix (unless you have a chip with 61 inputs...) with 61 switches (per each keyboard). And further, for a &quot;piano&quot; use, it will be a little more tricky.</p><p>Vivo en Francia, pero soy &quot;casado&quot; con Espa&ntilde;a ;-) hace muchos a&ntilde;os</p><p>Un saludo !</p>
<p>Hi, do you have the hex file or the sketch that you use on the chip. Thanks.</p>
<p>Hi there! Great man, it seems like the best solution! Can i have the parts that i will need &amp; the schematic to solder them? thanks for now</p>
<p>Hi,<br>I have made an update with the components list and a schematic file.</p>
<p>Very cool! Thanks for sharing this.</p>

About This Instructable




More by El Pajarito Manitas:Make your own cheap USB MIDI Controller or Keyboard 
Add instructable to: