PICkit 2 as an AVR programmer

From richmondmakerlabs.uk
Revision as of 14:51, 20 June 2024 by IanM (talk | contribs)
Jump to navigation Jump to search

Back to Ian M's profile

We have a Microchip PICkit 2 on the electronics bench. Its probably in the Arduino (Funduino) kit box on the top shelf.

AVRDUDE support

Recent versions of AVRDUDE support Microchip PICkit 2 as an AVR ISP programmer. Use command line option: -p pickit2

Installation (Windows)

I assume you already have AVRDUDE, and possibly a GUI for it installed.

Run Zadig (from https://zadig.akeo.ie/ ) and do 'Options=>'List all devices'. Select the PICkit 2 and install the WinUSB (libusb) driver. If problems occur later return to this step and try the libusbK driver.

Alternatively (my preference) use libusb-win32 and install a filter driver for the PICkit 2 so both AVRDUDE and the PICkit software can use it.

Reverting to PICs

N.B. If not using a filter driver, to revert the PICkit 2 to the original USB HID driver for use with MPLAB or the PICkit 2 GUI or command line PIC programming utility you need to 'De-Zadig' the PICkit 2 by uninstalling it from Device Manager, selecting the option to delete all drivers, then scan for hardware changes to let windows reinstall it.

Arduino IDE Support

To add PICkit 2 as a programmer in the Arduino v1.8x IDE, append the following lines to "C:\Program Files (x86)\Arduino\hardware\arduino\avr\programmers.txt" after making a backup copy:

# User added PICkit 2
pickit2.name=PICkit 2
pickit2.communication=usb
pickit2.protocol=pickit2
pickit2.program.protocol=pickit2
pickit2.program.tool=avrdude
pickit2.program.extra_params=-v -V

Test the installation by selecting PICkit 2 as the programmer in the Arduino IDE and, with an AVR based board selected but no target connected, do 'Burn bootloader'. You should get a long and detailed report ending:

avrdude: MicroChip's PICkit2 Programmer firmware version 2.32.0
avrdude: initialization failed, rc=-2
         Double check connections and try again, or use -F to override
         this check.

Error while burning bootloader.

Connections to an AVR MCU

The PICkit 2 pin 1 is identified by a white arrow on the upper case.

Pin assignments are:

PK2| AVR       |2x3 ISP|2x5 ISP|Breadboard| ATmega328P
pin| Signal    |header |header |ICSP cable| DIP pin
===|===========|=======|=======|==========|==========
 1 - RST       - 5     - 5     - Yellow   - 1 + 10K pullup    
 2 - Vcc Targ. - 2     - 2     - Red      - 7,20 } + 100nF
 3 - Gnd       - 6     - 10    - Black    - 8,22 } decoupling
 4 - MISO      - 1     - 9     - Blue     - 18 (D12)
 5 - SCLK      - 3     - 7     - White    - 19 (D13)
 6 - MOSI      - 4     - 1     - Green    - 17 (D11)
 ┌─┐
>│1│                    ┌───┐
 │2│            ┌───┐   │1 2│
 │3│            │1 2│   │3 4│
 │4│             3 4│    5 6│
 │5│            │5 6│   │7 8│
 │6│            └───┘   │9 o│10
 └─┘                    └───┘   

Also see https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all