PiFace – Getting Started

PiFace – Getting Started

PiFace Digital is by far the easiest way to connect your devices to the real world and it couldn’t be any easier. This guide will give you a basic understanding of the Piface Digital board features and show you how to get setup to start your maker projects.

Main Features:-

  • x2 Changeover Relays
  • x4 switches
  • x8 digital inputs
  • x8 open collector outputs
  • x8 LED status indicators
  • Easy to program in python, scratch and C
  • Graphical emulator/simulator

Fitting the Board

The PiFace Digital fit neatly ontop of the Raspberry Pi using the GPIO housing on the PiFace to connect together with the Raspberry Pi. When connecting the boards toegether please make sure the pins are aligned to abvoid bending the GPIO pins on the Raspberry Pi.

PiFace Digital

Installing the software

The fastest way and most convehnient way to get the software is to download a prepared image file and install it to a compatible SD card. You can get the latest download image from http://pi.cs.man.ac.uk/download/ . Alternatively if you already own an Raspbian OS installed SD card then you can just download all the neccessary library files to the OS.

PiFace Digital communicates to the Raspberry Pi using the SPI interface. The SPI interface driver is included in the later Raspbian distributions but is not enabled by default. You can always enable the SPI driver, or you can load it by hand when required.

Always enabling SPI

To always enable the SPI driver:

  • After logging in, edit /etc/modprobe.d/raspi-blacklist.conf

sudo nano etc/modprobe.d/raspi-blacklist.conf

  • Insert a # at the start of the line containing blacklist spi-bcm2708

#blacklist spi-bcm2708

Alternatively, to load the SPI driver by hand (will not be loaded on reboot):

  • Type in a terminal:

sudo modprobe spi-bcm2708

Next, you we need to install the PiFace Digital libraries and change the permissions of the SPI interface. The following script automates this into one command.

To install and setup the software, ensure your Pi can access the Internet and type:

sudo apt-get update

wget -O – http://pi.cs.man.ac.uk/download/install.txt | bash

The software will complete installing in a few minutes.

Reboot your Pi by typing:

sudo reboot

Testing

After installing the software and restarting, login and startx.

Start the PiFace emulator by typing in a terminal:

piface/scripts/piface-emulator

Outputs

  1. To manually control the outputs, in the PiFace Emulator window, click Override Enable.
  2. Toggle Output Pin 1 on by clicking on it. The PiFace interface will click as the relay turns on and the corresponding LED will illuminate. Notice the graphic onscreen updates to show the LED being on, the contacts have changed over on the relay and the first output pin is on.

The LEDs are in parallel with the outputs terminal connectors and indicate when the output is enabled.

Inputs

  1. We want to observe the inputs so click Keep inputs updated checkbox so the emulator reads the buttons and updates the screen. The interval sets how often the inputs are read, for most cases, it is fine to leave it on 500ms.
  2. Press one of the buttons on the bottom left of PiFace. Notice how the onscreen representation changes to indicate the switch has been pressed.

First steps with Python

To use Piface with Python import the piface.pfio module:

import piface.pfio

Before use, the board must be initialised with a call to init() .

There are three main functions to control the interface

  • digital_read(pin_number)
  • returns 1 or 0 depending on the state of the input numbered pin_number
  • digital_write(pin_number, state)
  • sets the output numbered pin_number to state 0 or 1. State 1 turns the LED on and enables to open collector to sink current
  • digital_write_pullup(pin_number, state)
  • sets a 10k pullup on input numbered pin_number to be state 0 or 1. State 1 is pullup enabled
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Anti-Spam Quiz: