New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Uno resets every time my Pi script opens /dev/ttyUSB0

DTR is one of the old modem control lines. On the Uno it goes through a 100 nF capacitor to the reset pin, so the IDE can reset the board before an upload. Any program that opens the port toggles DTR, so the board resets. I fought this on a line counter at work last year.

Software side, two things together:

stty -F /dev/ttyUSB0 -hupcl     # don't drop DTR when the port closes

ser = serial.Serial()
ser.port = '/dev/ttyUSB0'
ser.baudrate = 9600
ser.timeout = 2
ser.dtr = False
ser.open()

Be warned that on Linux the driver may still raise DTR for a moment on the very first open after boot, so this reduces resets, it doesn’t always kill them.

The sure fix is hardware: a 10 µF capacitor between RESET and GND on the Uno, minus to GND. That swamps the reset pulse. You then have to pull it out (or press reset by hand at the right moment) when you upload new firmware.

And for the drops in your total: also keep the count in EEPROM every few minutes, or have the Uno send a running total since it was flashed instead of since boot. A reset then costs you a few pulses, not the whole total.

Ground loops are my cardio.
Accepted solution♥ 5