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?
-
6I've never seen a sketch that uses serial not do this, so literally any sketch.Cybergibbons– Cybergibbons2014年02月25日 23:03:31 +00:00Commented Feb 25, 2014 at 23:03
-
Related: Arduino serial port reset in Serial monitor & PythonPeter Mortensen– Peter Mortensen2015年08月09日 19:54:23 +00:00Commented Aug 9, 2015 at 19:54
-
Duplicate: Why does my Arduino seems to reboot every time that I open Serial Monitor?Peter Mortensen– Peter Mortensen2015年08月09日 20:10:56 +00:00Commented 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?CMCDragonkai– CMCDragonkai2016年10月06日 15:14:49 +00:00Commented 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'.Eric Duminil– Eric Duminil2021年04月21日 08:56:36 +00:00Commented Apr 21, 2021 at 8:56
4 Answers 4
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.
-
2Arduino 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– scruss2014年10月19日 15:44:41 +00:00Commented Oct 19, 2014 at 15:44
-
1I 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– Peter Mortensen2015年08月09日 11:13:10 +00:00Commented Aug 9, 2015 at 11:13
-
-cont: It was tried on an Arduino Uno R3.Peter Mortensen– Peter Mortensen2015年08月09日 11:21:23 +00:00Commented 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– mhopeng2016年05月14日 04:13:32 +00:00Commented May 14, 2016 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:
-
The link to your schematic image is broken.linhartr22– linhartr222016年08月11日 22:47:18 +00:00Commented Aug 11, 2016 at 22:47
-
1Thank 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– zmo2016年08月14日 10:06:54 +00:00Commented Aug 14, 2016 at 10:06
-
1Yes, 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– Peter Mortensen2018年03月20日 08:53:32 +00:00Commented Mar 20, 2018 at 8:53
-
1How is this an answer? What we suppose to do with this information????GeneCode– GeneCode2018年12月23日 07:51:40 +00:00Commented Dec 23, 2018 at 7:51
-
1It 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– zmo2020年02月19日 13:21:37 +00:00Commented Feb 19, 2020 at 13:21
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)
-
1Please provide some explanation as to why it fixes the issue.Quazi Irfan– Quazi Irfan2021年01月13日 05:23:23 +00:00Commented Jan 13, 2021 at 5:23
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...