Traducido del English por IA ·
DTR es una de las antiguas líneas de control de módem. En el Uno pasa por un condensador de 100 nF hasta el pin de reset, para que el IDE pueda reiniciar la placa antes de cargar un programa. Cualquier programa que abra el puerto cambia DTR, y la placa se reinicia. Yo me peleé con esto en un contador de líneas en el trabajo el año pasado.Por el lado del software, dos cosas juntas:
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()
Ojo: en Linux, el controlador puede seguir activando DTR un momento en la primera apertura tras el arranque, así que esto reduce los reinicios, pero no siempre los elimina.La solución segura es el hardware: un condensador de 10 µF entre RESET y GND en el Uno, con el negativo a GND. Eso absorbe el pulso de reset. Después tienes que quitarlo (o pulsar reset a mano en el momento adecuado) cuando subas un nuevo firmware.Y para las caídas en tu total: guarda también el conteo en la EEPROM cada pocos minutos, o haz que el Uno envíe un total acumulado desde que se flasheó en lugar de desde el arranque. Así, un reinicio te costará unos pocos pulsos, no todo el total.
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.

