Hardware Reference
In-Depth Information
As you want to manually control the outputs, in the PiFace Emulator window click Override
Enable.
Toggle Output Pin 1 on by clicking it. The PiFace interface will click as the relay turns on, and
the corresponding LED will illuminate. Notice the graphic on-screen updates to show the
LED being on, the contacts have changed over on the relay and the first output pin is on.
Try turning multiple output pins on, and notice how the on-screen display updates. Try the
All On, All Off and Flip buttons to discover what they do.
When you are finished flashing lights and trying the various options close the emulator.
You're now ready to program your Raspberry Pi to take control!
Interfacing with Python
You first meet the Hello World program in Appendix B, “Introductory Software Project: The
Insult Generator”. The hardware equivalent of Hello World is flashing a light, which similarly,
although not exciting in itself, is the first step in getting a computer to start controlling the
world. After you've mastered this, there's no limit to what you can start controlling!
Turning a Light On
First, write the code to turn an LED on:
Double-click IDLE to begin entering code interactively.
Type the following:
import piface.pfio as pfio
pfio.init()
pfio.digital_write(0,1)
The first LED should be lit.
Appendix B mentions that there are two versions of Python - Python 2 and Python 3. Similarly
there are two versions of IDLE; IDLE that corresponds to the Python 2 command python and
IDLE3 that corresponds to Python 3.
TIP
he import statement tells Python to use the piface.pfio module so it can talk to the
PiFace interface. You must call pfio.init() to check the connection and reset the PiFace
hardware. he digital_write( outputpin , value ) function takes outputpin , which
 
Search WWH ::




Custom Search