Serial communication STOP after few time

Hi everybody,

I wrote a simple code in which Arduino generate random numbers and they are transmitted via serial port. I have two questions:

  • How can I activate the communication only to connect the usb without open serial monitor?
  • When I open the serial monitor, Arduino starts to sent data, I close the serial monitor and after about one minute the TX led stops blinking and the communication is interrupted. Why? I'd like a communication for long time.

Thanks!!

long randNumber;

void setup() {

  • Serial.begin(9600);*

  • randomSeed(analogRead(0));*
    }
    void loop() {

  • // print a random number from 0 to 10*

  • randNumber = random(10);*

  • Serial.write(randNumber);*

  • delay(500);*

}

If you are not receiving numbers in the Serial Monitor what is the point of transmitting stuff?

The Tx led may go off because it can't send any more stuff (the buffer is full, and not being emptied) but the Arduino program probably keeps on running.

Add a few lines of code to make an LED blink so you can tell whether the program is still running.

...R

Thanks Robin2 for your reply!

So I'll try with a LED blink. But Is it possible to fill the buffer with a delay of 500ms?!? I think that it is slow enough to empty it.
And about my first question have you any idea?

woodstock:
So I'll try with a LED blink. But Is it possible to fill the buffer with a delay of 500ms?!? I think that it is slow enough to empty it.

Just delay it by 500ms, it's already in your code.

woodstock:

  • How can I activate the communication only to connect the usb without open serial monitor?

Not sure what you mean by this. You want it to send data to the USB but you don't want to open a serial port? what are you using to check the data?

Also be aware: If you open a serial line half way through your program the arduino will reset and the buffer will empty then.
So a continually connection is advised.
There are ways of disabling the auto-reset, but it requires more sweat than to leave the port open.

Not sure what you mean by this. You want it to send data to the USB but you don't want to open a serial port? what are you using to check the data?

In the priliminary test I want to check the value on the serial monitor but after I'll connect Arduino with a external power supply and I wish that it doesn't stop.

I want to generate random values and printing them on the LCD screen.

woodstock:
In the priliminary test I want to check the value on the serial monitor but after I'll connect Arduino with a external power supply and I wish that it doesn't stop.

I want to generate random values and printing them on the LCD screen.

How can I activate the communication only to connect the usb without open serial monitor?

I don't understand this either.

What makes you think it will stop? Have you tried it with your LCD screen?

...R

woodstock:

Not sure what you mean by this. You want it to send data to the USB but you don't want to open a serial port? what are you using to check the data?

In the priliminary test I want to check the value on the serial monitor but after I'll connect Arduino with a external power supply and I wish that it doesn't stop.

I want to generate random values and printing them on the LCD screen.

I think you'r over-thinking the problem.

If you disconnect your serial monitor it's true the buffer will fill up until you empty it again. But why not just let it happen?
Your program will just continue and no harm's done.

And if your LCD is programmed by serial (Probably not but just thinking out loud) the buffer will be read and emptied.

Conclusion: Just try it, your program won't crash!

I have been having problems with serial monitor, Win 8.1.
It stops suddenly and then will lock the com port - is that the sort of problem you have been having?

walshlg:
I have been having problems with serial monitor, Win 8.1.
It stops suddenly and then will lock the com port - is that the sort of problem you have been having?

This is the first time I have felt it necessary to comment on a Forum members choice of picture. Those blinking eyes are a dreadful PITA. Please get rid of them.

...R

OK found the problem: its a bad Uno usb connector. Can see some problems with the pins, my Leonardos are working fine.

P.S. sorry about the blink, on some forums its nice and slow, will try to rebuild the .png with more frames.