UNO not storing a particular sketch

I’m an experienced programmer and electronics engineer, but new to Arduino.
I started with a very simple blink sketch like this…

int led = 13;
void setup() {                
  pinMode(led, OUTPUT);     
}

void loop() {
  digitalWrite(led, HIGH);   
  delay(2000);             
  digitalWrite(led, LOW);   
  delay(1000);              
}

That all works fine. If I disconnect USB or power and reconnect, it all starts up again as you would expect.
However I’m working towards some MIDI control so I extended it like this…

#include <MIDI.h>
int led = 13;
void setup() {                
  pinMode(led, OUTPUT); 
    MIDI.begin();    
}

void loop() {
  digitalWrite(led, HIGH);  
      MIDI.sendNoteOn(42,127,1);  
  delay(2000);             
  digitalWrite(led, LOW);   
    MIDI.sendNoteOff(42,0,1); 
  delay(1000);              
}

So the only difference is including the class, adding MIDI.begin and the 2 sendNote lines.
This also works fine and you can see both the Pin 13 LED and the TX LED flashing as you would expect.
BUT…
If you remove the USB connection to power down the board, when you replace it, the program doesn’t restart - no flashing lights. Applying 9v power instead of USB makes no difference - still doesn’t start.

I guess I’m missing something very obvious here, but any idea what???
Thanks
Steve

What board are you using?
What is measured on the 5V header pin when powered from the 9V supply?

UNO R3

5.01v

Steve

I have never use MIDI but I programmed my UNO with your sketch, the led flashes after removing power and restoring it again.
What version of the IDE do you have?

1.0.5

Try adding a short delay in setup before MIDI.bgin() to give the midi time to sort its self out.

Mark

A bit more investigation...
It looks like the program IS running after a power off/on in that the pin 13 led does what it should but the tx led no longer flashes.

Adding a 2s delay before or after the MIDI.begin (or both) made no difference.

So it looks like the midiNote commands don't work after a power cycle - at least there is no sign of activity on the tx led.

Steve

The TX and RX LEDs are driven by the USB interface MCU. With no active USB connection there will be no activity, and hence no TX and RX LEDs flashing.

AAHH! Thanks. I'll finish of the MIDI interface circuitry and see if that's going OK.

I'll report back.

Steve