user49126: UPDATE : I still can't receive MIDI as of 2019/07/01. 
Here goes so far : I'm trying to follow this schematics from instructables, using 6N138. To make it easier, I'm going to copy his schematics. 

===================================
I'm using Arduino Mega. I tried to find specific topic about this and can't find any. 
The target is actually send and receive MIDI, then replace the whole Arduino Mega to ESP8266 (probably the ESP-01, or Wemos D1), but I'm afraid it is too specific. 
Here's the code so far on PasteBin
Here's my work so far. 


The diodes were replaced with LED, because I don't have one Original guide here.
But that schematics on that thread also didn't work for some reason. 

user49126: How to connect 6N138 to Arduino :

Schematics : 

Basically the above schematics and installation is already okay, but instead of 1k, I used 10k on 6N138 PIN 7 to GND.
VCC to 470 ohm is on PIN 6, also RX out, connected in series. 

Just in case you want to use 6N137 : 

Schematics : 


Pin 5 of the MIDI DIN connector goes to pin 2 of the 6N137 
Pin 4 of the MIDI DIN connector goes via 330 ohm resistor to pin 3 of the 6N137 (so the 6N137 pins and the resistor are connected in series) 
You should also have a reverse connection protection diode between pins 2 and 3 of the 6N137 but I like living dangerously and rely on the diode inside the 6N137 
Pin 8 and 7 are connected to VCC 
Pin 6 is connected to RX
Pin 5 is connected to GND
4.7 kohm pullup resistor between pin 8 and 6 (VCC and signal out)

Adapted from this blog post.

How to test it : 

I used Arduino Mega with this code.
I then attached the Arduino Mega to Hairless MIDI, then to loopMIDI.
Then I read the MIDI output using MIDIOX. 


I might update it with H11L1 / PC900 later, if I have some time. Also, I'm going to put this thread in Indonesian in my blog later. 

user20245: Most start at the midi site at playground.arduino.cc.  But there are numerous web sites across the Internet.  It is important to understand that the MIDI interface uses a current loop to send and receive data.  While the Arduino normally uses voltage levels to communicate.  As such, an electronic interface needs to be built or bought to convert between these two types of signals.  Some interface designs are simple and limited.  Others are complex and robust.

user31105: There are plenty of MIDI circuits and most of them are quite simple, mostly an optocoupler (6N137 or 6N138, although I had better luck with H11L1), some resistors and that's mostly it. I also added ferrite beads for EMI protection, but this is not absolutely necessary.
To test your circuit, use a lot of data (e.g. by pitchbend/aftertouch), and play notes meanwhile. If you hear stuck notes (meaning the MIDI Note Off command is missed), you know the circuit is not full proof.
Regarding libraries: the FortySeven Effects library is really easy to use. I used it in the beginning before I moved on to STM32 and having to write my own, but this is a good starting point.
For the schematics I based my circuit of can be found at H11L1 optocoupler.
The best way is to read the official MIDI documentation, see page MIDI 1.0 Specification, than search for
Download the Complete MIDI 1.0 Detailed Specification Document (1996) 
(Please Register! It's Free!).


49126: <p>UPDATE : I still can't receive MIDI as of 2019/07/01. </p>

<p>Here goes so far : I'm trying to follow <a href="https://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/" rel="nofollow noreferrer">this schematics from instructables</a>, using 6N138. To make it easier, I'm going to copy his schematics. 
<a href="https://i.stack.imgur.com/VmuRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VmuRr.png" alt="enter image description here"></a></p>

<p>===================================</p>

<p>I'm using Arduino Mega. I tried to find specific topic about this and can't find any. </p>

<p>The target is actually send and receive MIDI, then replace the whole Arduino Mega to ESP8266 (probably the ESP-01, or Wemos D1), but I'm afraid it is too specific. </p>

<p><a href="https://pastebin.com/Wv8y1LUf" rel="nofollow noreferrer">Here's the code so far on PasteBin</a></p>

<p>Here's my work so far. 
<a href="https://i.stack.imgur.com/n56Xu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n56Xu.jpg" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/l6ByZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l6ByZ.jpg" alt="6N138"></a></p>

<p>The diodes were replaced with LED, because I don't have one <a href="https://electronics.stackexchange.com/questions/436268/do-i-really-need-diodes-to-receive-midi">Original guide here.</a>
But that schematics on that thread also didn't work for some reason. </p>
 49126: <p>How to connect 6N138 to Arduino :</p>

<p><a href="https://i.stack.imgur.com/n56Xu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n56Xu.jpg" alt="enter image description here"></a>
Schematics : 
<a href="https://i.stack.imgur.com/VmuRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VmuRr.png" alt="enter image description here"></a></p>

<p>Basically the above schematics and installation is already okay, but instead of 1k, I used 10k on 6N138 PIN 7 to GND.
VCC to 470 ohm is on PIN 6, also RX out, connected in series. </p>

<hr>

<p>Just in case you want to use 6N137 : </p>

<p><a href="https://i.stack.imgur.com/t6V0G.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t6V0G.jpg" alt="enter image description here"></a></p>

<p>Schematics : 
<a href="https://i.stack.imgur.com/GJhPo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GJhPo.jpg" alt="enter image description here"></a></p>

<ul>
<li>Pin 5 of the MIDI DIN connector goes to pin 2 of the 6N137 </li>
<li>Pin 4 of the MIDI DIN connector goes via 330 ohm resistor to pin 3 of the 6N137 (so the 6N137 pins and the resistor are connected in series) </li>
<li>You should also have a reverse connection protection diode between pins 2 and 3 of the 6N137 but I like living dangerously and rely on the diode inside the 6N137 </li>
<li>Pin 8 and 7 are connected to VCC </li>
<li>Pin 6 is connected to RX</li>
<li>Pin 5 is connected to GND</li>
<li>4.7 kohm pullup resistor between pin 8 and 6 (VCC and signal out)</li>
</ul>

<p>Adapted from <a href="https://codeandlife.com/2017/09/17/5-usb-midi-adapter-with-atmega32u4/" rel="nofollow noreferrer">this blog post</a>.</p>

<hr>

<p>How to test it : </p>

<p><ol>
<li>I used Arduino Mega with <a href="https://pastebin.com/9jNRYbcj" rel="nofollow noreferrer">this code</a>.</li>
<li>I then attached the Arduino Mega to <a href="https://projectgus.github.io/hairless-midiserial/#downloads" rel="nofollow noreferrer">Hairless MIDI</a>, then to <a href="https://www.tobias-erichsen.de/software/loopmidi.html" rel="nofollow noreferrer">loopMIDI.</a>
<li>Then I read the MIDI output using <a href="http://www.midiox.com/" rel="nofollow noreferrer">MIDIOX</a>. </li>
</ol> </p>

<hr>

<p>I might update it with H11L1 / PC900 later, if I have some time. Also, I'm going to put this thread in Indonesian <a href="http://rinaldo.id" rel="nofollow noreferrer">in my blog</a> later. </p>
 20245: <p>Most start at the <a href="https://playground.arduino.cc/Main/MIDILibrary" rel="nofollow noreferrer">midi site at playground.arduino.cc</a>.  But there are numerous web sites across the Internet.  It is important to understand that the <a href="https://en.wikipedia.org/wiki/MIDI" rel="nofollow noreferrer">MIDI interface</a> uses a <a href="https://en.wikipedia.org/wiki/Current_loop" rel="nofollow noreferrer">current loop</a> to send and receive data.  While the Arduino normally uses voltage levels to communicate.  As such, an electronic interface needs to be built or bought to convert between these two types of signals.  <a href="https://www.instructables.com/id/Custom-Arduino-MIDI-Controller/" rel="nofollow noreferrer">Some interface designs are simple and limited</a>.  <a href="https://www.sparkfun.com/products/12898" rel="nofollow noreferrer">Others are complex and robust</a>.</p>
 31105: <p>There are plenty of MIDI circuits and most of them are quite simple, mostly an optocoupler (6N137 or 6N138, although I had better luck with H11L1), some resistors and that's mostly it. I also added ferrite beads for EMI protection, but this is not absolutely necessary.</p>

<p>To test your circuit, use a lot of data (e.g. by pitchbend/aftertouch), and play notes meanwhile. If you hear stuck notes (meaning the MIDI Note Off command is missed), you know the circuit is not full proof.</p>

<p>Regarding libraries: the <a href="https://github.com/FortySevenEffects/arduino_midi_library" rel="nofollow noreferrer">FortySeven Effects library</a> is really easy to use. I used it in the beginning before I moved on to STM32 and having to write my own, but this is a good starting point.</p>

<p>For the schematics I based my circuit of can be found at <a href="https://electronics.stackexchange.com/questions/311889/i-cannot-get-opto-coupler-h11l1-to-work-as-midi-input">H11L1 optocoupler</a>.</p>

<p>The best way is to read the official MIDI documentation, see page <a href="https://www.midi.org/specifications-old/item/the-midi-1-0-specification" rel="nofollow noreferrer">MIDI 1.0 Specification</a>, than search for</p>

<pre><code>Download the Complete MIDI 1.0 Detailed Specification Document (1996) 
(Please Register! It's Free!).
</code></pre>
