Leonardo Disconnecting/Reconnecting when uploaded to

Hey guys, I've been working for a few months with an Arduino Uno Genuino, without issue.
I'm working on a project that needed more interrupt pins, so I bought a Leonardo.

When I plug the Leonardo in, it shows up just fine, as COM6. I switched to the Leonardo and the COM Port in the Sketch window, but when I try to upload to the Leonardo, my Windows 10 machine makes the standard windows disconnect sound, followed a few seconds later by the reconnect sound, and my sketch doesn't seem to show up on the Leonardo.

I opened the device manager and watched as I uploaded a sketch. When the disconnect sound plays, the Leonardo (COM6) disconnects, and is replaced by the Leonardo Bootloader (COM5), and then goes back to COM6 when the reconnect sound plays.

However, my Uno has never done this. When I upload the same sketch to the Uno (COM3), windows plays no sounds, and the device manager doesn't budge. The Uno is COM3 the whole way through.

I'm not sure if there's something I'm doing, or not doing to cause this, or how to address it? Any help or advice is appreciated.

While Uploading:

After Upload:

The behaviour is normal. When starting an upload, the Leonardo is reset (same as the Uno but using a different approach).

That is when you see the normal Leonardo disappear and the bootloader shows up.

You state that your sketch does not seem to show up on the Leonardo. Does avrdude throw errors in the IDE's output window? If not, you have a problem in your sketch. Test with a simple blink or so. If that works, post your sketch.

Blink works. When I say nothing works, I mean that nothing shows up in the serial monitor (yes it's set to the right baud), and nothing prints on the 16x2 LCD screen, despite there being declarations in the setup block for both, which work fine in the Uno.

Is there something different I have to do to get that to work in the Leonardo?

Here's a modified Blink sketch, with serial printing, which never shows up in the serial monitor of the Leonardo, but shows up fine in the Uno.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO 
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino model, check
  the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products
  
  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
  
  modified 2 Sep 2016
  by Arturo Guadalupi
  
  modified 8 Sep 2016
  by Colby Newman
*/


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("This Never Shows Up!");
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Add while(!Serial(); in setup() before or after Serial begin(); as far as I know it does not matter although I always place it after. You have to wait till a communication channel is established before you can use Serial.print.

On Leonardo, baudrate is actually irrelevant (from my experience).

As you do not show the real sketch with lcd, it's impossible to judge why that does not work.

Thanks! Adding the while made the serial work, and something else I did (I wonder what. . .) made the LCD work now.

I appreciate the help!

Note that there is a side effect to using the while(!Serial();. You will always need a connection to the PC and an application that opens the serial port (e.g. serial monitor) for your sketch to get past that point.

Sometimes that is not an issue, sometimes it is.