I'm trying to receive MIDI messages on a Leonardo. To do that I used the circuit in the diagram below (only the top half for receiving). The only thing I did differently was using an 1N4148 diode instead of the 1N914. I connected GND to pin GND, 5V to pin 5V and RX to pin 0 (RX), and I used code below to see whether I do get any inputs or not. (I first started with some more complex code but it seems this is the minimal thing I can do.) As a MIDI source I used an Arturia Keystep which I tested on a midi instrument.

Unfortunately I don't get any input, and I don't know why. What I tried so far:

  • Verified the polarity of all cables, and made sure all connections work.
  • Swapped the Leonardo with a different one (both new).
  • Swapped out the 6N137 optocoupler with another one (both new).
  • Addded above the if-statement a Serial.println("test"); which then resulted in an endless avalanche of "test" in the serial monitor - just to check if the USB connection works.
  • Measured the voltage between pin 5 and 8 on the 6N137 and it is indeed 5V.

Is there anything obvious I'm doing wrong? What things do you suggest doing to try to find the bug? (I do have a multimeter but no oscilloscope.)

(from this answer).

byte b;
void setup() {
  Serial.begin(9600); //USB
  Serial1.begin(31250); //MIDI

void loop() {
  if (Serial1.available() > 0) {
    b = Serial1.read();
  • I don't see any obvious problem, but I used a similar circuit (long time ago though), and I used an 1N4148 without any problem. I had some trouble using the correct resistor value, and I added ferrite beads, but this should not be a problem on a breadboard. Commented Apr 3, 2020 at 19:49
  • Have you checked the plugs according to diagram => solder side. Commented Apr 3, 2020 at 20:02
  • perhaps you reversed pins 4 and 5
    – jsotola
    Commented Apr 3, 2020 at 20:10
  • @Codebreaker007 I think that is it, it seems I have swapped pin 2 and 3 on my stripboard. I'll try to fix that and report back - it would be nice if it was that simple:)
    – flawr
    Commented Apr 3, 2020 at 20:15
  • learn.sparkfun.com/tutorials/midi-tutorial/all
    – jsotola
    Commented Apr 3, 2020 at 20:16

2 Answers 2


The solution:
On the image is stated plugs are solder-side. So swapping pin 2/3 does the trick

  • Actually I should have clarified: The picture is a top down view on the component side - my mistake was that I misinterpreted the diagram:)
    – flawr
    Commented Apr 3, 2020 at 20:49

I think problem is in baudrate of your USB, message from usb is slow and this destroy MIDI message (timing of 31250 baudrate). Set little bit faster USB serial speed. And make buffer between.

Is only try, i dont know if its solve this problem.

  • 2
    Hi devbob, the problem was already solved and acknowledged. Commented Dec 31, 2023 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.