The PiFace digital is a GPIO add-on board for the Raspberry Pi which allows you to connect lights, switches, motors and sensors to be used with program's written with Scratch, Python or C.
This article relates to the 2.1 revision that fits the layout of the original Raspberry Pi models A & B, so features may differ from earlier versions.
There is now a new Version 2 Piface Digital which has a different layout as it has both the Green input block and the Orange output block on the same side to fit the layout of the Raspberry Pi A+, B+ and Raspberry Pi 2.
This article is relevant to both models of the Piface Digital.
The PiFace Digital is a good device to be used in schools as it can be programmed using Scratch, which is a fun and simple way for children to learn to program. It can also be programmed using python 2 or 3 and C and has all the required libraries available in the latest versions of Raspbian.
- 8 Green Input ports and with 4 Input Buttons, 8 Orange Output ports with 5V supply.
The Piface connects to the GPIO port of the Raspberry Pi and fits within it's profile.
Round the edges are screw connectors for:
- 8 digital inputs such as switches buttons and sensors.
- 8 open-collector outputs for things like lights, buzzers, motors and servos.
- 2 change over relays for switching devices up to 20 volts and 5 amps.
(Note: the relays are capable of 250 volts and 10 Amps but the leaflet that comes with the PiFace warns that they should not be used over 20Volts and 5Amps)
Two 20V relays and PiFace Digital Optional 5V supply block, 8 on-board LED lights for output.
Onboard there are:
- 8 output red LED lights
- 4 buttons for input.
These are also connected to the input and output ports so you can either use connected devices or the buttons and LEDs on-board with the same programming code.
The Relays are connected to outputs 0 and 1 as well as LED's 0 and 1 so when you connect an external device on outputs 0 and 1 the LEDs will come on and the relays will click. The relays and all 8 LED's can be disconnected via the jumpers. See the Jumper section below.
The PiFace circuit board is powered by a 3.3v supply taken from the RPi but connected devices for the input and output ports can use up to 5 volts and be powered by their own supply or a 5v supply on the PiFace-Digital. The 5v supply block can also be used to power the PiFace digital and raspberry pi instead of the Rpi's power supply.
If jumper J3 is connected then both Rpi and Piface will be powered by the Raspberry Pi or just a 5V supply to the power block on the PiFace. If the jumper is not set then both devices will need separate power supplies.
The ULN2803A chip is capable of handling 50V and 500mA with the Outputs but the jumper at J4 MUST be disconnected if you are using more than 5V with the Output connectors, otherwise this will damage the Raspberry Pi. See jumper section and Data Sheet links below. The Inputs cannot be used with more than 5V.
To use the PiFace-Digital you will need to activate the SPI drivers as this is off by default in Raspbian.
In Lxterminal enter the command
In the menu that loads:
- Select "8 Advanced Options"
- Select "A5 SPI"
- Select "Yes" then OK
- Select "Finish"
PiFace Digital Emulator
The Piface Digital emulator lets you activate the inputs and outputs via a graphical interface and see what is active while a program is running so you can test your wiring and programs.
This is installed with the command
sudo apt-get install python3-pifacedigital-emulator
Can be used to to control the outputs and read the inputs but has to have some configuration modified before it can be used to program the PiFace.
This involves changing one setting from True to False. Full details can be found on the PiFace website, see link at the bottom of this article.
Once scratch is setup and the Mesh service is running the pifacedigital-scratch-handler need to be run.
I updated an existing copy of Raspbian with the required software. The scratch Handler is installed but not on the desktop as started in the guide. It can be activated by going into LXterminal and entering the command:
Though I have to stop the mesh service in Scratch, then restart it and then start the scratch handler before the connection is made.
Once you're connected you can start a project. The input controls are available in the Sensing section which can be tested with the four input buttons.
For output you have to setup custom variables in the variables section. This just involves making 8 variable called piface-output1 to piface-output8. Once done you can switch on and off the 8 LEDs and 2 relays by setting the variable to 1.
Python control is available through the pifacedigitalio library which is available in the latest version of Raspbian or can be installed.
To use Python you will need the Python libraries which can be installed with the commands:
sudo apt-get install python3-pifacedigitalio
sudo apt-get install python-pifacedigitalio
C libraries are available at Github http://piface.github.io/
There are 7 jumpers on the board that are used for:
JP1 & JP2
These set the address of the board if multiple PiFace-Digitals are used in a stack. Though there is no GPIO through port several boards can be connected to a Raspberry Pi using the PiFace Rack.
Connects the 5V rail of the Raspberry Pi to the PiFace-Digital. With this active the PiFace receives the 5V supply from the RPi and can also supply the RPi with 5V if an external supply is connected to the PiFace-Digitals 5V power block. With it unset both devices need their own 5V supply.
For the Snubber Diode. If the Open-Collectors are used for more than 5 Volts, then J4 must be disconnected to stop the Raspberry Pi receiving over 5V.
J5 & J6
To disconnect the two relays so they don't activate and click when outputs 0 and 1 are used.
Deactivates both relays and all 8 LED's when the output ports are used.
Links and Documentation
Setting up the Piface-Digital
Using Scratch with the PiFace-Digital
Pi Face Digital Scratch Handeler
Python Library pifacedigitalio documentation
Controlling a Slot Car racing track from beginners to intermediate level
16-bit input/output port expander - MCP23517
Darlington Transistor array (output) - ULN2308A
I have very limited time currently for the comments, so you will probably get a very slow response for questions I know the answer to. If I need to set up a Pi to check your issue or request then I am unlikely to have chance to spend time on this.
I will continue support once I can spare the time again.
Thank you for your interest