Arduino Mega2560 resets every time I connect via USB

I am seeing some odd behavior with Mega2560. Every time I try to connect to the USB port from a computer, the Arduino resets as soon as I open the port.

As I understand it, the hardware flow control lines over USB is used to reset the Arduino in order to access the bootloader and flash Arduino over the USB port.. but no amount of enabling/disabling hardware or software flow control seems to change the resetting. I've read that OSX has a tendency to ignore the disabling of flow control and use it anyway, but I see the same thing running on Linux.

I am using PySerial and this can be replicated with just using the PySerial 's builtin test app "miniterm.py"

miniterm.py --dtr 0 --rts 0  /dev/ttyACM0 115200

Any suggestions on how to open the port without resetting the MCU?

Thanks

-HH

You can disable auto reset by connecting a 10 uF capacitor between reset and ground.

You can also cut the "reset-en" jumper on your board.

Note that if auto-reset is disabled when you upload you will need to manually reset the microcontroller.

As for doing it in software, it seems like it should be possible but I've never tried it.

hichhiker:
Any suggestions on how to open the port without resetting the MCU?

With my Python programs I just open the serial port once, wait for the reset to complete, and keep the serial port open until the Python program is completely finished with the Arduino.

If it really is necessary to connect to the Mega without causing a reset then a simple way is to use a USB-TTL cable to connect directly to the Rx and Tx and GND pins. On a Mega you could connect to Rx1 and Tx1 (Serial1) and leave Serial free for uploading programs and debug messages.

...R
Python - Arduino demo

Robin2:
With my Python programs I just open the serial port once, wait for the reset to complete, and keep the serial port open until the Python program is completely finished with the Arduino.

If it really is necessary to connect to the Mega without causing a reset then a simple way is to use a USB-TTL cable to connect directly to the Rx and Tx and GND pins. On a Mega you could connect to Rx1 and Tx1 (Serial1) and leave Serial free for uploading programs and debug messages.

...R
Python - Arduino demo

Thanks. Unfortunately none of these are desired options for my use-case. I am being asked to use the USB port for both ability to flash and to communicate with the device (It works great on secondary HardwareSerial ports, and that was the solution I was proposing, but that is not what they want). And just accepting the reset is not an option because reset triggers a lengthy re-calibration cycle and loses the real-time state we would like to see.

I will see if I can work around some of the above issues, but ideally I hoping to find a software solution. Is there any documentation someone can point me to as to how this works? I imagine it has something to do with the 16u2 firmware...

Thanks.

-HH

Just a quick follow up - I came across a promising lead - raspbian - Disable DTR on ttyUSB0 - Raspberry Pi Stack Exchange

This says that the automatic toggling of the DTR can be controlled by the Linux software driver, which seems to work, albeit imperfectly (still resets the Arduino on the first connection, but not on subsequent ones). Still, it moves the problem into the Linux world, where I am pretty sure it is solvable somehow - just need to figure out how to make the setting take effect before the first connection.

-HH

1 Like