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:
1 |
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:
1 2 3 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#!/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:
1 |
$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.
The first happy user:
http://forums.adafruit.com/viewtopic.php?f=25&t=13339
Another happy user, but using Python !
Same post as above ;-)
Same happy user, different site ;-)
http://disappearingstaircase.blogspot.com/2009/11/ubuntu-arduino-and-ftdi-cable.html
Pingback: Getting Started with Arduino – Chapter Ten « t r o n i x s t u f f