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
6182 gold badges5 silver badges18 bronze badges
asked Feb 25, 2014 at 22:51
5
  • 6
    I've never seen a sketch that uses serial not do this, so literally any sketch. Commented Feb 25, 2014 at 23:03
  • Related: Arduino serial port reset in Serial monitor & Python Commented Aug 9, 2015 at 19:54
  • Duplicate: Why does my Arduino seems to reboot every time that I open Serial Monitor? Commented Aug 9, 2015 at 20:10
  • I've got a separate problem. The Arduino leostick (and others) don't autoreset anymore. How do I renable it? Commented Oct 6, 2016 at 15:14
  • Weird. I don't think it happens to platformio or Arduino IDE on my Linux laptop, but I just noticed it with pio on Windows. It's a horrible 'feature'. Commented Apr 21, 2021 at 8:56

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

answered Feb 26, 2014 at 0:02
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 ... 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. 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

answered Mar 1, 2014 at 22:24
11
  • The link to your schematic image is broken. 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. 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???? 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. 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)
RSM
1,4571 gold badge11 silver badges26 bronze badges
answered May 13, 2016 at 18:17
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...

answered Jun 29, 2021 at 13:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.