felic
July 3, 2024, 8:21am
1
I have an ESP32 D1 Mini, two MIDI connectors and an 4N35 optocoupler.
Also, I use a 12V power source with a 5V step down.
How can I use these in order to receive/send MIDI signals?
I found this online, but don't know if it is even correct:
But I tried to adapt it for my case:
Would this work?
of course, but 100k resistor is not needed. and 220ohm is missing
1 Like
felic
July 3, 2024, 9:58am
3
Like this?
And would it be a problem to to use an 1N4148 instead of 1N914? And do I need exactly 560R or could I also go with a more standard size such as 470R or 680R?
kolaha
July 3, 2024, 10:03am
4
felic:
1N4148 instead of 1N914?
yes, they are identic, but anyway it pictured in reverse
felic:
680R?
yes
1 Like
felic
July 3, 2024, 11:45am
5
Like this then? (I swapped the resistor for a 680R one and turned the diode 180°)
And it is correct that Midi Out is not connected to GND?
Just one (important) detail:
The jack labeled MIDI OUT is actually the MIDI IN jack; it is the one who receives the messages.
Conversely, the socket labeled MIDI IN is in fact the MIDI OUT socket; it is the one who sends the messages.
If it seems simpler to you, you can also label them From MIDI OUT and To MIDI IN respectively. This will allow you to know which sockets of your external device you should connect them to.
felic
July 3, 2024, 1:45pm
7
Oh that makes sense. I mean RX sends and TX receives. I guess the description "To MIDI in" and "From MIDI out" from the schematics confused me.
Should be fine now:
The resistor values are incorrect, and since the ESP32's UART uses a 3.3V level, you should use 3.3V for the MIDI jack, not 5V.
See the official spec at 5 Pin DIN Electrical Specs – MIDI.org , it includes details about 3.3V devices.
felic
July 4, 2024, 8:19am
9
Like this?
MIDI In Pin 4 -> 4N35 Pin 1
MIDI In Pin 2 -> 220Ω -> (anode) 1N4148 (cathode) -> 4N35 Pin 1
MIDI In Pin 2 -> 220Ω -> 4N35 Pin 2
4N35 Pin 4 -> GND
4N35 Pin 5 -> RX
4N35 Pin 5 -> 10kΩ -> 3.3V
MIDI Out Pin 2 -> 220Ω -> 5V
MIDI Out Pin 4 -> GND
MIDI Out Pin 5 -> 220Ω -> TX
felic:
Like this?
No, where did you get these values? There's no point in guessing. Just download the official specification and use the correct schematic with the correct resistor values.
Downloading the spec is free, you just need to register with an email address, but you can use a throwaway "10 minute mail" address if you want.
felic
July 4, 2024, 1:12pm
11
How about this then:
MIDI In Pin 4 (IN+) -> 220Ω -> (Anode) 1N4148 (Cathode) -> 4N35 Pin 1 (LED Anode)
MIDI In Pin 5 (IN-) -> 220Ω -> 4N35 Pin 2 (LED Cathode)
4N35 Pin 4 (Emitter) -> GND
4N35 Pin 5 (Collector) -> RX
4N35 Pin 5 (Collector) -> 430Ω -> 3.3V
MIDI Out Pin 5 (OUT) -> 10Ω -> TX
MIDI Out Pin 2 (GND) -> GND
MIDI Out Pin 4 (3.3V) -> 33Ω -> 3.3V
I don't really understand how all of this is works, but I suppose "MIDI In" always receives 5V, thus 220R being fine on that side of the 4N35.
And then on the other side of the 4N35 I suppose 420Ω would be required, based on this information which I may have obtained and used incorrectly:
4N35 forward voltage: 1.2V
4N35 forward current: 0.005A (at 3.3V)
Voltage drop: 3.3V − 1.2V = 2.1V
Resistor value: 2.1V / 0.005A = 420Ω
Nearest E12: 430Ω
Or do I need the forward current for 1.2V? In that case forward current would only be 0.001A and thus a 1.2K resistor would be the result.
It's based on the 4N35 Datasheet :
Forward voltage:
Forward current:
For MIDI Out, I just used 10Ω and 33Ω as the MIDI document seems to suggest for 3.3V:
Dunno why this went off the radar.
The LED resistor at 5 milliamps (0.005 amps) seems good. I'd run it a bit harder, but this should work.
And the other resistor values come from a good-looking document of some kind, so they seem plausible too.
By posting this possibly incorrect response, I rely on that being the best way to get a rapid slap with a damp trout, and a better answer.
It's how the internet works, so let's see if that happens.
a7