Serial.print Arduino

0 views
Skip to first unread message

Nathen Paisley

unread,
Aug 5, 2024, 2:12:44 AM8/5/24
to keihalepu
Im 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.

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.


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.


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.


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?


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?


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


Here are the details:

Board: Arduino Uno Rev.3, have tried two official "made in Italy" boards, and two clones. none work

Computer: Gateway and HP, both with Windows 7, neither work.

USB cable: Have tried two different cables, neither work.

Sketch with Serial.print: Have downloaded three sketches off Arduino Examples site, and one I copied from Arduino for Dummies. none communicate serially.

My sketches and wiring have to be correct, because the projects work perfectly other than writing to the computer's serial monitor.

Occasionally I get a partial message, if I toggle the computer's serial monitor off and on.

I can' be the only one to have had this problem.

Any suggestions greatly appreciated.

Thanks a million.


Thanks for the suggestion.

I'm not sure what an IDE is.

Each time I switch Arduino boards I need to go to tools and then to Com, to select the appropriate com. Is that what you mean by "Com driver"???

Please reply.

Thanks.


About wiring:

All four of my applications work perfectly except for serial communications.

They are very simple sketches and very simple wiring.

If there was a problem with wiring the applications would not function properly.


You are not the only person to have this problem. You will probably only get it once. Turning the monitor off and on re-stets the programme. The IDE is essentially the window in which you write programmes, the one with black and turquoise stripes, and it tells you which COM port you are using at the bottom left corner. I think IDE stands for integrated development environment.


If you are using that, which is very likely, and you can upload a sketch OK by pressing the black arrow, there is nothing wrong with the programme, the USB cable, or the Arduino .

So, do you see the message "Done Uploading" shortly after you press the black arrow?


I have changed Serial.print() to Serial.println() I have also moved it to loop() and added a 1000 msec delay. That way it will cause the message to repeat every second as long as the sketch runs. (Nick's sketch produces the desired output every time on my setup but I'm running Linux and not certain the behavior is the same on Windows.) You can also watch the TX and RX LEDs on the UNO. They will both flicker when you load the sketch and TX should flicker when your sketch writes to the serial port.


OK... Three changes. I added code to turn the output on pin 13 high during the serial write. I connect that to an LED in series with a 330 ohm resistor. I can see the LED light every time a serial write occurs. That gives me a very high level of confidence that the Serial.println() is being executed. Hopefully you have a spare digital output you can use for testing.


Nick's test produced only one line of type every time I toggled the serial monitor off and on.

But only twice out of ten times did it print a complete "Hello".

Usually it was just "H", "He", or "Hel".


Hank's test did almost exactly the same.

Once again, only one line of type every time I toggled the serial monitor off and on.

The Tx LED, and LED hooked up to pin 13 flashed every second as expected.


Very simple serial test code. Copy and paste into the IDE code area. Upload via clicking the IDE upload arrow. When upload finished, open the serial monitor by clicking the serial monitor icon in the upper right of the IDE. Ensure 9600 baud rate is selected in the serial monitor. Type something in the serial monitor text box and send. What was typed in the text box should be sent back to the serial monitor display.


PeterRabbit:

Nick's test produced only one line of type every time I toggled the serial monitor off and on.

But only twice out of ten times did it print a complete "Hello".

Usually it was just "H", "He", or "Hel".


I'm sure you understand that what I sent was the absolute minimum to prove the point - see something on the screen. The flashing lights are irrelevant at this stage. And yes, it is supposed to say one line - hello - in full, and nothing else.


If it says just "hel", there is there is something wrong, but the fact that it says something implies that it isn't serious - and no more money need be spent. I'm afraid I have no idea what it can be - other than to check in the bottom right corner of the serial monitor (again?) and ensure it says "no line ending" and "9600 baud".


Thanks a million Zoomkat.

Your sketch did not return the message which I sent.

However, every time I toggled off and on the serial monitor, a few of the first few letters of serial came up.

For example "Ser"


Which version of arduino IDE software are you running? I have in the past encountered something similar with an older arduino IDE, possibly version 0019. I suspect that particular version arduino IDE opens serial port differently than other serial monitors.


You ask how I "toggle the serial monitor off and on"

I click on the serial monitor button at the upper right to turn on.

I then click on the X at the upper right to turn off.

Then I click on the serial monitor button again to turn back on.

With each toggling of the screen I get a partial, but very rarely complete message.

For example if the arduino was to transmit "Hello my friend", it would typically transmit "H", "He", or "Hell", and rarely "Hello".


I click on the serial monitor button at the upper right to turn on.

I then click on the X at the upper right to turn off.

Then I click on the serial monitor button again to turn back on.

With each toggling of the screen I get a partial, but very rarely complete message.


Do you know that each time you toggle the serial monitor window the Arduino resets and so the program starts again?

And that the serial buffer in the computer is not emptied when this happens, so yes you will get partial messages when you dick about with the serial monitor window.

3a8082e126
Reply all
Reply to author
Forward
0 new messages