The circuit for this project is quite simple. Its purpose is to adapt the GPIO pins of the Raspberry Pi to the voltages expected by the PIC. It also provides LEDs for diagnostic purposes.
Since different devices have different pinouts, I recommend that you build this circuit on a breadboard. Of course, you could adapt it for strip board, but I would suggest providing a mechanism to rewire the connections to the IC socket.
You could safely omit the diagnostic and testing LEDs. You will need to supply 12V externally to this circuit, as the Raspberry Pi does not have a voltage source that produces that high a voltage, and also make connectors to connect the Raspberry Pi to the circuit. I recommend connecting the GPIO to match the defaults for the software:
|Line||Default GPIO Pin|
|Data Out Control||25|
|R1, R2, R3, R6, R7, R11, R12, R16, R17||9||10kΩ, ±5%, 0.25W|
|R4, R5, R8, R9, R10, R13, R14, R15, R18, R19, R20, R21, R22||13||1kΩ, ±5%, 0.25W|
|C1, C2||2||1μF, 25V|
|LED1, LED2, LED3, LED4, LED5, LED6||4||General purpose standard or low power LED|
|Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8||8||General purpose NPN BJT transistor||BC548|
|VR1||1||12V linear voltage regulator||L7812CV|
|VR2||1||6V linear voltage regulator||L7806CV|
|IC1||1||A supported PIC microcontroller||PIC16F628|
I'm currently working on specific links for these components, but I've had good experience with Farnell element14 - Electronics Distributor and they have a good selection.
Currently, some of Microchip's 12 bit and 14 bit devices are supported (technically, 8 bit data word size, but 12/14 bit program word size):
- PIC16F628 (14 bit auto-detected; recommended for beginners)
- PIC16F54 (12 bit; recommended for advanced users only)
- PIC16F627 (14 bit auto-detected)
- PIC16F872 (14 bit auto-detected)
It would not be difficult to add support for more similar devices. To do this, edit "Pic14Bit::s_chips" in pic14.cpp for 14 bit chips, or "Pic12Bit::s_chips" in pic12.cpp and "Arguments::s_ChipIdmap" in rpipic.cpp. Note: the PIC16F28 is recommended as this is the chip that I have tested most, and does not require circuit reconfiguration (such as the PIC16F54 does in order to make it boot). You should note that this software is very experimental, and likely has many bugs.
Building and Running
Install scons, and a PIC assembler such as gpasm:
sudo apt-get install gpasm scons
- Download and extract the RPiPIC software source to your Raspberry Pi. The current version of the RPiPIC software is: 2012100701.
Change to the source directory and run:
Test the circuit by running:
sudo ./rpipic -r --device-idIf you're using one of the recognised devices, you should see an output like:Reading device ID...If you see:
Finished reading device ID...
Detected chip: pic16f628
Reading device ID...
Finished reading device ID...
Reading device ID... Finished reading device ID... Could not find 14 bit chip with ID: 0x0000then there is something wrong with your circuit.
If necessary, erase the PIC:
sudo ./rpipic -eThis command should also be sufficient to disable code protection if it has been enabled.
Write a test program to the PIC:
make -C samplesNote: samples/pic16f627.hex also works on the PIC16F628.
cat samples/pic16f627.hex | sudo ./rpipic -pcdxu
To test the PIC program:
sudo ./rpipic -b
See what else the program can do:
Hopefully you'll be able to make some use of this. I've posted a thread on the Raspberry Pi forum, so if you have questions/feedback, please do post!