Go Down

Topic: works: MIDI-IN: code + schematics (Read 117653 times) previous topic - next topic


From what I understood it is a different voltage level, so that's a bit more than precaution.
(BTW that's why the 3.3k resistor is 1k if a FTDI is connected.)


Feb 23, 2010, 05:25 pm Last Edit: Feb 23, 2010, 05:30 pm by Charbot Reason: 1
Hey Tep,
just tried your circuit (again). Like before, the opto seems to function(via LED) but my arduino read nothing.   I have already tried different resistor combos with the (working)cny17-4.  As far as I can tell, it seems pretty forgiving, midi data gets through every time.  
There has to be some hardware problem going on here.  It doesnt read midi even when the opto is bypassed and the midi connected directly to the arduino.  THis should work.  There is no need for any kind of filter or anything, is there?


Oh, another thing....
I may have already mentioned this , but I did get a 4n28 to work,once.
I dont know what I did, but after like, the umpteenth  build it just worked, briefly...until I disconnected the rx lead.  When I put it back in place it would no longer communicate. At first I though that it was definately a continuity issue but everything checked out, and since it works fine now with a cny17-4, i know it cant be  bad or loose connection.


The resistance is RBE and is mentioned in the datasheet. It's measured in kohms from 10k to 1meg. And it does cut down noise. It also has an affect on Ton.




i am looking for a solution to extract a beat out of Midi Time Code. I want to cycle four relays in the tempo of whatever is running. 1-2-3-4, 1-2-3-4, 1-2-3-4 etc

With this schematic and an arduino, is it all possible? Is there a "click" in the MTC or somewhere else in MIDI that I will be able to read with the arduino?

I will not be able to loop a note. I have to get it out of some kind of general system message stream or time code.




Yes you can.
Have a look at the doc:

In the worst case, if you don't get it working or think it is too complex for you now, have a midi loop sending standard Midi CC.


Like Chris L here above I'm having a problem making my Arduino read a poly midi signal.

When I send a MIDI signal from my TC Electronics Konnekt 48 it works fine and polyphonic works, but when I use my MOTU UltraLite it only receives a mono signal.

Here is the code I am using
Code: [Select]
//variables setup

byte incomingByte;
byte note;
byte velocity;

int statusLed = 13;   // select the pin for the LED

int action=2; //0 =note off ; 1=note on ; 2= nada

//setup: declaring iputs and outputs and begin serial
void setup() {
 pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
 //start serial with midi baudrate 31250 or 38400 for debugging

//loop: wait for serial data, and interpret the message
void loop () {
 if (Serial.available() > 0) {
   // read the incoming byte:
   incomingByte = Serial.read();

   // wait for as status-byte, channel 1, note on or off
   if (incomingByte== 144){ // note on message starting starting
   }else if (incomingByte== 128){ // note off message starting
   }else if (incomingByte== 208){ // aftertouch message starting
      //not implemented yet
   }else if (incomingByte== 160){ // polypressure message starting
      //not implemented yet
   }else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
     playNote(note, 0);
   }else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
   }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
     playNote(note, velocity);

void blink(){
 digitalWrite(statusLed, HIGH);
 digitalWrite(statusLed, LOW);

void playNote(byte note, byte velocity){
 int value=LOW;
 if (velocity >10){

//since we don't want to "play" all notes we wait for a note between 36 & 44
if(note>=36 && note<44){
  byte myPin=note-34; // to get a pinnumber between 2 and 9
  digitalWrite(myPin, value);


Anyone else seen this?


Aug 11, 2010, 02:43 pm Last Edit: Aug 11, 2010, 02:43 pm by tep Reason: 1
As said before a few times:
[glow]A lot of MIDI devices don't use NOTE OFF messages but NOTE ON with VELOCITY 0.[/glow]
That's the main issue related.
Check that out, add a verification of the velocity before the action to switch to action 0 if the velocity is 0 ! ;)

(and/or connect the two interfaces together and read the raw MIDI to be sure about it.)


Oh thanks

sorry I missed your earlier posts.


I can't seem to figure this out. Could you please post a modified version of the code I've been using?

I'm going on a tour with my band and i just changed my Audio/Midi interface and now my "light show" is all mono.


Aug 12, 2010, 09:03 am Last Edit: Aug 12, 2010, 09:03 am by tep Reason: 1
No, wait it seems ok, because if the velocity is 0, the velocity is <10 then the light is LOW.
I have no much time for this right now, but I noticed a detail:
Code: [Select]

    if ( (action==1)&&(note!=0) ){ // ...and then the velocity
     playNote(note, velocity);
     action=2;                  //and not "action=0;" to reinit the value

Otherwise, are you sure polyphony is activated in your software and you didn't miss a setting?


Hi. First of all please excuse my English. For a long time I've being searching for a way to convert MIDI code to plain text. I've found some software but what I really need is to isolate ONLY a list of all Note-On data in the same order they are played. I don't need Velocity, Note-Off Channel Number, Duration, etc. Also need the posibility to transport (change to the other 11 semitones pitch) the whole data. I'm talking about a monodic track (only one voice). For example, to open a MIDI file from Mozart's Piano Sonata first two bars, and to get back this: [C5,E5,G5,B4,C5,D5,C5] But also beguining from [C#5...etc] and [D... etc] and from all the other 11 transposed chromatic steps. This is for Musical Research to found melodic-thematic similarities between within other works from the same or different composers. Could someone give any help to find something near this? I know Peter Van Oostrüm and Günter Nagler's and Go-Minimal software but I can't isolate Note-On data from the rest.
Thank You.


From what I understood it is a different voltage level, so that's a bit more than precaution.
(BTW that's why the 3.3k resistor is 1k if a FTDI is connected.)

I know this thread is a little old, but can anyone explain or point me to some literature why the 3.3k resistor looks like 1k when powered up and how the FTDI relates?


Also the 4N28 optocoupler did not work in any configuration for me.  I could verify the chip itself was working fine using the test circuit on this page [1] and I verified the Arduino Rx worked fine and MIDI signal was fine.  I did finally get things working with the CNY17-4 optocoupler though.

Here is the configuration that ended up working for me:
Arduino Duemilanove connected to Macbook USB
M-Audio Keystation 61es
Schematic in the original post of this thread, substituting CNY17-4 for 4N28

Really strange about the 4N28. No idea why it would not work in this configuration other than some sort of variation between manufacturers [2].

Test Circuit, see #4:

[2] 4N28 by VISHAY SEMICONDUCTOR. I bought mine here:


I'm sorry I can't point you to some literature, but you could have a look at the FTDI chip datasheet and and MIDI specifications.
I've used Motorolas 4N28 an 4N35, the white ones and it works.
Did you try the schematic I did post here?
The one in the first post seems to work only for the poster, many people have the same problem: No 100k & GND connection on 4N28 pin 1!

Go Up