I am currently working on a Teensy 2.0 Arduino project where I want to either connect the Teensy USB to the computer, or in other scenarios just to a phone Charger (no computer listening to the serial port). Without chaning the sketch in between.

I am now opening Serial like:

Code:
void setup() {
  Serial.begin(38400);
  while (!Serial)
  ;
}

... 

void loop() {
 Serial.print("foo");
 // do other stuff
}
If I comment out all the serial stuff my sketch runs just fine with "nothing" (a charger actually) connected to USB. If not it seems to hang in setup().

Is there a "right" or suggested way to solve this problem or should this just work and is my problem somewhere else (a side effect)?

Thanks in advance,
Ralph