uClock icon indicating copy to clipboard operation
uClock copied to clipboard

Workaround for strange MIDI delays using RP2040 and the MIDI library on the hardware serial ports

Open ichingxs4all opened this issue 1 year ago • 1 comments

I recently found a workaround for strange irregular delays in outputting MIDI clock through the hardware serial port on a RP2040 based boards like the Pico or the Waveshare RP2040 Zero. I can pinpoint it to every read operation that is executed in the main loop lik : void loop(){ MIDI.read()} . Or a direct serial port read without the MIDI library. USB MIDI does not have this problem when it is used solo, but both together with an hardware serial device it also this strange behaviour. The result is a BPM that is very irregular and way below the BPM you set with setTempo.

So the workaround I found after al lot of experimentation is using the dual core mode of the RP2040. This solves the problem.

// Running on core1 void setup1() { // Initialize UART midi stack MIDI.begin(MIDI_CHANNEL_OMNI); setHWMidiHandlers(); MIDI_USB.begin(MIDI_CHANNEL_OMNI); setMIDI_USBHandlers(); }

void loop1() { MIDI.read(); MIDI_USB.read(); }

ichingxs4all avatar Sep 24 '24 11:09 ichingxs4all