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?

up vote 33 down vote accepted

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

  • 1
    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 Oct 19 '14 at 15:44
  • 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. – Peter Mortensen Aug 9 '15 at 11:13
  • -cont: It was tried on an Arduino Uno R3. – Peter Mortensen Aug 9 '15 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 May 14 '16 at 4: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

  • The link to your schematic image is broken. – linhartr22 Aug 11 '16 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 Aug 14 '16 at 10:06
  • Again, it's broken. Perhaps you can add it as an image using StackExchange's imgur option? Just click the 'image' option in the toolbar of the editor. – Keelan Jun 16 '17 at 11:56
  • done, thanks for the tip (I actually had my own site down for 10 days because I was doing some maintainance, which was just temporary) – zmo Jun 25 '17 at 12:21
  • 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? – Peter Mortensen Mar 20 at 8:53

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)

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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