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?

5

4 Answers 4

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

4
  • 2
    Arduino Unos can be fixed with a 10 µF capacitor across RESET and GND. It works for the one installation I've used it for, so far …
    – scruss
    Commented Oct 19, 2014 at 15:44
  • 1
    I tried using PuTTY, connecting to the COM port the Arduino appears at (COM16 in my case). It is still resetting the Arduino if "Flow control" in Connection/Serial is set to "None" (the other options are "XON/XOFF", "RTS/CTS", and "DSR/DTR"). I used version 0.60 of PuTTY. Commented Aug 9, 2015 at 11:13
  • -cont: It was tried on an Arduino Uno R3. Commented Aug 9, 2015 at 11:21
  • The Duemilanove and Uno have a trace labeled "EN RESET" which controls this behavior. Scratch off that trace to disable auto-reset. Solder a wire across the pads to re-enable it.
    – mhopeng
    Commented May 14, 2016 at 4:13
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

11
  • The link to your schematic image is broken.
    – linhartr22
    Commented Aug 11, 2016 at 22:47
  • 1
    Thank you, I fixed it! I actually thought that SO was caching images, but looks like it's not, so I'll make sure to keep it always on.
    – zmo
    Commented Aug 14, 2016 at 10:06
  • 1
    Yes, but what actually happens? Is it due to the way the ATmega16U2 is programmed (asserting PD7 low when a COM port is opened by a program?)? Or following some standard for DTR?). And what is the implication of C5? - will it reset the main processor for both transitions (low to high & high to low)? What is the approximate pulse width (in microseconds) on the reset pin of the main processor and what does it look like? Commented Mar 20, 2018 at 8:53
  • 1
    How is this an answer? What we suppose to do with this information????
    – GeneCode
    Commented Dec 23, 2018 at 7:51
  • 1
    It actually does nothing, as you can see from the schematics. The reason it's there is that you can cut the DTR line between the RESET-EN legs to disable automatic reset, and if you want to reenable it, then you can solder together the two RESET-EN pads.
    – zmo
    Commented Feb 19, 2020 at 13:21
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)
1
  • 1
    Please provide some explanation as to why it fixes the issue. Commented Jan 13, 2021 at 5:23
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…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.