The Arduino boards have a cool feature built into them that allows them to be programmed easily. That is, when the serial/comm port is opened, the board will automatically reset.

I discovered this when developing the firmware for ArDewNo. Every time I made a connection to the serial port, the board would reset. This is good for ease of programming but bad for long running applications that may establish connections during the middle of execution.

The Arduino reset pin is held high via a 10K resistor during use, allowing the CPU to operate normally. When the button is pushed, the voltage on the reset pin is momentarily pulled down to 0v resetting the CPU.

When the comm port is opened, the driver pulls DTR low. This in turn, causes the voltage on the reset pin to drop to 0v. The 100nf capacitor then quickly charges up through the 10K resistor allowing the CPU to operate again.

The oscilloscope screenshot shows this behaviour. Channel A is the blue trace shown on top and is connected to the reset pin. Channel B is the yellow trace on the bottom and is connected to the DTR line.

We can see that when the serial port is opened and the DTR line is pulled low, reset is immediately pulled low before returning high again approximately 1 to 2 milliseconds later.

The following C++ code is used to demonstrate what happens to the microcontroller when the serial port is opened and the chip resets.

#include <Arduino.h>

bool a = false;

void setup() {
  // Output pin 2 high briefly so we can see when the
  // Arduino has been reset
  digitalWrite(2, HIGH);
  delay(1);
  digitalWrite(2, LOW);
}

void loop()
{
  // Toggle pin 3 so we can see when the
  // Arduino is running
  a = !a;
  digitalWrite(3, a);
  delayMicroseconds(100);
}

Using a logic analyser, we can see that when the DTR line is pulled low after opening the serial port on my laptop, the reset line is briefly pulled low disabling the activity on pin 3.

After a delay of around 1.5s, the MCU is rebooted and starts executing the setup() method as seen by pin 2 being toggle high.

These 2 tests confirm that when the serial port is opened on the computer side, the arduino will reset and lose any state currently held before restarting execution from the main entry point of the program again.

This may be a desired feature in a few cases, but for an arduino controlled go-to mount (for example) this would get rather annoying if the telescope lost track of what it was pointed at when you connected to it.

So how do we stop it?

Temporary method

Adding a 10uF (ish) capacitor between GND and RESET.

This solution is where the modification needs to be reversible. However, it may effect the behaviour of the manual push button the board. It may need to be pushed and held for slightly longer.

We can see that when the serial port is opened and the DTR line (yellow/bottom) is pulled low, the RESET line (top/blue) barely even drops 0.1v. The 10uF capacitor provides enough of a buffer to stop the RESET line from falling far enough to reset the chip.

Permanent Method

Either remove the capacitor between the DTR and RESET lines or cut the trace. This will prevent the chip from ever being reset without any extra components.

This is a good solution where the board will be permanently installed into a project.

Drag the slider on the next image to see the capacitor removed. Be aware that your board may differ slightly.

Can I Still Upload Firmware?

Of course! However; uploading firmware will no longer work automatically.

When uploading firmware, you will need to manually press the reset button on the board at the right time, just after the terminal says "Uploading firmare". There's a window of a number of seconds to be able to do this though so it's not difficult to execute.