sync-signal.com audio, video, electronics and code

8Jan/106

Getting Started with a PICkit2 on Ubuntu 9.10

This Christmas I received a PICkit2. Unfortunately the support for Linux is nothing like it's support for Windows.  Here's a quick guide on getting things working in Ubuntu 9.10 (Karmic Koala).

Firstly you're going to want to setup udev to give your account access to the programmer. The original instructions can be found here. Start by creating a group 'microchip' and then give your account access to that group.

sudo addgroup microchip
sudo addgroup <username> microchip

Then create the file '/etc/udev/rules.d/026_microchip.rules' and add the following contents to it. Don't forget to prefix your editor with 'sudo' e.g. 'sudo nano /etc/udev/rules.d/026_microchip.rules'.

#PICKit
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="0032", MODE="0660", GROUP="microchip"
#PICKit2
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="0033", MODE="0660", GROUP="microchip"
#ICD2
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="8000", MODE="0660", GROUP="microchip"
#ICD21
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="8001", MODE="0660", GROUP="microchip"

Now restart.

pk2cmd

pk2cmd is the program that you're going to use to flash the PIC chip. It's available here, Scroll down to 'Downloads' and grab the 'Mac OS X Source Code with Makefile'.

Now extract and compile like so.

tar xzf pk2cmdv1.20LinuxMacSource.tar.gz
cd pk2cmdv1.20LinuxMacSource
make linux

If you get an error 'make: command not found' you'll need to install Ubuntu's build-essential package.

sudo apt-get install build-essential

To install pk2cmd you need to place it and PK2DeviceFile.dat somewhere on your path. The easiest way is to copy it to '/usr/bin'

sudo cp pk2cmd /usr/bin/
chmod -x PK2DeviceFile.dat
sudo cp PK2DeviceFile.dat /usr/bin

Testing it out

Now you've got everything setup you can start talking to your PICkit2. To make sure everything works plug in your PICkit2 and the demo board and run these two commands.

pk2cmd -?V
pk2cmd -P

You should see some output like this:

$ pk2cmd -?V

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

Operation Succeeded

$ pk2cmd -P
Auto-Detect: Found part PIC16F690.

Running some Code

On the PICkit CD there are 12 lessons, they can be found in 'Install/Lessons/Low Pin Count Demo Board'. They contain example code, an assembled HEX program, and an MPLab IDE project.

Here's the command to write, verify and run a HEX program. In this case, Lesson 03.

pk2cmd -P -M -FRotate.HEX -Y -T

To break it down:

  • -P - The chip type you're writing to. Omitting it will make PICkit2 attempt to detect the type. If it fails with 'No known part found' try specifying the chip type like -PPIC16F690 for the PIC16F690
  • -M - The region of memory to write to. As there is no region specified it'll write to the entire of the chip.
  • -FRotate.HEX - The HEX file you wish to write. In this case 'Rotate.HEX'.
  • -Y - Verify after writing. Like -M, you can indicate the region you wish to verify.
  • -T - Power the circuit after completion. This will provide your circuit with the chips Vdd allowing your program to run.

There are a lot more flags to pk2cmd, to see them all and get a description of what they do, run pk2cmd with no arguments.

Comments (6) Trackbacks (0)
  1. Thanks for the tutorial!
    I had two minor problems on my ubuntu 9.10 karmic koala.
    1) Some files were reported as not found while compiling although they were present in the source folder. Debug messages pointed to include statements where i changed brackets form to claws “file_to_be_included.h”

    2) “/usr/bin/ld: cannot find -lusb” error while running make
    Installing libusb-dev solved it for me.
    Hopefully this helps someone.

  2. Thanks! It worked, but when I typed:

    $ pk2cmd -P
    PK2DeviceFile.dat device file not found.

    It’s a permission problem:

    /usr/bin$ ls -l PK2DeviceFile.dat
    -rw——- 1 root root 156449 2010-03-14 17:25 PK2DeviceFile.dat

    So I had to change owner of the file (roberto is both my name and my primary group):

    sudo chown roberto:roberto /usr/bin/PK2DeviceFile.dat

    Thanks again!

  3. Hi, thanks for your tutorial. I’m trying to install everything, I hope it works. Do you have any suggestion about the HEX editor to use? Some years ago I used piklab, because it had also the debugger. I remeber though I had to struggle a lot to have everything working….

  4. In my case I had to install both build-essential and libusb-dev to compile pk2cmd.

  5. Thanks for the howto. I can get it to work if I type ” sudo sudo pk2cmd -?V ”

    but when I type pk2cmd only I get

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

    I have added me to the group microship. is there anything ells I should do?

  6. Does anyone know how to debug with pickit under linux?? I dont have any idea about this… Can anyone help me?? Thanks..


Leave a comment


No trackbacks yet.

Recent Posts

Tags

Electronics Equaliser Fluxus Guide JACK Karmic Live Coding lucid PIC PICkit2 Project Projects Pulseaudio Python StagFS TVRage TVSlurp Ubuntu Undrawing Usenet Video

Archives

Blogroll