Leonardo Serial Port not Working

Hello,

I just purchased a couple of Arduino Leonardos and I am having some issues with the serial port.
When I program the board it changes the com port number to the bootloader programs, then the main com port comes back.

Test program; (1.0.5 IDE)

int led = 13;

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {}
}

void loop() {
Serial.println("Serial test");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

When I compiled the LED blinked but no serial. I tried this on a Freeduino SB board and it worked fine.
The serial also worked on the Arduino Ethernet.
What could be the issue?

Thanks,
Rob DeVries

Are you sure the Serial Monitor is opening the correct serial port?

Yes, I have verified the ports by looking at the device manager. When programming it is com15 and serial port is com16.
I tired 4 Leonardos and they all did the same thing with not serial port. I even tried different terminal programs with no luck, but they work with other arduino boards.

When I was verifying the com ports something must of changed now I seem to be getting serial communications.
What changed I have no idea since other arduino boards work without any problems.

Thanks you,

rdevries:
What changed I have no idea since other arduino boards work without any problems.

Serial is implemented different on the other boards. So there's no reason to compare behavior of a Leonardo to those. It is like saying: "My Leonardo doesn't work but my Mouse does! What gives?!"

Serial is implemented different on the other boards. So there's no reason to compare behavior of a Leonardo to those. It is like saying: "My Leonardo doesn't work but my Mouse does! What gives?!"

correct the serial is different, but in this case it should act the same as other Arduino boards as I was comparing. So i am not sure why you made a comment like that. All The Arduino boards I have all require a USB driver which makes the serial work the same. In this case I found out what the issue was. I was missing the
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
Once added then it became more reliable.

Moderator edit: quote tag corrected

rdevries:
So i am not sure why you made a comment like that.

Because serial is implemented differently on Leonardo than the other boards. It is also to point out that when troubleshooting, don't over simply what is going on. In this case, it really is equal to saying my comment "My mouse works, why doesn't the Leonardo?" There's nothing in common on the hardware level between the Leonardo and the two boards you describe.

rdevries:
All The Arduino boards I have all require a USB driver which makes the serial work the same.

No, actually, the boards do not require a driver at all. They require a "hardware information file" which is a simple description file for the OS (well just Windows) to know what kind of USB device is attached if you are using a modern board like a Uno or Mega 2560. These are implemented with an ATmega8u2 or 16u2 which is programmed for only USB to Serial conversion.

A Freeduino SB board is based on a Diecmila which uses a FTDI chip. This particular device does require a device driver specific to FTDI chips. Completely different from the Leonoard.

The Arduino Ethernet has no on board USB to Serial converter. So whatever converter you used works different than a Leonardo.

rdevries:
In this case I found out what the issue was. I was missing the
while (!Serial)

Again, it is because serial is implemented different on a Leonardo than the other two boards you mention. In both cases there is dedicated hardware to do the USB to Serial conversion, so there is nothing for the ATmega328 chip to "wait for" to start. This is not how the CDC device works on the Leonardo's ATmega32u4.

This is quite interesting to me, i am having a similar problem with Leonardo. everything seems ...... to work OK except serial port, i stripped down my code so that only the basic serial port stuff is left:
#include <SoftwareSerial.h>

const int ledPin = 13;
boolean ledOn = false;

void setup()
{
Mouse.end();
Keyboard.end(); // make sure both mouse & keyboard are off
Serial.begin(9600);
while (!Serial) { }; // wait for serial port
pinMode(ledPin, OUTPUT);
}

void loop()
{
Serial.println("Hello");
if (! ledOn) {
digitalWrite(ledPin, LOW);
ledOn = true;
} else {
digitalWrite(ledPin, HIGH);
ledOn = false;
}
delay(500);
}
this should write "Hello" to serial every 500mS and turn the led on or off, in practice it stops (i assume) in the while loop.
if i take the while (!Serial) {}; out the led flashes as expected but still no serial output.
pressing reset to upload i get disconnect sound, then connect sound when reset is released, bootloader shows in device manager followed by disconnect sound (no other sounds) but Leonardo, Keyboard hid and mouse hid all appear in device manager, all with no indication that there is a problem (question mark or pling) this is frustrating because it means i cannot use serial to develop but uploading, mouse and keyboard all test OK with uploaded sketches
any help would be extremely helpfull
Dave.... ps i am using windows 7 with all updates to date

This is often to be seen:

Screaming if a newbie asks a "stupid" question
but if it becomes difficult is there nothing but silence.

You arduino developers have a nice forum here.

DRESI
(very frustrated)

This forum is not a bunch of Arduino developers waiting to fix people's problems or support the product. It is people like me, who are simply Arduino users. Some boards are more popular than others, and more people with experience with a particular board may chime in and help, while the less popular board users may have difficulty. Well the Leonardo never did quite catch on as well as the other boards such as Uno, and guess what, it is discontinued! If you have a specific problem with the Leo, I know some about it. Start a new thread instead of posting to the end of an old thread, and give details of the problem, including code inside code tags. You have all personalities here, not everybody quite as loving as me, so don't be so quick to be offended. :slight_smile: