Thursday 19 February 2015

Midi for the Arduino - Build a Midi Input Circuit

Less talking, more building!


In this installment we are going to assemble a Midi Input Circuit and connect it to your Arduino UNO. The Circuit itself is actually quite simple consisting of only a handful of parts.

In the last installment, we looked at a Circuit Analysis of a Midi Input and Output Circuit. If you are new to this series, I suggest you check it out. It will give you a better understanding of what you are actually building. Now, let's put this knowledge to use and start building the hardware.

I am assembling the circuit on a small solder-less breadboard. The video will walk you through the steps of putting it together. Take your time and double check your work. You'll be fine!


Parts List (Click links to view parts on Amazon.com)


Schematic (I find it helpful to have a printed copy when I am building)


In the next installment, we look at the Arduino MIDI Library and write software for this circuit.

52 comments:

  1. Hi
    I have problem with your circuit or program for midi in... I did circuit on the prototype board and maybe it works. I have Arduino Mega 2560. I connected this with TX0 (pin 1 on my board) and I see that tx lead blinking, also it's getting the signal. I think the midi library and function not reading massages. :( Function Serial.write() are writing something received with tx communication port. I dont know what I should do now. Please help me!

    ReplyDelete
    Replies
    1. Hi DJ. If you are building a MIDI input you need to use the RX Pin (Receive) instead of the TX Pin (Transmit).

      Delete
    2. thanks Dave, the arrows on the arduino board misled me.

      Delete
    3. LOL Thanks guys, here I am, 7 years later and I made the same mistake. Reading this made me realize it. Thanks for a great tutorial, still of great use!

      Delete
    4. 哈哈,对于新手来说是致命的错误

      Delete
  2. Why did you pull pin 7 to ground with the 4.7k resistor in this version? (really I could use an explanation of the entire thing, but I figured this was the difference between the two circuits)

    ReplyDelete
    Replies
    1. Hi Beni. Check out the following post. It explains the whole thing. http://www.notesandvolts.com/2014/11/midi-and-arduino-circuit-analysis.html

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. It is my humble understanding (thanks for this great educational video!) that the higher the resistor,
    the slower the residual capacity inside the transistor will by drained (considering the pin 7 open as connected to an infinite resistor
    should help understanding how the slope shape evolves relative to the resistor value).
    Slower draining of the residual current means rounder slopes and hence higher propagation times.
    Now keeping in mind that some basic circuits don't even connect Q7, it is not surprising that in many applications like yours apprentely; it still works and it should still be ok/better to have a 10k resistor than no pull-down resistor but expect slower propagation delays...

    ReplyDelete
  5. Just received my 6n138 opto-couplers, measured various resistors configuration and to reply Timo question 10k gave me poor results as expected, around 5us rise time, whereas suggested 4.7k gave me about 1.35us ; much sharper edge.
    Now the interesting thing is that I tried 3.3k and got 950ns rise time. It seems to be better and yet not too sharp (too sharp edges could cause other problems on a pcb layout from what i could read).

    ReplyDelete
  6. Hi
    How do we process chords as part of midi messages. Since midi is delivered serially presumably the notes are sent immediately (hopefully)one after the other and not at the same time? If so then would need to pay attention to the noteon and noteoff callbacks. Correct?

    ReplyDelete
    Replies
    1. Hi John. Not necessarily. Think of it this way, when you press a note on a keyboard it generates a note on message. When you release the key it sends a note off.

      So lets say you play a C major chord (C E G) on a Midi keyboard that is hooked up to an external synth module. The keyboard sends three note commands in quick secsession NoteOn 60,NoteOn 62,NoteOn 64. The synth module would then react to those 3 messages and play the three notes.

      Those notes remain "stuck" on until you release the keys. Now say you take your finger off the C note. The keyboard sends a NoteOff 60 command and the synth kills the C note. The other two notes continue playing until you remove your fingers from them as well. This way the notes take care of themselves.

      To see this in action, you could play a chord on your keyboard then unplug your midi cable. You will find the notes get stuck on until you reset your synth. Hope that makes sense.

      Delete
    2. Thanks for the quick response, totally understand. Just did a quick test sketch and got it to work utilizing 12 leds and having each one representing a note and getting the callbacks from the midi messages. A little off topic, but would like to start using servos to pluck a string from an instrument (guitar,harp,celeste,etc...). Do you have any experience in this area? Any advice you can give or is it pretty straight forward?

      Delete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Hello, first of all thanks for all that has been taught, excuse me if you do not understand well I am using the translator since I am from Argentina, I have the following drawback, I do not think it is normal, since the synthesizer without midi tube the problem that sometimes I can do oscillators and sometimes do not walk, until I move the knob of the pich, now with the midi I have the problem that I have notes sounding and I have to restart the arduino to reestablish, can you help me with this? Or is it normal? Thank you!

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Just as a heads up, the parts list says 3 220 ohm resistors, but looks like there are only 2 in the schematic.

    ReplyDelete
  11. Can I use 330 Ohm resistors instead of 220?

    ReplyDelete
  12. Hi Maz here. I built this and it works great apart from occasionally getting midi drop-outs or hung notes. I wonder if this is a software issue or maybe something that can be rectified by adjusting some values in the optocoupling circuit..
    I am yet to try this myself but I read elsewhere of someone having slight issues with their NaV-1 synth project dropping some midi info. It was suggested to try changing the resistor value from pin 6 on the 6n138 to +V to 470 ohms (from the current value of 220 ohms). It was also suggested to use a 1k resistor from pin 7 to ground ( whereas here it is 4.7k ).
    This apparently solved the guys issues on his NaV-1 project but not sure if it will do the same on this Auduino midi project but could be worth a try.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. How come you chose to pull up the signal on the receiving end to +5V with only 220 Ohms? That seems like it'd only dissipate power unnecessarily, and perhaps even cause issues depending on power supply capabilities.

    ReplyDelete
  15. Great work! Thanks a lot for sharing and all of the effort you put in. I also really like the way you explain the midi signal in general. For the script I have one question. How is it possible to read out the channel, pitch and velocity? In a first attempt I would like to see the readout in the Serialmonitor, later on use those readouts to control a LED light strip.

    ReplyDelete
  16. Hello! Great information! I would like to add a Midi Thru along my Midi In/Out. Is it possible?

    ReplyDelete
  17. Hi !

    My electronics store only had a 6n136 and a 4004 diode, should I change any resistor value ?

    Thanks ! :)

    ReplyDelete
  18. Hi! I know it's been a while since this post was created, but I still hope somebody can help me. I'm trying to do this, but mi piano has usb midi out, and I can't find the right pinout for de usb usb jack.

    ReplyDelete
  19. เติมเงินครั้งแรกผ่านเว็บไซต์เกมคาสิโนออนไลน์ อย่าเงว็บ AMBBET ท่านจะได้รับโปรดีๆ ที่หาที่ไหนไม่ได้อีกแล้ว อาทิ โปรคืนคอมทุกยอดเสีย 0.5-0.8% ซึ่งสมาชิกทุกท่านจะได้รับไปเลยทันที หลังจากที่เป็นสมาชิก ดังนั้น เข้าดู สิ่งที่น่าสนใจเพิ่มเติมในเว็บไซต์ได้เลย

    ReplyDelete
  20. Hi Dave,
    First of all I would like to congratulate you for the excellent work. I'm Brazilian and I started in the "Midi" world now.
    I am building a midi pedalboard and would like to know how to make my pedalboard receive an input for expression/Wah pedals...
    Do you have any material that can help me? I found several materials teaching how to build the 5-pin input (midi input). Would making a guitar input be the same thing?
    Thank you in advance for your attention.

    ReplyDelete
  21. Hello! I just would like to give a huge thumbs up for the great info you have here on this post. I will be coming back to your blog for more soon.

    Cceazuay.gob.ec
    Information
    Click Here
    Visit Web

    ReplyDelete
  22. Negative rail and ground (gnd) are not the same. Negative rail in my opinion mean minus voltage (ex. -12v), and ground is 0 volts.

    ReplyDelete
  23. Hi! I’m new in Arduino and I want to do this project.

    I’ve mounted all the components in a prototype board, but when I connect all, the rx led on my Arduino Uno don’t turn on never…

    I’ve checked the circuit, changed the IC… but nothing happens.

    Can you help me? What can I check?

    ReplyDelete
    Replies
    1. Hi, I'm new too. Also I didn't get the RX led on until I've tried this:
      I've tried to make a Midi input using the code of this web (https://www.prometec.net/midi-recibir-manipular-mensajes/) using Arduino Due (schematic here: https://diyelectromusic.wordpress.com/2021/02/15/midi-in-for-3-3v-microcontrollers/) which is like Arduino Uno but with different voltage.
      What I did that works was: use Hairless (app who connect both serial port and midi - warning: turn on/off "serial&midi bridge" each time you upload your .ino) and use 115200 baud (in your .ino with "Serial.begin(115200); and in the preferences of the Hairless app). Sorry for my english. Hope your Arduino Uno works too.

      Delete