Monday, 06 January 2014 22:11

PiFace Digital

Written by 
  • Operating System: Raspbian
  • Country: UK

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.

 piface-digital-input-connectorspiface-digital-output-connectors

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)

piface-digital-relay-connectorspiface-digita-led-lights

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.

Initial set-up

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

sudo raspi-config

In the menu that loads:

  • Select "8 Advanced Options"
  • Select "A5 SPI"
  • Select "Yes" then OK
  • Select "Finish"

Piface-EmulatorPiFace 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

Programming:

Scratch

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:

pifacedigital-scratch-handler 127.0.1.1

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

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:

Python 3

sudo apt-get install python3-pifacedigitalio

Python 2

sudo apt-get install python-pifacedigitalio

C

C libraries are available at Github http://piface.github.io/

Jumpers

piface digital jumpers

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.

JP3
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.

JP4
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.

J7
Deactivates both relays and all 8 LED's when the output ports are used.

 

Links and Documentation

Setting up the Piface-Digital

http://www.piface.org.uk/guides/Install_PiFace_Software/Updating_Raspbian/

Using Scratch with the PiFace-Digital

http://www.piface.org.uk/guides/scratch_with_pifacedigital/Setting_up_Scratch/

Python Library pifacedigitalio documentation

http://piface.github.io/pifacedigitalio/index.html

OCR Classroom guide to building a basic programmable buggy using 2 motors in Scratch.

http://www.ocr.org.uk/Images/125877-classroom-challenge-hardware-hacking-and-robotics-learner-sheet.pdf

Controlling a Slot Car racing track from beginners to intermediate level

http://elinux.org/RPi_Projects/PiFace_controlling_a_slot-car#Simple_on.2Fout_control_over_your_slot_car_.28difficulty:_beginner.29


Data Sheets

16-bit input/output port expander - MCP23517

 Darlington Transistor array (output) - ULN2308A

 

 

Last modified on Saturday, 14 February 2015 10:21
Google
roboberry

RapberryConnect.com SuperUser.  Contactable via the site admin e-mail in the Contact Us link.

Website: www.raspberryconnect.com

Leave a comment

Comments for Guest and account owners. Account owners will need to login to use registered e-mail address.

3 comments

  • Comment Link Tim Rowledge Tuesday, 02 December 2014 01:17 posted by Tim Rowledge

    Nicely done explanation! Especially since the install of the scratch handler fails to add that desktop icon.

    You'll be able to simplify it a bit very soon since the revised Pi Scratch (see the assorted NuScratch blog and forum entree on the Pi site) will have the Mesh networking stuff available without having to mess around in the Squeak code browser.

    Report
  • Comment Link Greame Saturday, 26 July 2014 11:51 posted by Greame

    You're welcome

    Report
  • Comment Link Richard Ballard Thursday, 24 July 2014 05:37 posted by Richard Ballard

    At Last! I have been trying to get PiFace and Scratch working together for weeks! I have no idea how many sites I have been to trying to get this working. Your piece had ALL the steps needed to make this work. Thank you!

    Report

Additional information