Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arduino stops sending data to the serial port after a long time period

I am using an Arduino Uno rev2 device as a permanently connected device that sometimes sends signals to a PC (Windows 7 x64). Code compiled with Arduino 1.0 software from arduino.cc

Topic on arduino.cc, Arduino stops sending data to Serial after a long time period

Souce code

It works perfectly but sometimes, after a long period of time, the PC stops receiving data from the Arduino device. It is not a PC software issue, as all software(putty, telnet, etc..) acts the same - I can send data TO the Arduino (the device responds to commands); I just can't receive it back.

A similar problem was described here in Serial communication stops after long periods., but no solution was suggested.

Disconnecting/connecting the device solved the issue temporarily, but this can't be a solution, as the device is supposed to be used permanently and fully automatically.

Using board reset button that resets program & all values to it's start wont help. Data does not start to be being received by PC.

Notes:

  1. millis() rollover bug is not reproducable on Arduino Uno board with Arduino 1.0 software - I guess this was fixed and millis() now do really rollover only in 50 days, like it is said in documentation. Besides code has millis() independent code that is not responding too.

  2. LED that is blinking during sending data to PC still blinks.

  3. Strings usage could increase memory usage, but this program is way too small for that to be a problem. No additional memory was used after 10+ hours of program running, so I'm not really going to bother with replacing Strings with something else, as Serial port problem is far more major.

If you think that the problem is in arduino program bug, please think of how to explain TX blinking & reset not helping.

like image 220
Max The Cat Avatar asked Dec 05 '11 17:12

Max The Cat


People also ask

How does Arduino send data to serial monitor?

How? Using serial inputs is not much more complex than serial output. To send characters over serial from your computer to the Arduino just open the serial monitor and type something in the field next to the Send button. Press the Send button or the Enter key on your keyboard to send.

How long is Arduino serial read?

You can't speed it up. Sounds realistic for me. However, calling Arduino Serial library's Serial. Print takes about 400~600 microseconds to complete the process.

Why port in Arduino is not working?

The most common reason for the board not being displayed on a port are a failing USB connection. The board needs to be connected to your computer with a data USB cable. Make sure the USB cable is not damaged. Test your cable with a different device, or try using a different cable.

How fast can Arduino send data to serial monitor?

9600 bits per second. You are using 9600 baud so letters get pushed out at 960 per second.


1 Answers

Perhaps making a software reset your problem would be solved. I ran the following code to find out if a software reset would reset the clock and therefore the millis() function:

void setup()
{
  Serial.begin(9600);
  Serial.println("Will start sending millis values in 5 seconds...");
  delay(5000);
}

void loop()
{
  Serial.println(String(millis()));

  if (Serial.available() > 0)
  {
    if (Serial.read() == '@')
    {
      Serial.println("Rebooting. . .");
      delay(100); // Give the computer time to receive the "Rebooting. . ." message, or it won't show up
      void (*reboot)(void) = 0; // Creating a function pointer to address 0 then calling it reboots the board.
      reboot();
    }
  }
}

As explained in the code, to make a software reboot simply create a function pointer to address 0 and call it. I, indeed, had satisfactory results:

Will start sending clock values in 5 seconds...
5000
5000
5000
5001
5001
5001
5002
5002
5002
. . .
6804
Rebooting...
Will start sending millis value in 5 seconds...
5000
5000
5000
5001
5001
5001
5002
5002
5002
5003
5003
. . .

I hope this solves your problem :)

like image 111
Matheus Rocha Avatar answered Oct 09 '22 10:10

Matheus Rocha