Index: arduino.c
===================================================================
--- arduino.c	(revision 841)
+++ arduino.c	(working copy)
@@ -82,13 +82,40 @@
   return 3;
 }
 
+static int arduino_open(PROGRAMMER * pgm, char * port)
+{
+  strcpy(pgm->port, port);
+  serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd);
+
+  /* Clear DTR and RTS to unload the RESET capacitor 
+   * (for example in Arduino) */
+  serial_set_dtr_rts(&pgm->fd, 0);
+  usleep(50*1000);
+  /* Set DTR and RTS back to high */
+  serial_set_dtr_rts(&pgm->fd, 1);
+  usleep(50*1000);
+
+  /*
+   * drain any extraneous input
+   */
+  stk500_drain(pgm, 0);
+
+  if (stk500_getsync(pgm) < 0)
+    return -1;
+
+  return 0;
+}
+
+
 void arduino_initpgm(PROGRAMMER * pgm)
 {
 	/* This is mostly a STK500; just the signature is read
-     differently than on real STK500v1 */
+     differently than on real STK500v1 
+     and the DTR signal is set when opening the serial port
+     for the Auto-Reset feature */
   stk500_initpgm(pgm);
 
   strcpy(pgm->type, "Arduino");
   pgm->read_sig_bytes = arduino_read_sig_bytes;
-
+  pgm->open = arduino_open;
 }
Index: ser_win32.c
===================================================================
--- ser_win32.c	(revision 841)
+++ ser_win32.c	(working copy)
@@ -203,7 +203,21 @@
 	hComPort = INVALID_HANDLE_VALUE;
 }
 
+static int ser_set_dtr_rts(union filedescriptor *fdp, int is_on)
+{
+	HANDLE hComPort=(HANDLE)fd->pfd;
 
+	if (is_on) {
+		EscapeCommFunction(hComPort, SETDTR);
+		EscapeCommFunction(hComPort, SETRTS);
+	} else {
+		EscapeCommFunction(hComPort, CLRDTR);
+		EscapeCommFunction(hComPort, CLRRTS);
+	}
+	return 0;
+}
+
+
 static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen)
 {
 	size_t len = buflen;
@@ -378,6 +392,7 @@
   .send = ser_send,
   .recv = ser_recv,
   .drain = ser_drain,
+  .set_dtr_rts = ser_set_dtr_rts,
   .flags = SERDEV_FL_CANSETSPEED,
 };
 
Index: stk500.c
===================================================================
--- stk500.c	(revision 841)
+++ stk500.c	(working copy)
@@ -73,13 +73,13 @@
 }
 
 
-static int stk500_drain(PROGRAMMER * pgm, int display)
+int stk500_drain(PROGRAMMER * pgm, int display)
 {
   return serial_drain(&pgm->fd, display);
 }
 
 
-static int stk500_getsync(PROGRAMMER * pgm)
+int stk500_getsync(PROGRAMMER * pgm)
 {
   unsigned char buf[32], resp[32];
 
Index: stk500.h
===================================================================
--- stk500.h	(revision 841)
+++ stk500.h	(working copy)
@@ -28,6 +28,10 @@
 
 void stk500_initpgm (PROGRAMMER * pgm);
 
+/* used by arduino.c to avoid duplicate code */
+int stk500_getsync(PROGRAMMER * pgm);
+int stk500_drain(PROGRAMMER * pgm, int display);
+
 #ifdef __cplusplus
 }
 #endif
Index: serial.h
===================================================================
--- serial.h	(revision 841)
+++ serial.h	(working copy)
@@ -52,6 +52,8 @@
   int (*recv)(union filedescriptor *fd, unsigned char * buf, size_t buflen);
   int (*drain)(union filedescriptor *fd, int display);
 
+  int (*set_dtr_rts)(union filedescriptor *fd, int is_on);
+
   int flags;
 #define SERDEV_FL_NONE         0x0000 /* no flags */
 #define SERDEV_FL_CANSETSPEED  0x0001 /* device can change speed */
@@ -69,5 +71,6 @@
 #define serial_send (serdev->send)
 #define serial_recv (serdev->recv)
 #define serial_drain (serdev->drain)
+#define serial_set_dtr_rts (serdev->set_dtr_rts)
 
 #endif /* serial_h */
Index: ser_avrdoper.c
===================================================================
--- ser_avrdoper.c	(revision 841)
+++ ser_avrdoper.c	(working copy)
@@ -634,6 +634,14 @@
 
 /* ------------------------------------------------------------------------- */
 
+static int avrdoper_set_dtr_rts(union filedescriptor *fdp, int is_on)
+{
+	fprintf(stderr, "%s: AVR-Doper doesn't support DTR/RTS setting\n", progname);
+    return -1;
+}
+
+/* ------------------------------------------------------------------------- */
+
 struct serial_device avrdoper_serdev =
 {
   .open = avrdoper_open,
@@ -641,6 +649,7 @@
   .send = avrdoper_send,
   .recv = avrdoper_recv,
   .drain = avrdoper_drain,
+  .set_dtr_rts = avrdoper_set_dtr_rts,
   .flags = SERDEV_FL_NONE,
 };
 
Index: ser_posix.c
===================================================================
--- ser_posix.c	(revision 841)
+++ ser_posix.c	(working copy)
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
@@ -210,6 +211,36 @@
   fdp->ifd = fd;
 }
 
+
+static int ser_set_dtr_rts(union filedescriptor *fdp, int is_on)
+{
+  unsigned int	ctl;
+  int           r;
+
+  r = ioctl(fdp->ifd, TIOCMGET, &ctl);
+  if (r < 0) {
+    perror("ioctl(\"TIOCMGET\")");
+    return -1;
+  }
+
+  if (is_on) {
+    /* Clear DTR and RTS */
+    ctl &= ~(TIOCM_DTR | TIOCM_RTS);
+  }
+  else {
+    /* Set DTR and RTS */
+    ctl |= (TIOCM_DTR | TIOCM_RTS);
+  }
+
+  r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+  if (r < 0) {
+    perror("ioctl(\"TIOCMSET\")");
+    return -1;
+  }
+
+  return 0;
+}
+
 static void ser_open(char * port, long baud, union filedescriptor *fdp)
 {
   int rc;
@@ -455,6 +486,7 @@
   .send = ser_send,
   .recv = ser_recv,
   .drain = ser_drain,
+  .set_dtr_rts = ser_set_dtr_rts,
   .flags = SERDEV_FL_CANSETSPEED,
 };
 
