Leonardo No Serial Output

I'm quite perplexed on this one. I'm trying to get the serial output to work but I'm not receiving anything on my serial port, either through serial monitor or hyperterminal!

void setup() {
   Serial.begin(9600);
}

void loop() {
   Serial.println("Hi");
   delay(100);
}

I figure this should be simple enough, it should just print "Hi" over and over again in the Serial Monitor. It compile and uploads fine on COM4, and then I immediately click the serial monitor. Autoscroll is checked, No line ending, 9600 Baud. I just get a blank screen, however.

Is this just a simple problem?

A leonardo is different from more standard arduino boards when using the Serial port. You must use a 'wait for attachment' command after the begin statement:

void setup() {
   Serial.begin(9600);
     while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
     }
}

void loop() {
   Serial.println("Hi");
   delay(100);
}

Not tested as I don't have a Leonardo board.

Lefty

Still nothing even with the while loop...

You have exhausted my knowledge of the Leonardo. Like I said it's -different- :wink:

Lefty

Well, here's something I discovered that's interesting, if nothing else. I actually have a PING))) sensor, and I was going through the tutorial with an LED just to make sure the arduino is at least working.

Basically I am running the code from here: http://arduino.cc/en/Tutorial/Ping

What happens is that the LED blinks as I expect with distance... the closer I am, the faster the LED blinks. At point blank it blinks at something like 10-20 Hz.

Now, if I open up the serial monitor, this blinking goes down to maybe 1-2 Hz. So opening the serial connection is doing something... but what it is doing, I don't know. I'm not receiving any output on the monitor at all, when I am expecting the range value.

I would say it's a communications error related to the TX of the Leonardo (since you can upload a sketch), but I have no idea of how to test this. Can you just try another Usb cable? Look at the RX/TX LEDS when you connect the Leonardo, then when you upload a sketch, and finally when the sketch is supposed to send data after you open the serial monitor. Do they blink?

Another thing you may try is to monitor the Windows COM ports when you upload a sketch. You should see the current COM port disconnect (while the Leo resets), then reconnect (while the bootloader is active), then disconnect and reconnect again (moving to normal operations); maybe the ports are assigned a different number.

Another thought: if I'm not mistaken the bootloader for the Leonardo uses a baud rate of 57600, it may be worth trying the same rate on the serial monitor.

spatula:
I would say it's a communications error related to the TX of the Leonardo (since you can upload a sketch), but I have no idea of how to test this. Can you just try another Usb cable? Look at the RX/TX LEDS when you connect the Leonardo, then when you upload a sketch, and finally when the sketch is supposed to send data after you open the serial monitor. Do they blink?

Another thing you may try is to monitor the Windows COM ports when you upload a sketch. You should see the current COM port disconnect (while the Leo resets), then reconnect (while the bootloader is active), then disconnect and reconnect again (moving to normal operations); maybe the ports are assigned a different number.

The TX light will blink during the sketch upload, but not after that (when it's supposed to be sending the "Hi"). Switching baud rates to 57600 does nothing either.

I did monitor the COM port, and it does go through the disconnect -> connect bootloader -> connect to the original COM port. I am definitely on the right COM port... serial monitor won't open anyway if you're not using an active port.

I think it is some kind of Arduino-PC communication error. We checked the TX (1) pin and the USB lines... both show activity under an oscilloscope.

I did a quick loop where I tied pin 0 and 1 together, and printed a number to Serial1, and read it back in using Serial1. I verified activity with an LED and it works.

However, I tried to do another code, where I send data from the Serial monitor and try to read using Serial. It does not work, and in fact, the Arduino sketch gives me an error:

java.io.IOException: Input/output error in writeArray

Any ideas? I reinstalled drivers, updated Java to the latest revision... I don't know what it is.

No more ideas, but your latest observations would make me think of an error on the pc side. And then, some more clueless advice: change physical com port, change cable, change pc, install a different OS (some linux live distros can run from a usb pen drive). Also, there might be utilities that show if a port is taken by a process (say, the leonardo is seen as a modem and you have a fax service running on the pc). And it could be that some languages (say, python) show more detailed information about the I/O error.

normanc:
I think it is some kind of Arduino-PC communication error.

This likely, and the problem is probably on the PC side.

normanc:
We checked the TX (1) pin and the USB lines... both show activity under an oscilloscope.

This concludes nothing. USB is a serial protocol and there is always activity (ACKs on the link layer for example.). Unless you are using a USB protocol decode, you don't know what was going on.

Pins 0 and 1 on the leonoado have nothing to do with PC/USB communication.

You guys are right, it's PC side. I tried it on another computer (Windows 7, IDE 1.0.4) yesterday and everything works as expected.

I can't isolate what the issue is. The computer I'm using is Windows XP, with Java 7 installed, and the Arduino IDE 1.0.4 and 1.5.2. I've tried uninstalling and reinstalling the drivers, tried a number of COM Ports from 2 to 10. I haven't thought about the cable but if I can upload software successfully I don't think it's the cable. I cannot reinstall the OS on this and I can't really use another one (this PC is the one that's been allocated for my project). Anything else that could be obvious?

Thanks for all your help so far guys, it's been appreciated.

Although the symptoms aren't the same, you might try disabling Bluetooth. That has caused other serial related problems on Windows.

Look at the BIOS parameters before boot, there should be an option to enable/disable the Usb EHCI (enhanced host control interface). As far as I understand it is enabled by default, but a previous user may have disabled it.

You can obtain basic diagnostic information from the Windows event log, and since you have access to an oscilloscope you might want to try a tool for Usb electrical analysis (see http://www.usb.org/developers/tools/).

One thing to consider is what version USB ports do you have? I've had problems using my Leonardo on USB3.0 ports. I had to move it to a USB2.0 port to work correctly.

spatula:
Look at the BIOS parameters before boot, there should be an option to enable/disable the Usb EHCI (enhanced host control interface). As far as I understand it is enabled by default, but a previous user may have disabled it.

You can obtain basic diagnostic information from the Windows event log, and since you have access to an oscilloscope you might want to try a tool for Usb electrical analysis (see http://www.usb.org/developers/tools/).

This is a laptop, I have very limited options. There is no EHCI option in BIOS.

hiduino:
One thing to consider is what version USB ports do you have? I've had problems using my Leonardo on USB3.0 ports. I had to move it to a USB2.0 port to work correctly.

This is an old computer, HP zd7160us. P4 running Win XP SP2 and Java 7. The USB should be 2.0.

Thanks for any continuing help. I may just have to run on another computer if I can't figure it out, but I don't see any reason why it shouldn't communicate.

Perhaps you already did, but check the HP support page for Usb troubleshooting: http://h10025.www1.hp.com/ewfrf/wc/documentSubCategory?tmp_rule=68308&tmp_task=solveCategory&cc=ca&dlc=en&lc=en&product=392747.

I would go back to my previous suggestion to burn a linux OS on a DVD or pen drive (if the PC can boot from a Usb pen drive). lubuntu.net is relatively lightweight and should work with acceptable performance.

I've given up on this PC and I'm using an ubuntu netbook with no problems. Thanks for all the help, I've even tried new firmware for the laptop.

Question, what is the difference between the Arduino IDE available on the sofware center versus the downloadable from the website? I'm currently using the IDE from the software center.