Arduino board resets after reconnecting with USB-port

Hello forum, I want to gather sensor data with my Arduino UNO R3 over some period of time. During this interval I want to power my board with an external power source and not through the USB port of my laptop. After the data has been gathered I want to connect the board to my PC to transfer the data via USB. Unfortunately I noticed that when I start the python-script which I wrote for the communication between laptop and the Arduino, the board resets so that the previously gathered data is lost.

So I would like to ask if my approach is wrong, i.e. connecting a running board to the laptop, or if there might be something wrong with my programms. Perhaps it is important to mention that the external power source yields only 5 volts; though I have never experienced any problems with it before.

Maybe there is an entirely better method to transfer information from an Arduino to a PC to which it was formerly not connected.

If there is some information missing to solve the problem, please tell me what is missing and I will try to supply it.

Many thanks in advance for our help!

You can cut a trace on the board to disable the USB enable. You then have to manually press Reset for a code download, not a big deal.

You can store the data gathered, up to 1024 bytes, in the '328Ps EEPROM. Then a reset won't matter. "The Uno board contains a trace that can be cut to disable the auto-reset. The pads on either side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum thread for details. " Excerpted from this page https://www.arduino.cc/en/Main/ArduinoBoardUno

It is normal for the Arduino to reset when the PC opens the serial port.

One solution is to use a USB-TTL cable connected directly to pins 0 and 1 rather than the normal Arduino USB connector.

...R

It is normal for the Arduino to reset when the PC opens the serial port.

More than that, it was how the Arduino was designed to work.

Another way of disabling the auto reset is to attach a 10uF capacitor between the reset pin and ground.

Thank you for your input: this solves my problem. Using the EEPROM seems to be the simplest solution for my purposes.

It is interesting for the future to learn that opening a serial port by default resets the board and how to work around it.