Help troubleshooting MIDI receive circuit.

Hi.

I am trying to make a MIDI receive circuit. I have a 6N139 Opto-isolator and I have been looking at the schematics at Grumpy Mike's site: MIDI Shield

My project is a simple (ha ha) midi clock counter. I thought I could just use the receive side of Mike's Drawings, so my circuit looks like the picture and schematic enclosed below. I made one change where I used a 470R in place of 680R to pull up to 5V. I only had the 470 on hand.

I use the code from Mike's site also, but I don't not receive any serial data as far as I can tell.

Here is a the code:

/* Midi Shield - Mike Cook May 2009
 * ----------------- 
 * listen for MIDI serial data, 
 * sends MIDI note on with push button on Pin 2
 
#####################################################################################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino RX through an opto-isolator to invert the MIDI signal 
and separate the circuits of individual instruments.

####################################################################################################################################################
*/

//variables setup

  byte incomingByte;
  byte note;
  byte button;
  int noteDown = LOW;
  int state=0;        // state machine variable 0 = command waiting : 1 = note waitin : 2 = velocity waiting
  byte channel = 1;  // MIDI channel to respond to (in this case channel 2) change this to change the channel number
                    // MIDI channel = the value in 'channel' + 1

//setup: declaring inputs and outputs and begin serial 
void setup() { 

  pinMode(13,OUTPUT);       // LED to light up
  pinMode(2,INPUT);         // push button to read
  digitalWrite(2,HIGH);     // enable internal pull up resistors
  button = digitalRead(2);  // initialise push button state
  state = 0;  // initialise state machine variable
  //start serial with MIDI baud rate 31250 or another standard speed for debugging
  Serial.begin(31250);        
  digitalWrite(13,LOW);     // Turn LED off
}

//loop: wait for serial data, and interpret the message 
void loop () {
  checkIn(); // see if anything has arrived at the input
  checkButton();
  }
  
void checkButton(){
  if(button != digitalRead(2)) {  // only do stuff on a change
    button = digitalRead(2);     // get new state of button
    if(button == HIGH) noteSend(0x80, 65, 0); else noteSend(0x90, 65, 127);
  }
}  

//  plays a MIDI note
void noteSend(byte cmd, byte data1, byte data2) {
  cmd = cmd | channel;        // merge channel number
  Serial.print((byte)cmd);    // command
  Serial.print((byte)data1);  // note number
  Serial.print((byte)data2);  // velocity
}
  
void checkIn(){
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
   switch (state){
      case 0:
    // look for as status-byte, our channel, note on
    // if (incomingByte== (144 | channel)){  // un comment and comment the line below - to read only one channel
      if ((incomingByte & 0xf0) == 0x90){    // this reads all channels
         noteDown = HIGH;
         state=1;
        }
    // look for as status-byte, our channel, note off
   // if (incomingByte== (128 | channel)){   // un comment and comment the line below - to read only one channel 
        if ((incomingByte & 0xf0) == 0x80){  // this reads all channels
         noteDown = LOW;
         state=1;
        }
        
       case 1:
       // get the note to play or stop
       if(incomingByte < 128) {
          note=incomingByte;
          state=2;
       }
       else{
       state = 0;  // reset state machine as this should be a note number
       }
       break;
       
       case 2:
       // get the velocity
       if(incomingByte < 128) {
         doNote(note, incomingByte, noteDown); // do something withh the note on message
       }
         state = 0;  // reset state machine to start            
     }
  }
}

void doNote(byte note, byte velocity, int down){
  // if velocity = 0 on a 'Note ON' command, treat it as a note off
  if ((down == HIGH) && (velocity == 0)){
      down = LOW; 
  }
  // do something with the note message 
  // this just toggles Pin 13 and ignores the note value and velocity
 if(down == LOW) digitalWrite(13, LOW); else  digitalWrite(13, HIGH);

}

I have a scope I can hook up to this, but I'm not sure what I should look for. and what test points I should check as I send midi to this circuit.

Thanks for any help anyone can give me on this project.

EDIT: The headers I have a the edge of the board are +5, GND, and pin RX from an Arduino.

Jimmy

midi.png

Here is another photo where I drew in the connections you cannot see under the proto board.

Jimmy

The update dropped my images

And this one.

Hello!
At first, it is much simpler for debugging using the standard arduino midi library:

Use the example " / MIDI_Callbacks / MIDI_Callbacks.ino" and just fill in the function:
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
digitalWrite(LED_PIN,HIGH);
}
and:
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
digitalWrite(LED_PIN,LOW);
}
(Make sure, that you define LED_PIN and declare it as output).

On your Midi Sequencer just send some 8th notes and you should see the LED blinking.

  1. Hardware
    Maybe 470R is much too low! Use 1k-10k for testing.
    I, personally, use successfully the midi schematic from the shruti synth (don't care about the 6N137, the 139 should be suitable).
    http://mutable-instruments.net/static/schematics/Shruthi-Digital-v07.pdf
    The wiring on the photo should be ok!
    edit: Scope test: just put the scope between Midi Jack pin4 and pin5 and you should see some flicker between ground an +V while sending notes. On success try the scope between ground and pin0 RX doing the same test.
    Regards
    Matthias

Thanks Madias for the input. I will try your suggestions. One question about the Sruthi schematic, are the midi connectors in that diagram shown from the front or the back? If that is the back, I have wired the correct way around.

thanks!

Try swapping the two socket wires round.