Problem with Serial Monitor / Serial.read() example

After trying unsuccessfully to use the serial monitor to debug my own program, I decided to drop back and test a simple example, but I get the same behavior from the Serial.read() example from the website

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

When I run this and try to test it from the serial monitor I get no activity on the Tx led and no text in the monitor. I'm testing this on a Mega 2560 and programming it from windows 7. Anyone know whats going on?

Very simple serial test code

// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    readString="";
  } 
}

Miodhchion:
Anyone know whats going on?

The code looks reasonable and I don't see why it wouldn't work. To give you a clearer indication of what's happening, I suggest you add a Serial.println("Hello world"); in setup() after the call to Serial.begin(). You should see this message on the serial monitor every time the Arduino resets. Among other things, this also proves that the Arduino is running the sketch you think it is. A reset should occur when you open the serial monitor, and of course when you press the reset button.

If you see this output but don't get any response to text entered at the serial monitor, that suggests that the Arduino isn't receiving stuff you type.

Have you double-checked that the correct COM port and serial port speed are selected in the Arduino IDE?

Can you confirm that there is no hardware connected to the Arduino - just the bare board connected to the USB cable?

Thanks guys. The suggestion to add output to the setup function was spot-on. Turns out the Arduino was resetting when the serial monitor opens and taking longer to do so than I had anticipated. It looks like most of my problems were a result of sending data before the Arduino was ready to receive it.