Scratch with PiFace Digital

Difficulty: beginner

How to setup and use Scratch with PiFace Digital.

Getting started with Scratch and PiFace Digital

  1. Connect the microUSB connector to boot up the Raspberry Pi.
  2. Start the graphical environment
  3. Double click on the Scratch icon on the desktop.
  4. We are going to connect Scratch to the PiFace hardware by using Mesh. In the Scratch window hold down the shift key and click the Share menu and then click Host Mesh.
  5. Scratch displays a window with the address of the Mesh handler. This confirms the Mesh handler is running. Click OK to dismiss the window.
  6. Next we need to connect the Scratch Handler that talks to the board. Double click the Scratch Handler icon on the desktop.
  7. A Terminal window appears and after a short period should display a message saying Connected.


  1. Click on the main Scratch window and click the orange Variables menu item.
  2. Click Make a variable button.
  3. When prompted for a variable name enter piface-output1 and then click OK. It is important that the name matches exactly.
  4. The new variable will appear on the canvas.
  5. Double click on the variable to display a slider to change it’s value.
  6. Slide the slider to the right to increase it’s value. As the value increases above 0 the relay on the PiFace board will turn on (you’ll notice it click) as well as the first LED.

We have now setup Scratch to use PiFace with one output. A new variable must be created for each output (with a different number).
In a classroom environment this whole process can be automated (and launched with a single double click). However, in this guide we have shown all steps involved for clarity.

Input with Scratch

Reading inputs is a lot easier in Scratch as you do not have to create variables. Instead, inputs are accessible under Sensing.

  1. Click Sensing.
  2. Click the <slider> sensor value to display the list of inputs that can be used and select piface-input1. The numbers correspond to the numbered inputs.