Arduino USB MIDI Interface

47,440

75

45

Introduction: Arduino USB MIDI Interface

A few weeks ago I started working on a MIDI controller using Arduino and ATmega32. I did not completed projected yet. It is under development.

You can read the whole story here http://openhardware.ro/arduino-usb-midi-controller/.

But during experiments I realized that interface module can be a stand-alone project and can be used by those who are already working on similar projects.

The project was designed to use easy to find components.

Step 1: Components

  1. Atmega8 microcontroller
  2. Socket DIP28
  3. USB-B connector
  4. Polarised capacitor 10uF ~ 50uF
  5. Connector 5x2 pins (optional)
  6. Connector 1x4 pins
  7. Quartz 16Mhz
  8. Ceramic capacitors 33pF
  9. Resistor 2k2
  10. Resistors 68 ohm
  11. Zenner Diodes 3V6
  12. Proto board

Step 2: Schematic

Circuit diagram is simple.

It is a standard schematic used for implementing USBasp programmer.

The difference is in the firmware that we will put in ATmega8.

Step 3: ​Installing the USB Connector

To mount the USB connector we need to make two holes of 2-2.5mm.

Step 4: Mounting Resistors

Step 5: Mounting Zener Diodes

Step 6: Mounting DIP28 Soket

... and capacitors and 16 MHz Quartz.

Step 7: Module Completed

Module is finished after installing 4pins connector.

From left to right:

  • Pin 1 - Gnd
  • Pin 2 - Vdd
  • Pin 3 - Rx
  • Pin 4 - Tx

I have not mounted connector 5x2pin ISP because I already had the possibility to write the firmware on a module made previously.

If you can't write the firmware outside the project will have to mount the ISP connector(5x2pin) and make connections according to schematic.

Step 8: Burning Firmware

To write the firmware for ATmega8 we need a programmer. The one in the image is a USBasp. Of course you can use any other compatible programmer.

MidiShield1Hex.zip contains only hex file.

MidiShield1.zip contains entire AVR Studio 4 project.

The firmware is a slightly modified version of MOCO/MICO – USB to MIDI Converter.

.

Step 9: Using With Arduino

Now we can make connections between the Arduino board and USB module..

In fact it is simple. Just plug the serial ports of the two microcontrollers and GND:

  • RX from Atmega8 to TX of Atmega32 (or TX of Arduino)
  • TX from Atmega8 to RX of Atmega32 (or RX of Arduino)
  • GND from Atmega8 to GND of Atmega32(Arduino)

In my set-up I am not connected VCC because USB interface is powered by USB port(or HUB) and Arduino(Atmega32) is powered separately.

Now we can make first test with the Arduino IDE. As you can see it works with the standard example File>>Examples>>Communication>>MIDI.

void setup() {
// Set MIDI baud rate: Serial.begin(31250); } void loop() { // play notes from F#-0 (0x1E) to F#-5 (0x5A): for (int note = 0x1E; note < 0x5A; note ++) { //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): noteOn(0x90, note, 0x45); delay(100); //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): noteOn(0x90, note, 0x00); delay(100); } } // plays a MIDI note. Doesn't check to see that // cmd is greater than 127, or that data values are less than 127: void noteOn(int cmd, int pitch, int velocity) { Serial.write(cmd); Serial.write(pitch); Serial.write(velocity); }

You can also install this library: https://github.com/FortySevenEffects/arduino_midi_library. It is very helpful for making a MIDI controller with Arduino.

Step 10: Screenshots

After I burned the firmware in ATmega8 and made connections, I connected the USB cable to the computer.
Windows immediately detected the device and installed the standard drivers. No other drivers is required (tested on Windows7-64bit and WindowsXP-32bit).

I also did tests with Fl Studio and Traktor.

Tech Contest

Participated in the
Tech Contest

1 Person Made This Project!

Recommendations

  • Make It Bridge

    Make It Bridge
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge
  • For the Home Contest

    For the Home Contest

45 Comments

0
michaelrayqueen
michaelrayqueen

2 years ago

Im not sure if this is too old to be posting now but hopefully I will get a reply. I am new to electronics and would like to make this. I can do the build just fine but Im not sure how to do Step 8 Burning the Firmware. I am familiar with how to upload sketches to an Arduino, even if i use a TTL converter on the ATmega chip alone on breadbord. However, this does not seem to be the same thing. Can anyone help me get started in this?

1
Silvius
Silvius

Reply 2 years ago

Step 8 is inherently vague because there are so many ways to put that hex file in that microcontroller...
From the question I deduced that you do not have a dedicated programmer. :)
You can try using an arduino as a programmer, and later you can buy a cheap programmer as an USBASP clone.
Search for "Arduino as ISP" right here on Instructables, there are many articles that deal with this, for instance:
https://www.instructables.com/Arduino-As-ISP-Burn-...
https://www.instructables.com/Programming-Chips-Wi...
I hope it was helpful.
Regards!

0
michaelrayqueen
michaelrayqueen

Reply 2 years ago

That was very helpful. Thank you so much. That actually confirms what I thought was the case. I also found those same links and info form the Arduino forum and thought that this was virtually what you were referring too. https://www.arduino.cc/en/Hacking/DFUProgramming8U2. I also read about Arduino as ISP but was not sure if this was the right method. It appears you can pick and choose as the results are the same. Thank you again or clearing that up. I do have a few Arduinos but I also I am fairly sure I have a programmer. I have a few USB to Serial USB to TTL CH340 Module with STC Microcontrollers. This is actually why I originally abandoned the Arduino as ISP research because I could not get it to work on the CH340 chips. Could I use these as dedicated programmer? Ultimately, I am building a MIDI Octopad, I have it working on the arduino uno as a USB to MIDI device and nano using hairless midi. I also removed the ATmega328 chip on the Arduino and and hooked it up in a breadboard and one point and got it working with Hairless MIDI using the TTL converters to power it and plug it in to the computer. I dont want to use Hairless MIDI. Just to make sure I am clear, with your build here could I ultimately remove any and all development boards? So could I build this then just hook up my build from the ATmega328 and this build will power my circuit and do MIDI over USB? If so, do I also need some sort of voltage regulating system? Or can I just connect Vcc from the USB-B to Vcc on the ATmega 8?

0
Silvius
Silvius

Reply 2 years ago

1. "Serial USB to TTL CH340" does not work as a dedicated programmer for
ATMEGA microcontrollers. You can only load programs if you have
previously put a bootloader in the MCU, which is not the case for this project.
You can search USBASP on aliexpress to get an idea about dedicated programmer, like this:

https://www.aliexpress.com/item/32647598702.html?...
...about $2...
2. You can power this interface in two ways, from USB 5V, or 5V from the other module(Arduino), but not both!!!. GND must be connected for RX TX signals to flow between the arduino and the interface.
Atmega8 Arduino
RX <----> TX
TX <----> RX
GND <----> GND

Have fun!
By the way, I haven't tried the interface for a few years, I don't know if it still works in windows 10, nor in the latest versions of linux ...

0
michaelrayqueen
michaelrayqueen

Reply 1 year ago

Hello again. Since you helped me I have bought a DFU programmer and learned how to burn custom hex files. That was great advice and felt like a rite of passage to be honest. Now that I have done that I still can not get the circuit to work. I have built and rebuilt it several times. The only thing that happens is my computer reads it as a power overload and disables the USB port. I have checked with a voltmeter and it is providing roughly 5.4 to 5.6 V. I even bought an oscilloscope just to test this but to be honest I am still very new to electronics and not really sure what the scope is telling me. I tried researching this further as well and looked up MocoLUFA, HIDuino, V-USB, USnoobie, etc. My question is, I notice there is no voltage regulator on your build but most of these type of V-USB projects have that. Could that be why I am having this issue? I did not include one since your build does not have one. I was hoping to not need one but am happy to include one in the build if you think that will help. I thank you again for pointing me in the right direction before. Any futher help will be greatly appreciated.

1
Silvius
Silvius

Reply 1 year ago

It seems to me that it is a short circuit there, or or you misidentified the usb connector pins (and the result is also a short circuit).
It is something you assume wrong, so that's why you reconstructed the scheme and you get the same bad result... maybe polarity of zener diodes?

The first thing I would do would be to measure the USB connector alone, without being connected to anything else.
This will identify with certainty which are the GND pins, + 5V, and which are the data pins (without knowing for sure what D+ and D- are).

In the next step you should identify with certainty which are the pins D + and D- (there are two possibilities anyway). I can assure you that the scheme is 100% correct and functional as it is.

About the possibility of a voltage regulator: if you power the circuit from USB there is no place in the diagram where you could put such a regulator;
USB gives you 5V, the circuit is powered at 5V.

The only place where a voltage reduction from 5V to 3.6V is needed, is D + and D- (on the computer side). And this is done by D1 .. D2 and R1 .. R2, which lowers the voltage level of USB signals (D + and D-) to 3.6V.

So the microcontroller will "put" 5V signals and the D1-D2 zener diodes together with the resistors R1-R2 will reduce the voltage to 3.6 for the computer side.
The computer will "put" 3.6V signals on D + and D- and they will reach the microcontroller pins almost unchanged. And although the microcontroller is powered at 5V it will "understand" the 3.6V signals (that's another story).

Make sure you have not already "burned" the microcontroller, as it could be a big load for USB.

Good luck!

0
michaelrayqueen
michaelrayqueen

Reply 1 year ago

Hello again. I am sorry to come back but it turns out I failed in editing the Hex file to make it say whatever I want when I plug it in to my computer. I can edit it but it every-time I do the circuit no longer works. All I did was edit the part that says V-USB in the Hex file. I also tried this link below,

https://forum.yaeltex.com/t/pimp-my-mocolufa-dual-...

While this does edit the USB device name it also causes the circuit not to work. This is the same MocoLufa that you stated you based this hex file off of but just slightly edited it. What about your Hex file and any of these other mocco lufa files you can find on the internet are different? Can you give me insight in to how I can make your hex file still work even with an edited device name?

0
michaelrayqueen
michaelrayqueen

Reply 1 year ago

You are the best sir! There was a short in the breakout board I made for the USB port. It was hard to determine because it was intermittent. Then, while trying to measure the port as you suggested and realized that the short only happens if that port is jostled around a bit. I made a new one and that seems to be fine but the circuit is still not working. I assume I must not have flashed the ATmega8 properly so I will revisit that but wanted to also mention that I get no readings of any kind off of D- and D+. I am not sure if that is normal. 5V gives roughly 5.23V. Not sure if that is too much. When I test the crystals leads I get around 3.6V at 16Hz. I will post more as I work on it more. Thank you again for your help!

0
michaelrayqueen
michaelrayqueen

Reply 1 year ago

I am very happy to state that I finally figured this out and got my build working perfectly. I have tried this on a Mac running 10.15 and a Windows 10 Machine and it works! I even finished the rest of my MIDI controller build on a solderless bread board to be sure. I was not able to try this on a Linux computer though. I can seriously not thank you enough for your help. Very long story short, the issue was that I was using Arduino as ISP while trying to flash the hex file to the chip. I switched to using an actual DFU Programmer just like the one you recommended and it worked just fine! I also figured out how to set the fuse bits along the way! This was a fun project to be sure! I am now going to work on trying to edit the hex file if I can. I want to figure out how to edit the device name when it is plugged in. Thank you again!!

0
michaelrayqueen
michaelrayqueen

Reply 1 year ago

Not 15 minutes after posting this I learned how to edit the hex files.

0
ultimate virus
ultimate virus

5 years ago

as fer as i know i solder the connections correctly. also set the fuse bit CE,D9. [Atmega8a] install the hex file with ISP, using 16MHz crystal as shown.

but when i try to connect with pc. usb malfunctioned. any suggestion??

0
ThéoM32
ThéoM32

5 years ago

Hi, thank's for your nice work. I have an CP1202 and I don't find how to program my Atmega8 with this hex, do you have a link where I can learn how to do please ?

0
Silvius
Silvius

Reply 5 years ago

CP1202 is a usb to serial/uart converter. You can use this to program an Atmega 8 after you burn a bootloader with a "real" programmer... like USBASP.

But in this case, this project it is not made compatible with a bootloader. So you will need a proper programmer anyway.

At www.aliexpress.com you will find usbasp with price starting at $1.20 with free shipping ... (which is amazing)

Here are some links about usbasp and avrdude:

http://www.elecrom.com/avrdude-tutorial-burning-he...

https://learn.adafruit.com/usbtinyisp/avrdude

https://www.instructables.com/id/The-Idiots-Guide-...

:) ...have fun !

0
JasonM296
JasonM296

6 years ago

Note that USB specification is very strict when it comes to voltages and timing. This can easily explain the unreliable and unexpected results that are mentioned in some prior comments.

0
JasonM296
JasonM296

6 years ago

Note that USB specification is very strict when it comes to voltages and timing. This can easily explain the unreliable and unexpected results that are mentioned in some prior comments.

0
ContribuinteS
ContribuinteS

6 years ago

Amazing ! but...just one question, please. How can I send one note, yes, just one note to a programlike FL Studio and others, through a simple push button ? can you help how to make something like this , please ?

Very nice tutorial, thank you !

Greetings.

0
Silvius
Silvius

Reply 6 years ago

Thank you for comment! At step 9 is an example taken from Arduino IDE which is exactly what you need ... send one note to PC.

you can also look here: https://www.instructables.com/id/XY-MIDI-Pad-with-... I used this interface to send commands to FL Studio.

by the way... I also tested this interface with Linux and FLStudio with WINE... and it's working also with LMMS: https://lmms.io/ in windows and linux...

also I managed to read 15 rotary encoders with atmega1284 and this interface... latest results here: http://openhardware.ro/rotary-encoders-experiment...

This last article is the core for a new instructable that is not published yet...

0
ContribuinteS
ContribuinteS

Reply 6 years ago

Thanks for the quick response. I apologize, because I had tried the example from step 9 , and I do not communicated to you, sorry. This example from step 9, is making the notes follow automatically. I wanted something I even pressed the button and the note was played. I'll see your other instructable. I believe it will help me a lot.

Thank you very much !

0
DươngH1
DươngH1

7 years ago

Hi. If i don't have diode 3.6v. Can i use diode 3.3V 0.5W or diode 3.6V 1W??