44

If I upload any sketch that sends serial data, I immediately see the TX/RX LEDs flash once the sketch is uploaded. If I then start the serial monitor, the sketch appears to restart.

A bare minimum sketch that shows this behaviour:

    void setup()
    {
        Serial.begin(9600);
        Serial.println("Setup");
    }
void loop()
{
  Serial.println("Loop");
  delay(1000);
}

Tested with several boards and Mac and Windows versions of the IDE.

Example output - it goes back to "Setup" when I open the serial monitor:

Restart

Why is this?

Rohit Gupta
  • 618
  • 2
  • 5
  • 18
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51

4 Answers4

42

The Arduino uses the RTS (Request To Send) (and I think DTR (Data Terminal Ready)) signals to auto-reset. If you get a serial terminal that allows you to change the flow control settings you can change this functionality.

The Arduino terminal doesn't give you a lot of options and that's the default. Others will allow you to configure a lot more. Setting the flow control to none will allow you to connect/disconnect from the serial without resetting your board. it's quite useful for debugging when you want to be able to just plug in the connector and see the output without having to start the sketch over.

Another way to disable the auto reset is to put a pull up resistor on the reset pin.

Disabling Auto Reset On Serial Connection

sachleen
  • 7,565
  • 5
  • 40
  • 57
13

The truth is always in the datasheets, the schematics and the code:

The Arduino UNO actually uses the /DTR line to trigger a reset, as you can see on the following datasheet:

reset schematic

zmo
  • 1,518
  • 10
  • 16
2

This fixes the problem

import os
import sys
import termios
import fcntl

        self.fd = sys.stdin.fileno()

        # Stop resetting the arduino on serial connect

        self.newattr = termios.tcgetattr(self.fd)
        self.newattr[2] = self.newattr[2] & ~termios.HUPCL
        termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)
RSM
  • 1,457
  • 1
  • 11
  • 26
2

Arduino uses the DTR line (data terminal ready)

So, with the Arduino Serial Monitor it is not possible to change the restart when established the rs232 connection.

But I'm using for example the freeware "HTerm" (under Windows). By default, it does not use the DTR signal. Meanwhile I changed to the freeware "CoolTerm" (a bit more comfortable...): You have to deactivate "DTR Off" unter "Connection Options". In Linux I'm using the "moserial". Under "PortSetup" you must deactivate the "handshake" ;-)

This way is more comfortable for me then adjusting the RESET pin. Also, its a nice benefit saving all the data in a log file for later analyzing…

stevo
  • 51
  • 3