Pages: [1] 2   Go Down
Author Topic: Leonardo No Serial Output  (Read 2301 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

Code:
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?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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.

http://arduino.cc/en/Serial/IfSerial

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still nothing even with the while loop...
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 04, 2013, 06:53:51 am by normanc » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think it is some kind of Arduino-PC communication error. 
This likely, and the problem is probably on the PC side.

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 05, 2013, 07:19:51 am by normanc » Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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/).
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 30
Posts: 619
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Pages: [1] 2   Go Up
Jump to: