arduinoclockmiditempo

How to send clock message from arduino to MIDI synth?


I'm trying to send periodically clock from arduino to Electron Digitakt synth with 120 bpm. It means I need to send 0xF8 every 21ms (60000/bpm/ppq -> ppq = 24 pulses per quarter)

My code looks like

void setup() 
{
  Serial.begin(31250);

  for (int i=0; i<10; i++) { Serial.write(byte(0xFF)); } // reset the slave
  
  Serial.write(byte(0xFA)); // send start command
  delay(10);

}

void loop () {
    Serial.write(byte(0xF8));
    delay(21);
}

But I see that my synth switches to Play but BPM doesn't change. I use logic analyser to check the output, it shows that this byte sends every 21ms (+- 1.2ms, usually a half of ms). Tried several libs for arduino with midi management, nothing helped

Could you help me to understand where is an issue?


Solution

  • From this MIDI tutorial for programmers it seems the Reset message should be used cautiously:

    • MIDI Reset message
      • This is a one status byte message 0xFF, without data bytes. It should reset the synthesizer to its power-on default, so it also stops all notes playing. Use this message sparingly, as it reset the full synthesizer, not only the notes playing.

    I would suggest: