2010-11-10

3) Choosing Notes by Potentiometers

In this part we introduce one potentiometer (10 kOhm) per step to choose the note of the step. The current code is for N = 4 steps, but can be easily extended to more steps. As an Arduino Uno has only 6 anolog inputs this would allow N = 6 which is not enough for musical applications. This is why an Arduino Mega with 16 analog inputs should be used here. LowestNote and HighestNote define the range of MIDI notes that can be played. Both parameters should be multiples of 12, because then the note range goes from a C to a higher C.

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)
-N x Potentiometer 10 kOhm

Schematics


















Software



// Declaration of Varialbes
byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;
int clock_step;
int note;
int noteval;
int LowestNote;
int HighestNote;

// Initialization
void setup() {
Serial.begin(31250);
clock_step=0;
note = 0x3F;
noteval = 0;
LowestNote=36;
HighestNote=36+3*12; //3 Octaves over LowestNote
}

// Main Programm
void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data == midi_start) {
play_flag = 1;
clock_step=0;
}
else if(data == midi_continue) {
play_flag = 1;
}
else if(data == midi_stop) {
play_flag = 0;
clock_step=0;

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


noteval
= analogRead(0);
note = map(noteval, 0, 1023, LowestNote, HighestNote);
sendMidiNote (0x90, note, 0x7F); //note of this step on
}

if (clock_step==7){ //2nd step

sendMidiNote (0x80, note, 0x7F); //last note off


noteval
= analogRead(1);
note = map(noteval, 0, 1023, LowestNote, HighestNote);
sendMidiNote (0x90, note, 0x7F); //note of this step on

}
if (clock_step==13){ //3nd step

sendMidiNote (0x80, note, 0x7F); //last note off


noteval
= analogRead(2);
note = map(noteval, 0, 1023, LowestNote, HighestNote);
sendMidiNote (0x90, note, 0x7F); //note of this step on

}
if (clock_step==19){ //4nd step

sendMidiNote (0x80, note, 0x7F); //last note off


noteval
= analogRead(3);
note = map(noteval, 0, 1023, LowestNote, HighestNote);
sendMidiNote (0x90, note, 0x7F); //note of this step on

}

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);
}



2010-11-07

2) Sending MIDI Notes

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.


// Declaration of Varialbes
byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;
int clock_step;
int note;

// Initialization
void setup() {
Serial.begin(31250);
clock_step=0;
note = 0x3F;
}

// Main Programm
void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data == midi_start) {
play_flag = 1;
clock_step=0;
}
else if(data == midi_continue) {
play_flag = 1;
}
else if(data == midi_stop) {
play_flag = 0;
clock_step=0;

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);
}




2010-10-31

1) Reading MIDI Clock

To read MIDI-clock on an Arduino one needs a galvanic separation by an opto coupler. I used a GNY17-2. Use of other ICs (6N137, 6N138 or 4N28) are also possible and the schematics can easily be found on the web.

Parts list
-Resistor 220 Ohm
-Resistor 100 kOhm
-Diode
-opto coupler IC GNY17-2
-5-pole DIN female connector (180°)
-MIDI cable
-MIDI sync master (here: Roland TR-505)
-Arduino (here: Arduino Mega. For this demo also Arduinos with less input and output channels will work)

Schematics

The resistor connected to the MIDI jack is 220 Ohm, the other resistor is 100 kOhm.
As MIDI clock genarator a Roland TR-505 was used.
As LED I used the SMD-LED on the arduino board. You may also connect one to PIN13 (don´t forget the resistor to ground).

For a first attempt to sync the sequencer to MIDI-clock I used the software template of littlescale. Changes were so far only made in the Sync() function.




Software

The following code lets a LED light for the first half of a bar, while it is off for the second half of the bar. Please note that the delay() function was avoided and only clock_step was used for syncronization.


// Declaration of Varialbes
byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;
int clock_step;

// Initialization
void setup() {
Serial.begin(31250);
clock_step=0;
}

// Main Programm
void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data == midi_start) {
play_flag = 1;
clock_step=0;
}
else if(data == midi_continue) {
play_flag = 1;
}
else if(data == midi_stop) {
play_flag = 0;
clock_step=0;
}
else if((data == midi_clock) && (play_flag == 1)) {
Sync();
}
}
}



// Function

void Sync() { // 1st half of a bar: LED=on, seconds half of a bar: LED=off
clock_step = clock_step+1;
if (clock_step==1){
digitalWrite(13, HIGH); // set the LED on
}
else if (clock_step==96/2){
digitalWrite(13, LOW); // set the LED off
}
else if (clock_step==96){
clock_step=0;
}
}


Syncuino - An Arduino-based step Sequencer


In this blog I will report about developement of an
Arduino Mega based step sequencer. It will have the following features:

1) Syncable to external MIDI-Clock (responding to Start-, Stop-, Continue- and Clock-singals) ok
2) Output of MIDI Notes
ok
3) For each step one note can be chosen by a potentiometer
(1 hardware-potentiometer for each step) ok
4) A shuffle rhythm function ok
5) LEDs indicate the actual step (1 LED for each step) ok

Videos will be hosted here.