Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

Using the AVR ISP mkII (USB) to burn the bootloader on MacOS X

--interjecting here-- See the bottom of this article; I was successful on MacOS X 10.6 w/ Arduino 0022 just editing /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/programmers.txt and telling it to use "serial" for the avrispmkii rather than "usb". No compiling necessary. --

In order to use the AVR ISP mkII on MacOS X, you need to install avrdude and libusb. To do so, make sure that you have the Developer Tools (XCode) installed. They usually come bundled with every Mac and are also available as a free download from http://developer.apple.com after a (free) registration.

You can use Fink to install them, and it will get the sources and build them for you:

fink install libusb avrdude

You can also compile the necessary software yourself. First, download the latest versions of the following software

Once you have downloaded the latest versions of the above software, open a Terminal window and move the packages to a place to unpack and compile them (I usually do that in /tmp). To unpack them, use these commands (substituing the correct filenames if they are different for you).

tar xvfz libusb-0.1.12.tar.gz
tar xvfz avrdude-5.1.tar.gz

Next, you should decide a place to install the software to in order to keep your base system tidy. I suggest installing them into a subdirectory named "bootloader-usb" in the Arduino folder. Assuming you have Arduino installed in /Applications, use the following command (or subsitute any folder of your choice. It needs not exist yet.). It should, however, be an absolute path (starting with /)

IDIR=/Applications/Arduino/bootloader-usb

Now it's time to compile libusb. Issue the following commands (substituting the correct filename if necessary. Also, sudo in the last step may not be necessary if the folder where you want to install to is writeable by your current user (for example, if it's somewhere in your home folder)).

cd libusb-0.1.12/
./configure --prefix=$IDIR
make
sudo make install

With libusb installed, you need to compile avrdude with support for libusb. To do so, issue the following commands (again, substitute correct filenames; sudo may not be necessary)

export CFLAGS=-I$IDIR/include
export LDFLAGS=-L$IDIR/lib
cd avrdude-5.1/
./configure --prefix=$IDIR
make
sudo make install

Make sure that during the output of "configure", a line such as

checking for usb_get_string_simple in -lusb... yes

pops up somewhere. This means that the libusb you have just installed was found by the avrdude build scripts and will be used. If it says "no" here, make sure that you correctly installed libusb and didn't mistype those two "export" commands before building avrdude.

Now that you have both libusb and avrdude installed, copy the ATmegaBOOT.hex from the "bootloader" directory inside the Arduino package into your installation directory. Use the latest bootloader from the Arduino 004 distribution.

cp /Applications/Arduino/bootloader/ATmegaBOOT.hex $IDIR

Finally, create a file named "burn-bootloader-usb.command" (or whatever) in $IDIR and make it executable.

chmod a+x burn-bootloader-usb.command

Paste the following shell code into this file. This burn script was provided by Arduino Forum user mehel. Thanks! (Slight changes to make it work both by double-click and command line invocation).

#!/bin/sh
IPATH=`echo $0 | sed s/[^\/]*$//`;
CMD="$IPATH/bin/avrdude" 
OPTS="-p m8 -b 115200 -P usb -c avrispmkII" 

# Erase chip write lock and fuses 
$CMD $OPTS -e -U lock:w:0x3f:m -U lfuse:w:0xdf:m -U hfuse:w:0xca:m  

# Upload bootloader code 
$CMD $OPTS -D -U flash:w:ATmegaBOOT.hex:i 

# Lock boot section 
$CMD $OPTS -U lock:w:0x0f:m 

Save the file.

To burn a bootloader onto an ATMEGA8 microcontroller now, hook up the AVR ISP mkII to an USB port of your computer, connect the Arduino board with the new microcontroller installed to an external power supply (you may need to set the jumper correctly) and connect the ISP to the Arduino board's ISP port. The LED on the ISP should light green if everything is hooked up correctly, otherwise, re-check all connections or try unplugging and re-plugging the ISP cable into the Arduino board.

If the light is green, double-click burn-bootloader-usb.command or execute it from a shell. You should now see some messages flying by. Check them for any errors. If no errors occurred, the bootloader is now burned into the microcontroller. To check, connect a LED between digital pin 13 and GND and press the reset button. The LED should flicker briefly.

I noticed that sometimes, avrdude can't find the AVR ISP mkII even though it's connected. In that case, rebooting usually solves the problem.

UPDATE

For folks running Snow Leopard and Xcode 4 (at least this is my configuration), libusb0 won't compile anymore and avrdude (latest version = 5.10 as of this update) does not compile against libusb1 yet. You will need to compile libusb 1.0 first and then obtain libusb-compat-0.1 -- http://sourceforge.net/projects/libusb/files/libusb-compat-0.1/

Note that libusb-compat-0.1 expects to find libusb1 using Pkgconfig, so make sure that's installed and you've set PKG_CONFIG_PATH correctly. I used MacPorts to get & compile libusb (it automatically went for the 1.0 version) and pkgconfig and everything went in /opt/local, so PKG_CONFIG_PATH=/opt/local/lib/pkgconfig

After installing libusb1 and libusb-compat-0.1, I was able to compile avrdude-5.10 using:

 export CFLAGS=-I/opt/local/include
 export LDFLAGS=-L/opt/local/lib
 ./configure --prefix=/Application/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr-510
 make
 sudo make install

... After going through that, it still wouldn't burn a bootloader for me, so I looked further and if you edit this file-- /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/programmers.txt -- change the line "avrispmkii.communication=usb" to "avrispmkii.communication=serial". Just burned the bootloader to three ATmega8 chips and they all worked perfectly, even with the Arduino IDE's stock version of avrdude.