With the introduction of wiringPi version 2, there is now a new website dedicated to all things wiringPi including the new PiFace interface code. This page will remain for historical purposes, but please click here to take you to the current PiFace page on the wiringPi Site.
PiFace is a peripheral IO device for the Raspberry Pi. To use it, I have put together an extension of wiringPi for use with the PiFace device.
The PiFace board
Symbolic view from above with the composite video connector at the top, and the HDMI connector at the bottom.
Pi GPIO | Inputs | ||||||||
0v | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
sw3 | sw2 | sw1 | sw0 | ||||||
•R2:N.Open | |||||||||
•R2:Comm | |||||||||
•R2:N.Closed | |||||||||
•R1:N.Open | |||||||||
•R1:Comm | |||||||||
•R1:N.Closed | |||||||||
+5v | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
Outputs |
Notes:
- sw0 through sw3 are connected to inputs 0 through 3 respectively.
- Relay 2 + LED 2 is connected to output 0
- Relay 1 + LED 1 is connected to output 1
- LED 3 is connected to output 2
- LED 4 is connected to output 3
Functions
The standard wiringPi functions work with the PiFace with a few notable exceptions and differences:
- Because we can’t control the direction of the pins – it’s fixed in hardware, there are no pin direction functions.
- Numbering starts at zero and carries on through 7 for both inputs and outputs. (so you can digitalWrite (0,1), but digitalRead (0) returns the value on the input pin, not the output pin)
- The PiFace only has internal pull-up resistors and these are not enabled by default. You should enable them if reading the switches on the PiFace.
Use
To use the PiFace, you must call the PiFace initialisation routine in your program where you would normally call one of the other wiringPi setup functions:
wiringPiSetupPiFace ()
After this, you can then call the usual digitalWrite(), digitalRead() and pullUpDnControl() functions, as required.
Download and Install
See the wiringPi download and install pages for more details. There is working example called piface.c in the examples directory. You do need to be root to run the program (for now), so after typing make, then type sudo ./piface then you can push the buttons and make the LEDs/Relays turn on and off.