This is going to be a quick post (compared to the average post here).
I recently was in need of a USB to MIDI adapter, wanted to test a midi implementation on a ATmega8 and also check out VCV Rack with my keyboard, which is pretty old and only has a legacy MIDI connection. I didn’t have a USB to MIDI adapter, and was not so keen to buy one anyways, so I set out to find the easiest USB MIDI implementation I could build in a afternoon.
Later, after some searching, I found this project by Yoshitaka Kuwata on the V-USB website. It is a USB MIDI IN and OUT adapter running on an ATtiny micrcontroller, as expected, by making use of V-USB. With some tweaking I could modify the code to run on a USBASP.
If you have not been introduced, the USBASP is an AVR programmer. Therefore, it is used to load code into AVR microncotrollers, like the Atmegas used on Arduinos. It uses V-USB, a software implementation of USB, as the ATmega8 it uses does not have native USB. I have used it as a USB adapter for SNES controllers before. They are very cheap, going as low as two US dollars or less on eBay. A good thing is that the serial (UART) pins, needed by the Legacy MIDI protocol, are already broken out to the connector.
The original code was a bit outdated, being updated for the last time in 2014. I replaced and reconfigured V-USB to the last version available on their website. I also fixed the code to run, and make use of the correct pins, on a ATmega8 instead of an attiny2313. That is it, all the credit goes to Yoshitaka. To burn the code into a USBASP with another, I just connect the ICSP cable between the two and close the jumper JP2 on the target board. See below, the programmer at the top is the target (JP2 closed).
I have three of these programmers, because I keep losing them on my stuff. So when I need one, I just use the first I find. It is okay, they are super cheap and last forever. I still have the first one I bought in 2013.
I could not hook up the MIDI port directly to the ATmega8. The MIDI implementation is isolated, so I used a 6N137 opto-isolator for the job. If you are going to try this, have in mind that you need an appropriate opto-isolator, with fast raising and falling times. I have had no problems with the 6N137. The circuit I used is quite simple, and can be seen below. Thankfully I had all the components here already, including some 5 pin DIN connectors, so I did not have to destroy a MIDI cable or anything like that.
I am not using MIDI OUT, although it is supported by the code and microcontroller. If you need it, you can easily find schematics online, usually with inverters, just tie the input of the circuit to the TX pin on the header.
I could make a board layout and mill it on the CNC, bit it was too much of a hassle for something so simple. So I just used some veroboard. I works fine, but it is ugly as hell. It fits into the programming header, so I can remove it when I need to use the programmer for programming or probably anything else.
Well, what can I say? It works. I am sharing this here so anyone with the same problem and a spare USBASP can save some time. Hope I can still use legacy MIDI for some time, as it is easy to program into a microcontroller. Recently I was searching and could not find a compact MIDI controller with legacy MIDI, most of them only have USB.
Oh. I should mention that I don’t know how to play the keyboard (or any instrument whatsoever) yet, and because of this I won’t record a test video. I got started into music through electronics, and although I can (slowly) read sheet music and understand some concepts of synthesis (even FM), I have not practiced enough to play anything. You unfortunately will have to take my word on this one, haha. The dmesg output for the device connection can be seen below:
Well, that is it, I guess. The code can be found on my github.
Thanks for reading. See you next post o/
13 thoughts to “Hacking an AVR programmer to function as a USB MIDI interface”
Thanks for sharing..
Thanks for reading!
This looks like a really great way of cheaply getting usb to work with MIDI
As i’m a noob with programming do I need to use say ATMEL studio to create a .hex file to program the chip. Or is there an easier way to do this. I have a USBASP and will buy another to try.
I guess you may be able to use Atmel studio to compile the code, but that may be a chore to set up. I use just bare AVR-GCC on Linux, so unfortunately I can not help with that.
However, I have added the already compiled .hex file to the repository, you can burn that with avrdude or a similar program.
Thanks for reading!
what is about the driver?
Sorry I did not make that clear.
USB HID (Human Interface Devices) devices don’t need new drivers, just like a mouse or keyboard. The system (wether linux or windows or whatever really) already has the drivers for this class of USB devices.
hi Robson , and how to set fuses?