Noisy/bad received MIDI data (UART)

I’m working on the MIDI side of my prototype now. I have built an H11L1-based circuit to receive MIDI and send it to the UART RX port on the Seed. Schematic:

On the left, pin 4 hits the 220 resistor and 5 goes to the diode’s cathode and then on to pin 2 on the H11. The schematic calls for 3V from the digital pin on the Seed but I am actually connected to the 3V analog pin (a mistake I haven’t corrected yet.)

I am sending data from an old but working AdrenaLinn pedal into this circuit, tried some other MIDI clock sources too.

What I’m seeing is really messy, bad MIDI data. The Seed is receiving the stream of clock pulses but also decoding random starts and stops, and if I take off the SystemRealTime type filter, all kinds of other messages too. Tracked tempo is kind of proportional to what I’m sending in, but never matches and varies a lot.

This all feels like a hardware problem to me? In case not, some code. Simplified here for space but in my test build I’m also calculating BPM and logging that periodically, and I’ve tried running a PrintLn on every message received to see what’s flowing in (fully aware that it’ll probably slow it all down) - that’s how I know I’m getting all kinds of other MIDI message types too.

I am setting up my MIDI handler like so:

    MidiUartHandler::Config midiConfig;
    midi.Init(midiConfig);
    midi.StartReceive();

And in my main while(true) loop:

       midi.Listen();
        while(midi.HasEvents()) {
            MidiEvent m = midi.PopEvent();
            if (m.type == SystemRealTime) {
                HandleSystemRealtime(m.srt_type);
            }
        }

And finally the handler:


void HandleSystemRealtime(SystemRealTimeType srt_type) 
{
    switch(srt_type) {
        case Start: {
            hw.PrintLine("MIDI Start");
        }
            break;
        case Stop: {
            hw.PrintLine("MIDI Stop");
        }
            break;
        case TimingClock: {
            tick_count++;
            if (tick_count == 23) {
                led_state = !led_state;
                hw.SetLed(led_state);
                tick_count = 0;
            }
        }
            break;
        default: {
        }
            break;
    }   
}

Hoping I’ve just done something dumb like forgotten a pull-up resistor. Thanks!

I think your R2 should be 470 ohms, not 270. Also, typically you’d have a 100NF capacitor with one end connected to VCC (pin 6) of the H11L1 and the other to gnd. Not sure if either of these things would cause the issue you are seeing though.

Thanks. Cap to ground will help with any noise, as will moving off the analog 3v3 to digital.

I got R2=270 from the Petal schematic and some reference schematics built around the H11L1; I think 470 may be the more appropriate value for a 6N138 optocoupler. But I’m waaay over my skis here and you’re not, so I make my claim respectfully and with curiosity :slight_smile:

I’m starting to wonder if I haven’t just built the thing wrong; tried it again just now and it doesn’t work at all. Time to rebuild. I at least did one thing right and made each functional module of my prototype (PSU, audio buffers, MIDI, Seed) separately so it’s easy to swap things out.

Interesting, you are correct the Pod schematic is using R2=270, I got my midi schematic from this website. Which is using 470 and the H11L1. 3V3 MIDI Module PCB – Simple DIY Electronic Music Projects

I’m out of my element too in terms of why it might be 270 or 470. I’ve been using 470 and haven’t had any trouble with my midi stuff

Been digging a bit. I think R2’s value used to be quite low (the MIDI spec calls for 270 using what’s now called an H11L1 but used to be some Sharp unit) to provide enough current to drive the old TTL circuitry that used to receive MIDI. With our microprocessor stuff they don’t need nearly as much current, so you can go really quite high there. I saw recommendations for 2k2 etc.

I guess the point is that one probably doesn’t matter as much as long as it’s not too low!

The 220 on the upstream side is important so there’s enough current in the transmit loop.

I’m also confident none of this is my issue though. I’ll report back when I’ve rebuilt.

Thanks again kshep, appreciate the responses here and time.

Intereating. Yeah, probably not your issue then. What are you sending midi with and what sort of plug? Maybe a wire is simply backwards somewhere. There are lots of different connection types for midi especially over trs.