Wait for Leonardo Enumeration(Code running when opening serial monitor)

I am running Jeff Rowbergs code on the MPU6050 and there is this one line saying

    // initialize serial communication
    // (115200 chosen because it is required for Teapot Demo output, but it's
    // really up to you depending on your project)
     while (!Serial); // wait for Leonardo enumeration, others continue immediately  


in the initialization of the sensor. I need to have the code running without opening the Serial monitor. Is there a workaround on this?

I want to restart the Arduino without opening the monitor(It should be stand alone) if the sensor code crashes(Which it does sometimes).

I have the Arduino Yun.

Thank you

Just remove that line.

On Arduino boards without native USB like the Uno, Mega, Nano, etc., the microcontroller is reset when you open Serial Monitor. So you see all the output from the very start of the program. On the native USB boards like your Yun, it is not reset. So any serial output that happens between the time the program starts and when you get the Serial Monitor open is lost. The solution to that issue is to add this endless loop that waits until you got the Serial Monitor open before continuing with your program. However, in the case where you want the program to run without Serial Monitor open, you should not have that code in the sketch.

Thank you, the restart process behave as it should now.

You're welcome. I'm glad to hear it's working now. Enjoy!