works: MIDI-IN: code + schematics

Oops, I meant...a resistor between pin 6 and ground. Also my arduino doesnt read midi data when the jack is connected to the arduino. (midi 4>rx, midi 5> ground) I thought that using the optoisolator was just a precaution.??

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.)

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.

http://www.fairchildsemi.com/ds/4N/4N28-M.pdf

hi

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.

thanks

fubbi

Yes you can.
Have a look at the doc:
http://home.roadrunner.com/~jgglatt/tech/midispec.htm

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

//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
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  
  //start serial with midi baudrate 31250 or 38400 for debugging
  Serial.begin(31250);        
  
}

//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
      action=1;
      digitalWrite(statusLed,HIGH);
    }else if (incomingByte== 128){ // note off message starting
      action=0;
      digitalWrite(statusLed,LOW);
    }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)
      note=incomingByte;
      playNote(note, 0);
      note=0;
      velocity=0;
      action=2;
    }else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
      note=incomingByte;
    }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
      velocity=incomingByte;
      playNote(note, velocity);
      note=0;
      velocity=0;
      action=0;
    }else{
      //nada
    }
  }
}

void blink(){
  digitalWrite(statusLed, HIGH);
  delay(1000);
  digitalWrite(statusLed, LOW);
  delay(1000);
}


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

 //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?

As said before a few times:
A lot of MIDI devices don't use NOTE OFF messages but NOTE ON with VELOCITY 0.
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 ! :wink:

(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.

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:

     if ( (action==1)&&(note!=0) ){ // ...and then the velocity
      velocity=incomingByte;
      playNote(note, velocity);
      note=0;
      velocity=0;
      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.

tep:

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].

[1]
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?
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187962258/60#71
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!

Yep, I did try your schematic, no luck. My experience was the same as Charbot.

For those planning on building this, order a few of both optocouplers to be safe. :wink:

Hi, I just recieved for Xmas my Arduino Mega, and I wish to control circuit bent devices (toy keyboards, speak and spell, DIY filters...) via Midi with Arduino.

Any help would be appreciated !

Question : did anyone tried the midi library for Arduino ?

Thanks

Here is the official midi schematic for inputs, outputs and through ports :

The triangle amps followed by a small ring are inverters, like the 4049, used for buffering the signal.

Hi !
I hacked my old dead Atari 1024stf with a handsaw and a dremel to get the midi in and out pcb with optocoupler, inverters and 556 timer.
(Off topic : do you know what the 556 do in midi out messages ? Midi clock ?)

It works great as a midi input optocoupler !