What could cause RX to not read data?

Hi, Ive been trying to get a simple verified midi-in sketch running for days. It does not recieve or read incoming midi data. My hardware is good and connected properly. the arduino loads and executes other sketches with no problem. I am begining to think it my be a problem with the ATMEGA itself or software. Here's the sketch:

//variables setup
byte incomingByte;

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


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


void loop () {
 if (Serial.available() > 0) {

    incomingByte = Serial.read();
    // wait for as status-byte, channel 1, note on or off
    if (incomingByte==144){ // 144 is note on ch1
      digitalWrite(statusLed, HIGH);
      delay(20);
      digitalWrite(statusLed, LOW);
      delay(1);
    }

 }
}

For Hardware, I have a arduino diecimila and an optoisolated midi in like this:http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187962258/all Im using midi out from a microkorg keyboard, on channel 1.

The most frustrating thing is it worked once, briefly, and after many failed attempts. (Out of frustration, and lack of other ideas) I took the lead from the opto out (pin 5) and touched it directly to the ATMEGA pin 2 ( rx). I also accidently touched pin 1 and found that I can trigger the board to reset with each keystroke. Directly touch the pin didnt work but when I pit the lead back into the RX socket, it worked. I was amazed, but when I unhooked the lead and put it back again, no dice. My first thought was that it was a loose or bad connection, but after an exhaustive search I have found nothing. I get a very strong beep when i perform a continuity test between the opto pin 5 and the ATMega pin 2. Naturally, I tried touching the lead diectly to pin 2 many times. This does nothing and leads me to suspect that there is a problem with the ATMega and /or some software problem (I dont think that it is the sketch, though) Anyone have any ideas? I am using Arduino 018. But my arduino is from '07. VCould it be a bug or problem with the bootloader....Im just guessing. When I had it working before it almost seemed like I had "jumpstarted" the arduino into reading the data. ?? does this make sense? What could cause the rx to not respond?

I dont have any "real" test equipment, but my Meter reads a steady 5.14v on the RX pin. Should this always be high? Im a noob with digital and programming pics, but shouldnt this be low to recieve input? (The midi input lead read about the same but flickers slightly with key action.)

I tried a simple skech to take a digital read of pin 0 and report back with serial.println. Unconnected it reads "I" and with a lead to ground I get "0", so it seems like it can read something.

I have no idea what to try next except to drop some cash on a new arduino and/or bootloaded chip and wait a week til they get here.

please, any ideas or suggestions are greatly appreciated. thanks

What to try next? How about adding a Serial.print statement to show whether there is serial data available to read? That way, you'd know whether there was data, or not. Not data means one thing. The wrong data means something else.

Then, add a Serial.print statement to show what data was read, if any was read. Maybe your midi device is not sending a 144. Maybe it's sending '1', '4', '4'. Without knowing what was received, if anything was, it's really hard to say what the problem is.

My hardware is good and connected properly. the arduino loads and executes other sketches with no problem. I am begining to think it my be a problem with the ATMEGA itself or software.

Well, if the Arduino loads and runs other sketches, the ATMega chip is working just fine. That only leaves software. I've suggested some ways to check that.

thanks, sounds like a plan.

By the way....I just made a cv to midi converter http://tomscarff.110mb.com/cv2midi/cv2midi.htmworks great...except for the midi thru. The arduino doesnt accept data from neither of my two keyboards, sending it out works fine though.

If anyone reading is familiar with midi, I have another question. The Midi out data is one step behind. I believe with a keyboard it is fine but when controlled by an analog sequencer it is always one step behind the step that should be played. meaning...the note that is being voiced is controled by the pot of the previous step. Not too big of a problem, Im just happy to get something working. Obviously Im a total novice, could someone point me in the direction of what to alter, code-wise? Im guessing clock?? anyway thanks again. ill report back after trying serial.print.

OK, if i did it correctly, I get no data being recieved. heres the sketch:

//variables setup
byte incomingByte;

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


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


void loop () {
 if (Serial.available() > 0) {

    incomingByte = Serial.read();
    // wait for as status-byte, channel 1, note on or off
    if (incomingByte==144){ // 144 is note on ch1
      digitalWrite(statusLed, HIGH);
      delay(20);
      digitalWrite(statusLed, LOW);
      delay(1);
    }

Serial.println (incomingByte);
delay (20);
 }



}

there is no gibberish on any baud..... Ill give it another go tomorrow.

The serial read and serial write use the same baud rate and as this is not the baud rate used by the serial monitor you can't "see" the data you are writing out. If you are writing out to a MIDI output you need to connect a MIDI interface to your computer and use a MIDI terminal program to see it.

144 is note on for channel 0 not channel 1 - sometimes channels are numbered 0 to 15 and other 1 to 16 so it could be the same thing.

Have you defined the incommingByte variable as a byte? I think it needs to be a char and the comparison in hex so it converts to a char. if (incomingByte==0x90){