[TUT] [UTIL] Programming ATmega with PICKit2 on Mac OSX

1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is what I had to do to be able to program ATmegas on a Mac with a PICKit2. It is known that the same method works on Linux, but OSX requires a little change in the code.

Prerequisites: Macports should be installed and build system should be sane. I tested this on Snow Leopard. Essential knowledge of Unix environment and GNU build tools. libusb from Macports should be installed.

These steps may be incomplete. I have replayed the entire process anew and it seems to work, but on a fresh install some problems may appear. Please let me know how it went for you.


  1. Get pk2 (pk2-3.00-alpha12.tar.gz) tool from http://home.pacbell.net/theposts... Compile it. Use pk2 -on, pk2 -off to turn on/off the power supplied by the PICKit2 if your AVR board is not self-powered.
  2. Get avrdude 5.10 sources from savannah.nongnu.org
  3. Get avdude pickit2 patch from http://savannah.nongnu.org/patch...
  4. Unpack the sources and apply the patch:

    tar zxvf avrdude-5.10.tar.gz
    cd avrdude-5.10
    patch -p0 <../avrdude_pickit2.patch

  5. In the file pickit2.c around line 1266, change:

    if ((errorCode = usb_set_configuration(handle, 1)) < 0)


    if ((errorCode = usb_set_configuration(handle, 2)) < 0)

    to make it a CONFIG_VENDOR intitalization. For some reason CONFIG_HID didn't work for me.

  6. Open avrdude.conf.in. Locate the lines that describe pickit2 programmer and move or copy them before @HAVE_PARPORT_BEGIN@ line. On Mac avrdude is never compiled with HAVE_PARPORT.
  7. You need to regenerate the makefiles.

    aclocal && automake

  8. Make sure that libusb is installed and that configure script can find all its headers and libs. Run configure.

    CFLAGS=-I/opt/local/include LDFLAGS=-L/opt/local/lib LIBS=-lusb ./configure --prefix=/opt/local

  9. run make and install

    make && make install

If no errors were reported, congratulations. You should now be able to program your ATmega's with a PICKit2, from Mac, natively, in batch mode, without having to use Windows with funny software.

This is how the programmer is invoked in my script:

# this programs atmega8 for internal RC oscillator @ 8MHz -- calibration may be required
avrdude -p m8 -c pickit2 -U hfuse:w:0xdc:m -U lfuse:w:0xe4:m
avrdude -p m8 -c pickit2 -U flash:w:"mouse+boot.hex":i -v -V -u 

It is recommended to have the original PICKit2 utility (Windows-only I'm afraid) handy in case something goes wrong and the programmer would have to have its OS reflashed.

The connections are described on the patch page, but here's a copy for your convenience:
ISP Pinout

AVR   - PICKit2 (pin)):
RST   - VPP/MCLR (1)
VDD   - VDD Target (2) -- possibly optional if AVR self powered
GND   - GND (3)
MISO  - PGD (4)
SCLK  - PDC (5)
MOSI  - AUX (6) 

Similar approach should work in Windows too, but I do not have any motivation to try. Alternatively, you can try the method described at http://pickit2.isgreat.org/

The Dark Boxes are coming.