Programming PIC microcontroller with Raspberry Pi
PICPgm is a free and simple In-System-Development programmer Software for the Microchip PIC microcontrollers. The programmer is available for Windows an Linux. Here I want to explain how to use the command line version of PICPgm together with the Raspberry Pi.
For more details regarding PICPgm visit the the PICPgm website: http://picpgm.picprojects.net.
The following commands download and install PICPgm on your Raspberry Pi:
cd ~ mkdir picpgm_install cd picpgm_install wget http://picpgm.picprojects.net/download/picpgm-188.8.131.52-linux-armhf.tar.gz tar xzvf picpgm-184.108.40.206-linux-armhf.tar.gz sudo ./install.sh cp pgmifcfg.xml ~
Running PICPgm on Raspberry Pi
PICPgm on the Raspberry Pi uses the GPIO pins to communicate with the PIC. The following diagram shows a very simple PIC programmer circuit for the Raspberry Pi. Since the voltage level on the Rapsberry Pi GPIO pins is 0V or 3.3V, this simple programmer shall only be used for PIC which work with 3.3V supply voltage.
WARNING: Do not use this circuit for PICs which operate at 5V. If you do that, it will damage your Raspberry Pi!
The GPIO pins used in the diagram above are only available on the new Raspberry Pi A+/B+. If you use older Raspberry Pi version or want to use other GPIO pins, you can change the used pins in pgmcfgif.xml which comes along with PICPgm.
The syntax of the configuration filename should be self explaining. The name attibute tells PICPgm the function of the pin and the pin attribute describes the GPIO pin number to be used. So for the above configuration, the programmer configuration looks like that (already preconfigured in delivered PICPgm package):
<PgmIf name="GPIO Programmer (Raspberry Pi)" typ="LVP" connection="GPIO"> <PinCfg name="MCLR" pin="5" invert="0" /> <PinCfg name="PGM" pin="6" invert="0" /> <PinCfg name="CLK" pin="13" invert="0" /> <PinCfg name="DOUT" pin="19" invert="0" /> <PinCfg name="DIN" pin="26" invert="0" /> </PgmIf>
Since PICPgm uses memory mapped access to the GPIO pins (required to allow fast GPIO access), you need to run PICPgm with root permissions. I.e. to check whether the programmer circuit is working fine, you could ask PICPgm to check the connection by the following command:
sudo picpgm -r
Now you can program "yourhexfile.hex" with the following command:
sudo picpgm -p yourhexfile.hex