Arduino Mega and Serial.print() not working?

I'm running this ridiculously simple sketch on my Arduino mega and I'm not seeing anything in the serial monitor output of the arduino software. Do I have to do something else with the mega to make it log? The documentation makes it sound like it should work fine.

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

void loop() {
  Serial.print("Millis: ");
  Serial.println(millis());
  delay(1000);
}

I don't see anything wrong but someone else may, check the baud rate on the serial monitor.

I assume the download is running fine.

try running blink to be sure of basics and one of the examples like serialcallresponse.

I've tried blink and it works fine. The baud rate is correct, it just doesn't output anything. Checking the TX led on the board, I don't see it flashing.

I was just wondering if the fact that the mega has four serial ports wreaks havoc with Serial.print().

Upon further inspection this is an "RCUBE MEGA" not an official Arduino Mega. It appears identical in all other respects to the photos of the mega I've seen online. Everything seems to function other than the serial. I'll get in contact with the seller and see if he knows.

Everything seems to function other than the serial.

If the serial doesn't work, how do you program the device?

Sorry I meant everything works except Serial.print(). I can run sketches on it just fine, I just can get it Serial.print() anything back.

If you are using the Arduino IDE serial monitor to look for the board's serial output, can we assume you have selected the correct baud rate in the monitor's window? Have to ask, as being able to upload sketches says that all the serial hardware is functioning.

Lefty

Ya I definitely selected the right baud rate. It's a really weird issue as I can open the serial output window and I see the RX led flash on the board. If I send some text to the board the RX light flashes again. For the life of me I can get it to send any output out via serial.

I have a duemilinove and if I run that sketch above on it, it outputs fine. If I switch to the mega and re-upload the sketch (nothing else changes except the board in the options) I get no serial output.

Well it might be worth doing a loop-back test. Wire a jumper from ground to the reset pin and wire a jumper from pin 0 to pin 1. Then plug the board into the PC and you should get the indication of a USB device found. Then open up the Arduino IDE, select the proper comm port and then open the serial monitor. Select the proper baud rate. Then whatever you send in the monitor's output window should be looped back to the monitor's receive window. This will check out all the boards hardware (except the processor and it's sketch code), PC usb handling and Arduino serial monitoring.

Lefty

I'm assuming I have to put the code on it before I put those jumpers in place? If I have those jumpers in place and I try and upload I get avr out of sync errors. I'm assuming because we're shorting the send and recv pins?

Anyway if I upload the above sketch, and then put those jumpers in place, open up the serial monitor and send "abc" I get abc in the output and the RX and TX lights both flash briefly. What does this mean?

Anyway if I upload the above sketch, and then put those jumpers in place, open up the serial monitor and send "abc" I get abc in the output and the RX and TX lights both flash briefly. What does this mean?

No code has to be loaded into the processor for the loop-back test to function. The grounded reset effectively disables the processor chip. What a good loop-back test results says is that there is no communications problems with the PC side and the mega board has good power and it's on-board FTDI USB serial converter chip is functioning fine.

It's possible you might have a FUBAR processor but then again you can succefully load sketches into it, so that points away from a bad processor chip, however maybe your Arduino IDE is an older version and/or you have a bad installation of the IDE code. It might be worth a try to reinstall version 18. What version of the IDE are you using?

Your sketch code runs fine in my Seeeduino mega board, so that doesn't seem to be the problem. This is a very interesting problem, anyone else have a guess what might be the problem?

Lefty

I don't know what the next step is. It's hard to test the board without having serial output. I think the analog pins may be defective also. No simple way to know without serial.print() though.

Did some more testing it and I found that if I do Serial.begin(9600); (or any speed) the sketch uploads and everything is happy. But the sketch never starts executing on the board.

If I take the super simple blink sketch and upload it, it works fine. If I add Serial.begin(9600) to the setup() the LED doesn't blink. Comment it out again and it starts working again.

I made a break through!

I use Linux as my primary Arduino OS. I took the above sketch and compiled it onto my Mega from Windows and it works fine! When I bring it back to my Linux box and pull up the serial monitor and I get output.

If I compile it again on my Linux box I get no output again. Is it possible that the Linux compiler is not configured properly? Maybe the serial library for the Mega is bad on Linux? I reinstalled the 0018 IDE on Linux with a vanilla config and it still doesn't work.

I even went so far as to compile the above sketch on Windows and Mac and both work, it's only on Linux that serial output seems to break.

it's only on Linux that serial output seems to break.

I wish you had mentioned you were using Linux sooner (or that I didn't ask!). I believe the Arduino IDE distribution for Linux systems does not include the gcc compiler because all Linux systems already have gcc installed. There are posts that explained about the version number of the gcc compiler that may be being used on your system causing this problem. I'm a windows only user so don't remember the details, but there have been several threads posted on this known problem. Seems if you revert to a older (or is it newer?) version of the compiler it will solve the problem.

Any Linux users that recall the gory details of this compiler version problem?

Lefty

I'll do some searching on the forums. That's strange that there are compiler problems on, as I've done ALL kinds of stuff with my Duemilanove and had no problems.

Everything compiles and works fine on my Mega too except Serial.print().

For the record here are the version of the avr stuff I have. All should be current and up to date.

avr-libc-1.6.7-2.fc13.noarch
avr-binutils-2.20-2.fc13.x86_64
avrdude-5.10-2.fc13.x86_64
avr-gcc-c++-4.5.0-1.fc13.x86_64
avr-gcc-4.5.0-1.fc13.x86_64

That's strange that there are compiler problems on, as I've done ALL kinds of stuff with my Duemilanove and had no problems.

That's because the bug only effected serial for the AVR1280 processor chip, but not the 168/328 chips. As the 1280 has four hardware serial ports the register set-up is different.

PS: Here is one thread telling of the problem and a version solution found that worked for someone. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250084886

Lefty

YOU SIR ARE FULL OF WIN!

I had avr-gcc-c++-4.5.0 and avr-gcc-4.5.0 which came with my Fedora 13 install automatically. I just removed those and installed the version from Fedora 10 avr-gcc-4.3.3 and avr-gcc-c++-4.3.3 and now I can get serial output! YAY!

FYI this is current on my x86_64 bit system and it is working:

avr-libc-1.6.7-2.fc13.noarch
avr-binutils-2.20-2.fc13.x86_64
avr-gcc-c++-4.3.3-2.fc11.x86_64
avrdude-5.10-2.fc13.x86_64
avr-gcc-4.3.3-2.fc11.x86_64

(one normal message first)
this bug persists on gcc upto 4.5.1 (on Linux at least) but with this patch it works like a charm :slight_smile: