Leonardo USB won't stay connected

That is one fundamental disadvantage of using a Leonardo type board Vs a standard UNO type board. The Uno uses a separate chip dedicated to just providing the USB serial function, and the sketch runs in the separate 328p chip. So a users sketch cannot cause loss of USB functionality no matter how flawed or crashed the code causes. On the Leonardo board the one and only chip has to perform both the serial USB function as well as executing the users sketch, and if the users sketch has logical errors or crashes due to say using too much SRAM it can prevent the USB function to operate and cause PC USB problems.

I could argue that one should only utilize a Leonardo type board only if the project requires interfacing with a USB slave device. Otherwise certainly beginners are better off utilizing a Uno type board.
Lefty