I'm not familiar with your board but it has support for native USB as far as I know. In which case the below will apply.
Your sketch does not get past the while(!Serial) if you don't have a communication channel open (e.g. serial monitor).
There are strange things in your sketch that make me wonder
while (!Serial) {
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialisation failed!");
while (1)
;
}
Serial.println("inistalisation done");
}
myFile = SD.open("Messung.txt", FILE_WRITE);
That reads:
if no communication channel is open, print something (that is acceptable although a bit silly as it will get lost) and next initialise the SD card; repeat till the communication channel is open. So you run hundreds of times SD.begin() which does not make sense.
I have no reason to believe that your board differs from other boards with native USB. In which case, if your communication channel was open and you disconnect your board (or even close serial monitor, eventually all the serial prints will start blocking the code.
You can load the below code for testing all of the above
//const uint8_t pinLED = 17; // For SparkFun Pro Micro, the RX LED has a defined Arduino pin
const uint8_t pinLED = LED_BUILTIN; // For Arduino Leonardo/Micro, use the built in LED
void setup()
{
pinMode(pinLED, OUTPUT); // Set LED as an output
Serial.begin(57600);
uint8_t LEDState = LOW;
uint32_t lastUpdateTime = 0;
while (!Serial)
{
if (millis() - lastUpdateTime >= 100)
{
lastUpdateTime = millis();
LEDState = !LEDState;
digitalWrite(pinLED, LEDState); // toggle the LED
}
}
Serial.println("Hello world");
}
void loop()
{
digitalWrite(pinLED, LOW); // set the RX LED ON
delay(500);
digitalWrite(pinLED, HIGH); // set the RX LED OFF
delay(500);
Serial.println("..................");
}
You might have to adjust the pin of the built in LED.
Run the sketch with serial monitor closed; it will flash at a high rate. When you open serial monitor, it will change to a lower flash frequency and start printing dots.
Close serial monitor and observe the blink pattern; it will eventually slow down.
Now disconnect your board from the computer and power your board externally; you will never get past the fast flashing blink.
//Edit
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project
See About the Installation & Troubleshooting category.