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.

Comments

author
ultimate virus made it! (author)2017-08-31

i change the usb cord. and magic....... Thank you silvius

WhatsApp Image 2017-08-31 at 9.54.30 PM.jpeg
author
Silvius (author)ultimate virus2017-09-01

Nice! I'm glad to hear that.

author
ultimate virus (author)2017-08-12

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??

author
ThéoM32 (author)2017-07-21

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 ?

author
Silvius (author)ThéoM322017-07-21

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 !

author
JasonM296 (author)2016-06-30

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.

author
JasonM296 (author)2016-06-30

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.

author
ContribuinteS (author)2016-05-21

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.

author
Silvius (author)ContribuinteS2016-05-21

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...

author
ContribuinteS (author)Silvius2016-05-22

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 !

author
DươngH1 (author)2015-09-30

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

author
Silvius (author)DươngH12015-09-30

I think is better to stick with 3.6V, anyway at first tests that I made a few years ago I use 3.3v diode and it worked (somewhat unstable)

author
SergeyS6 (author)2015-06-21

author
SergeyS6 (author)SergeyS62015-06-21

I assembled device, Win7 defined and put the driver, but when I look through MIDI messages to MIDI OX, are continuous errors and incorrect messages, tell me what's wrong?

author
Silvius (author)SergeyS62015-06-26

After we made several experiments with this interface, I noticed that do not work well with SoftwareSerial and MIDI Arduino libraries...

I have used MIDI library only with hardware serial...Perhaps there is a solution ... but should be reviewed/analised code for: MIDI library, Software Serial, MidiShield, and main Arduino program (sketch)...

So, for further experiments I give up using MIDI library. Instead I make my (little)code for sending MIDI messages with this interface.

This interface works well for experiments/projects which I am working... (I have no other MIDI USB interface).

You can read this instructable: https://www.instructables.com/id/XY-MIDI-Pad-with-Arduino-and-TFT/ where I successfully used this interface. (not with MIDI library)

You can read also this article http://openhardware.ro/rotary-encoders-experiments... where I read 15 rotary encoders with Atmega1284 and this interface... and I manage to make a small MIDI controller in this way...

also I use this interface in other project with CD4067 and 32 (up to 128) potentiometers and Atmega32. I also tested with Arduino Mega2560 and SoftwareSerial (and hardware serial).

This is the code that I use to send midi messages:

voidSendMIDIControl(bytechannel,bytecontroller,bytevalue){//0= channe l; 1=channel 2; ...
bytetmpChannel=(channel&0b00001111)-1;
//midi data first bit allways 1, + 011 control change command + midi channel
tmpChannel=0b10110000+tmpChannel;
//midi data first bit allways 0
bytetmpController=controller&0b01111111;
//midi data first bit allways 0
bytetmpValue=value&0b01111111;
// write midi data in order: channel, controller, value
Serial.write(tmpChannel);
Serial.write(tmpController);
Serial.write(tmpValue);}

... here in comment is not too readable, but you can read the two articles above... and there you will find the code.

And if the problem persists, do not hesitate to contact me again.

Good luck!

author
sashabeep (author)Silvius2015-09-06

Sad about this. It must be popular request and i didn't found any ready-to go device. Do you will release toolbox and/or library based on your code?

author
Silvius (author)SergeyS62015-06-24

I just returned from a long journey... I'll go back with an answer in a day or two

author
sbranzo (author)2015-03-15

hello! I tried to make this project with an atmega8a, but it doesn't work: if I connect the shield to pc I don't see any device. I can program the microcontroller with the usbasp (in slowclock mode) and checked all the connection... thanks in advance

author
Silvius (author)sbranzo2015-03-15

I don't think that has to do with differences between ATmega8 and ATmega8A... If you are sure the connections are correct / according to the scheme... I don't see a cause for that... You set fuse bits for 16MHz? I put here fuse values which are read exactly from a functional module(I use it for over 6 months
for other experiments with different MIDI modules).

LOW FUSE = 0xCE

HIGH FUSE = 0xD9

Setting fuses is mandatory in order to run at 16Mhz... hex file is compiled for that speed...

After that ... if not working: Check that you have correctly
identified pins from USB socket... especially D+ And D -

Regards!

author
ram_aloktripathi (author)2015-03-07

Hey!

Amazing Instructable!

I made one and programmed atmega8. Everything worked just fine but when I connect my usb module to computer, it shows usb device not recognized(code 43 error). How to solve that problem? What could be the probable error? Please Help!

author
Silvius (author)ram_aloktripathi2015-03-07

When I made the first tests with this project I met this behavior in these cases:

1. I forgot to put decoupling capacitor (10uF but I think will work even with unpolarised 1uF capacitor.

2. USB cable is faulty (I replaced the cable and everything went well)

3. But I think the most likely is not setting fuse bits of Atmega8 for external 16 Mhz quartz. I have not say about this in instructable... and maybe I would have to do.

look here about fuses: http://www.ladyada.net/learn/avr/fuses.html I think that's the most likely cause.

Waiting to see if it worked...

author
ram_aloktripathi (author)Silvius2015-03-07

Thank you so much!

Will try all and will get back to you. :)

author
stitchee (author)2014-09-01

the only avr available in my place are 88 168 and 328 can i use 88 instead??

author
Silvius (author)stitchee2014-09-01

I do not have handy an atmega88, so I worked "blinded". Pinout is the same but I have to recompile and change some code in project.

This should work but I can not guarantee until do a real test. You have to try.

Download zip file attached to this comment, locate the file MidiShield1.hex andwrite it in atmega88. Still use 16MHz quartz.

And please tell me if it worked. :) If ok I will update the article.

Success!

MidiShield1 atmega88.zip
author
stitchee (author)Silvius2014-09-01

is the hex different from the one in the intructable? and can i power my arduino conncting the vcc too? for one power supply

author
Silvius (author)stitchee2014-09-01

Yes hex is different. And source code in the project is slightly different (only main.c). Because the atmega88 has more I/O registers and more interrupts then atmega8, and some of their names are different.

Sure you can power arduino from vcc but you must take into account the number of potentiometers and LEDs that you intend to use (and other components, multiplexers, display etc).

USB 1.0 max 150mA

USB 2.0 max 500mA
USB 3.0 max 900mA

one 10k potentiometer at 5V ~ 0.5 mA, one standard LED ~ 20mA.

author
stitchee (author)Silvius2014-09-01

thank you very but i cant download the midihex in this comments

author
Silvius (author)stitchee2014-09-01

hex file was in the zip archive...but I put it here separately.

MidiShield1_atmega88.hex
author
stitchee (author)Silvius2014-09-02

ohh yes my fault haha my phone is lagging thats why i couldnt download
it hours ago. have you ever tried u ever tried uploading hex file on
arduinodroid?

and can i upload hex using the uno with this . this is interesting :D

http://www.gammon.com.au/forum/?id=11638

author
Silvius (author)stitchee2014-09-02

No. I did not tried to use the Arduino as a programmer. I know about it but I like to use USBASP programmer. It is more comfortable for me. I even built some based on ATmega8.

author
sonicase (author)2014-08-18

nice

author
Arman5592 (author)2014-08-18

Cool ! And thanks for sharing .

author
Robson Couto (author)2014-08-17

Cool!

I love AVRs, and have interest in learning how to use the V-USB with them, maybe someday.

author
Silvius (author)Robson Couto2014-08-17

Thanks! I tried to make things easier by putting HEX file ready to use.

author
MsSweetSatisfaction (author)2014-08-17

Nicely done, thanks for sharing!

author

Thank you!

author
Arman5592 (author)2014-08-17

Hi , is this a micro controller board ?

author
Silvius (author)Arman55922014-08-17

Yes... and can be connected to other microcontroller boards(Arduino or other type) to send/receive MIDI commands to/from the computer via USB.

About This Instructable

27,802views

63favorites

License:

More by Silvius:Reading 15 Rotary Encoders with Arduino and ATmega1284Open Source TV Box - GeekBoxAVR Transistor Tester
Add instructable to: