How to use the PICkit2 programmer under Linux

I’ve been using the Microchip PICkit2 development programmer for a long time now, under Windows and Linux :), it’s a very good piece of hardware and I think the recommended companion for hobby PIC micro controller developers.

These days I had to install the software for Ubuntu Lucid (32 bits) at work, and I think I’ll list the required steps to have it working so that I don’t forget them ;), and maybe it can be of help.

  1. Download pk2cmd source code for Linux/Mac OS X (it’s a command line application), you can get the code from the official PICkit2 page under the Linux and Mac OS X Software section at the bottom of the page or using this link: pk2cmdv1.20LinuxMacSource.tar.gz
  2. Uncompress the file and cd to the directory
    $ tar xzvf pk2cmdv1.20LinuxMacSource.tar.gz
    $ cd pk2cmdv1.20LinuxMacSource
  3. Make sure you have libusb development files:
    $ sudo aptitude install libusb-dev
  4. Build the application for linux (this is for Linux kernels 2.6, for older kernels and/other systems (FreeBSD, Mac) check the ReadmeMakefile.txt file.)
    $ make linux
  5. Make install as root
    $ sudo make install
  6. The device definitions file is copied to /usr/share/pk2/ directory, in order to be able to access it this directory should be in your path. To add it, edit your .bashrc file (in your home directory) and add these lines at the beginning:
    export PATH
  7. Test your installation:
    $ pk2cmd -?v

    If PICkit2 is not present (plugged in), you get:

    Executable Version:    1.20.00
    Device File Version:   1.55.00
    OS Firmware Version:   PICkit 2 not found
    Operation Succeeded

    If PICkit is plugged:

    Executable Version:    1.20.00
    Device File Version:   1.55.00
    OS Firmware Version:   2.32.00
    Operation Succeeded

For instructions on how to use pk2cmd execute it using the -?h parameter. As an example, if you want to program a sample.hex file to a pic16f84a you’d execute:

$ pk2cmd -ppic16f84a -fsample.hex -m

The output would be

PICkit 2 Program Report
3-7-2010, 9:55:24
Device Type: PIC16F84A

Program Succeeded.

That’s it. If you get an error message indicating that PK2DeviceFile.dat file can not be found, confirm whether /usr/share/pk2/ directory is in your path.

I have worked successfully with several micro controllers (12F508, 12F629, 12F683, 16F84, 16F628, 16F88, 18F2550 and 18F4550), under Ubuntu 32 and 64 bits without any major problem (sometime ago I read about some issues working under Ubuntu 64 bits, but I tried and didn’t find any).


  1. I tried to make this application on Ubuntu Lucid but this error message apears:

    $make linux
    make TARGET=linux
    make[1]: se ingresa al directorio «/home/becario/Escritorio/programando_PIC_en_Ubuntu/pk2cmdv1.20LinuxMacSource»
    g++ -Wall -D_GNU_SOURCE -O2 -I/usr/local/include -DLINUX -DUSE_DETACH -DCLAIM_USB -o pk2usbcommon.o -c pk2usbcommon.cpp
    In file included from pk2usbcommon.cpp:32:
    pk2usb.h:49:26: error: usb.h: No existe el fichero o el directorio
    pk2usbcommon.cpp: In member function ‘void CUsbhidioc::CloseReport()’:
    pk2usbcommon.cpp:648: error: ‘usb_release_interface’ was not declared in this scope
    make[1]: *** [pk2usbcommon.o] Error 1
    make[1]: se sale del directorio «/home/becario/Escritorio/Programando_PIC_en_Ubuntu/pk2cmdv1.20LinuxMacSource»
    make: *** [linux] Error 2

    I don know how to correct this error!!!!

  2. Excelente.. funciona:

    Release 13 (maya) 64-bitKernel
    Linux 3.2.0-23-generic
    GNOME 3.4.1
    Memory:5.8 GiB
    Processor:Intel® Core™2 Duo CPU P8700 @ 2.53GHz × 2

    Exactamente como lo tienes.
    Solo tuve que crear:
    gedit /home/martin/.bashrc

    Probar con: pk2cmd -?v
    Executable Version: 1.20.00
    Device File Version: 1.55.00
    OS Firmware Version: 2.32.00

    Hasta aqui todo ok…

    Querétaro, México

  3. Hello !

    I’ve just bought my Pickit 2 and I want to compile it to include a custom PK2DeviceFile.dat file which enables my PIC18F46K22. This file works without problem with the GUI pickit2 programmer on windows, but when I compile pk2cmd on linux, here is my error :

    pk2cmd -?v
    PK2DeviceFile.dat device file requires an update of pk2cmd.

    Executable Version: 1.20.00
    Device File Version: not found
    OS Firmware Version: 2.32.00

    What can I do ?

    Thanks a lot for this great guide !

  4. Hello I get this error “illegal instruction”

    root@ip2a:/home/test/pk2cmdv1-20Linux2-6/2/pk2cmdv1-20Linux2-6# ./pk2cmd -M -PPIC16F1827 -A3.3 -Ftest.hex
    Illegal instruction

    Any help will be appreciated

  5. Firmware / Source Code / Executables for Win, Linux & OSX.

    I guess setup_A is for win, the source v1.00 is for visualc++ (an old edition… wonder if newer visual studio releases can open& build it without making a big issue of it…

    The linux source needs or something like that FOR i386 (the 32bit basic binary libraries… not mmx/sse*/etc… the basic libraries for intel/amd/etc runable compatibilities. if u have debian, add the i386 plataform to ur system binland… and if ur distro is basicly i386 based, then probably libusb is already there.

    read the readme in the source directory if u dont get how to make the source… (tip: make linux… here)

    PS: i tought i was never gonna get the official pk2cmd software for my pickit2, i tried my google tricks and nothing so… gladdly i had backuped the links some time ago… so….


    7fba423ac4614ef3b4bdbb9fea59ad37e77ff7f96762eac4aeaa5d546b6f6651 PICkit 2 v2.61.00 Setup
    ba213a49be558d4628db777f66b63246b05d3c76440cc4bd85d185ec0c44f798 pk2cmdv1-20Linux2-4.tar.gz
    17b05834b52f90b203ae907209c48ca2fdd1d07164bb07cb6e8c71b1dd738473 pk2cmdv1-20Linux2-6.tar.gz
    903027de5036eda3a648decece4acfcefe91e754ef0d4eacba0e5ba8b18857fa pk2cmdv1.20LinuxMacSource.tar.gz

    a54fc9b572e1442b07e6a3a7c0ea92d9 PICkit 2 v2.61.00 Setup
    f97b7abe3fb70796002708b422e02379 pk2cmdv1-20Linux2-4.tar.gz
    d292c61e587876f8fed7900cd53b32e2 pk2cmdv1-20Linux2-6.tar.gz
    07c102f4e2d96cf03c6ea6420533265c pk2cmdv1.20LinuxMacSource.tar.gz

Leave a Reply

Your email address will not be published.