Getting auto reset to work with FTDI cables on Linux (MAC)


Update: please use avrdude 5.11 or later with “-c arduino” and your problems are gone!


Before you start, make sure you have the perl module Device::SerialPort installed ! On Debian based systems, you can easily do that by typing:

sudo apt-get install libdevice-serialport-perl

If it doesn’t work or you’re on a different flavour of linux, you can still use CPAN to pull in that module:

sudo perl -MCPAN -e shell
install Device::SerialPort
exit

You may have to answer a few questions, but in doubt pressing ENTER is also OK. As CPAN might have to compile some C code, having gcc and depending libraries installed is mandatory.

Now back to the main topic:

Here’s just a little Perl script you can put into the “./hardware/tools” folder of your Arduino IDE. Rename “avrdude” to “avrdude_bin”. Create a file named “avrdude” in said folder and change its permissions to “rwx——” (0700). Now copy the following Perl code into it and save.

#!/usr/bin/perl

use Device::SerialPort;

$avrdude = "./hardware/tools/avrdude_bin";
my $line;
my $opt_string;
my $pulse_time = 100; # time in ms

for $line (@ARGV) {
        $opt_string .= "\ ";
        $opt_string .= $line;
}

my $serial_port;
$opt_string =~ m/.*-P(\/dev\/\w*)\ -.*/; # looks for names with letters/numbers/_ ( no . )
$serial_port = $1;

print "Serial Port: ",$serial_port;

my $link = Device::SerialPort->new("$serial_port") || die("could not open port: $serial_port - $!");

$link->pulse_rts_on($pulse_time);
$link->pulse_rts_off($pulse_time);

$avrdude .= $opt_string;
system($avrdude);

The script extracts the serial port from the string passed to avrdude by the IDE. Then it creates the reset pulse by changing the level of the RTS line. Then it just calls avrdude_bin as usual. This little hack is necessary as the IDE uses the DTR line to reset the Arduino. The FTDI cables break out the RTS line instead of DTR.

Hint for MAC users:

Depending on how the virtual serial port is named on your system, maybe something like /dev/cua.usbserial…. , you’ll have to adjust the REGEX which extracts the serial port from the avrdude call. This happens here:

$opt_string =~ m/ ... ... ...

Flashing the bootloader with the Arduino IDE:

This Perl script currently conflicts with that method, as the REGEX match can’t find a serial port in that case. You can still flash the bootloader by hand quite easily.

This entry was posted in Arduino., Electronics. and tagged , , , , . Bookmark the permalink.

4 Responses to Getting auto reset to work with FTDI cables on Linux (MAC)

  1. robert says:

    Another happy user, but using Python !

    Same post as above ;-)

  2. Pingback: Getting Started with Arduino – Chapter Ten « t r o n i x s t u f f

Comments are closed.