To send MIDI commands we need a 5 pin DIN jack, like for the MIDI-in, but without a galvanic decoupling. The jack has to be connected to +5V, the serial output (TX) and to ground (via a 220 Ohm resitor).
Parts list
-2 x Resistor 220 Ohm
-1 x Resistor 100 kOhm
-1 x Diode
-1 x opto coupler IC GNY17-2
-2 x 5-pole DIN female connector (180°)
-1 x MIDI cable
-1 x MIDI sync master (here: Roland TR-505)
-1 x MIDI sync slave (here: DIY synthesizer with MIDI-input)
-1 x Arduino (here: Arduino Mega. For this demo also Arduinos with less input and output channels will work)
Schematics
Software
The following code can reveive MIDI clock and send synchronous MIDI notes.
sendMidiNote (0x80, note, 0x7F); //last note off
}
else if((data == midi_clock) && (play_flag == 1)) {
Sync();
}
}
}
// Functions
void Sync() { // play 8 fixed 16th notes, repeat after the cycle is finshed
clock_step = clock_step+1;
if (clock_step==1){ //1st step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x5A;
sendMidiNote (0x90, note, 0x7F); //note of this step on
}
if (clock_step==7){ //2nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x4A;
sendMidiNote (0x90, note, 0x7F);
}
if (clock_step==13){ //3nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x4B;
sendMidiNote (0x90, note, 0x7F);
}
if (clock_step==19){ //4nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x3F;
sendMidiNote (0x90, note, 0x7F);
}
else if (clock_step==24){
clock_step=0;
}
}
void sendMidiNote (byte midiCommand, byte noteValue, byte velocityValue){
Serial.print(midiCommand, BYTE);
Serial.print(noteValue, BYTE);
Serial.print(velocityValue, BYTE);
}
}
else if((data == midi_clock) && (play_flag == 1)) {
Sync();
}
}
}
// Functions
void Sync() { // play 8 fixed 16th notes, repeat after the cycle is finshed
clock_step = clock_step+1;
if (clock_step==1){ //1st step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x5A;
sendMidiNote (0x90, note, 0x7F); //note of this step on
}
if (clock_step==7){ //2nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x4A;
sendMidiNote (0x90, note, 0x7F);
}
if (clock_step==13){ //3nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x4B;
sendMidiNote (0x90, note, 0x7F);
}
if (clock_step==19){ //4nd step
sendMidiNote (0x80, note, 0x7F); //last note off
note = 0x3F;
sendMidiNote (0x90, note, 0x7F);
}
else if (clock_step==24){
clock_step=0;
}
}
void sendMidiNote (byte midiCommand, byte noteValue, byte velocityValue){
Serial.print(midiCommand, BYTE);
Serial.print(noteValue, BYTE);
Serial.print(velocityValue, BYTE);
}
No comments:
Post a Comment