Preparing the Pi
You should use the RaspPi website
( www.raspberrypi.org) as a reference to avoid
frustration when working with the Pi.
Documentation for the PiFace is at best weak.
However, dig hard and you will find what you need.
You will discover that the PiFace is a very simple
We will be running the latest version of
Raspbian on our RaspPi. Everything we need to
interface to the B4J program and PiFace is already
included in the Raspbian kernel. SSH is disabled by
default in Raspbian, so be sure to create an empty
file called ssh on the Pi’s bootable micro SD card.
The PiFace you see in Photo 1 is based on the
Microchip MCP23S17 16-bit I/O expander. The
RaspPi interfaces to the PiFace via the MCP23S17’s
SPI portal. I/O instructions from the Pi’s SPI portal
are processed by the MCP23S17, which drives a
ULN2803A Darlington transistor array.
The ULN2803 is designed to drive inductive loads.
To that end, the PiFace is equipped with a pair of relays
that are driven by the ULN2803A. The MCP23S17 pins
out to eight digital inputs and eight digital outputs. The
ULN2803A buffers the MCP23S17’s output pins, and
drives an octet of onboard LEDs in addition to the pair
of onboard relays. There is also a quad of pushbutton
switches tied to the MCP23S17’s input pins.
If you consult the Raspberry Pi website, you will
find that the Pi’s SPI portal is disabled by default. So,
our first task will be to enable it. We do this by editing
the /boot/config.txt file. As you can see in Screenshot 1,
we enable the RaspPi’s SPI portal by simply removing
the comment character standing in front of
To a programmer, B4J is very much like Visual Basic
THE DESIGN CYCLE
Put on a PiFace
■ BY FRED EADY
The Raspberry Pi is a very popular computing platform. Its claims to fame are
inexpensive hardware and open source programming. Browse the Internet and you will
find that many have purchased a Pi with the thoughts of easily applying Python to the
hardware. As you claw through the thousands of hits, you’ll find a bunch of those
potential Pi users crying in their beer. Seems there’s a learning curve that goes along
with Python coding that’s coupled with little gotchas that come with the Raspberry Pi
itself. I’ve suffered with the Pi gotchas, but I didn’t lose any hair learning Python. In this
installment of the Design Cycle, we will use a free RAD (Rapid Application Development)
tool called B4J to twiddle the I/O pins of a PiFace that is hosted by a Raspberry Pi.
■ PHOTO 1. The PiFace is an I/O expansion board that falls under
the control of a Raspberry Pi’s SPI portal. Standard PiFace
features include an octet of LEDs sitting on high current outputs
and a quad of pushbutton switches positioned on an octet of
■ SCREENSHOT 1. I find it funny that the Raspberry Pi fathers
listed the SPI and I2C portals as “optional.”
ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
July 2017 55