I'm looking to build an automation application using the Rasbery Pi + Piface board, using Python.

I've got as far as being able to switch the LEDs on and off from a command line Python script, however every time the script is called it re-sets the board when the init command is given. So for example if I call it once to turn LED1 on, when I call it again to turn LED2 on it turns LED1 off when the init is issued, but you have to issue the init before you can control things. Is there any way to call init without causing a Piface reset? I want to be able to turn specific things on and off without affecting other things.

Here's the test script - I'm sure there are far better ways to do this but it does as a starting point. This is the first time I've ever looked at Python, I normally work in Perl. It's called as for example: ./test2 on2

#!/usr/bin/env python

import time
import piface.pfio
import sys # import command line arguments


led1 = piface.pfio.LED(1)
led2 = piface.pfio.LED(2)
led3 = piface.pfio.LED(3)
led4 = piface.pfio.LED(4)
led5 = piface.pfio.LED(5)

if str(sys.argv[1]) == "on1":
elif str(sys.argv[1]) == "on2":
elif str(sys.argv[1]) == "on3":
elif str(sys.argv[1]) == "on4":
elif str(sys.argv[1]) == "on5":
elif str(sys.argv[1]) == "off1":
elif str(sys.argv[1]) == "off2":
elif str(sys.argv[1]) == "off3":
elif str(sys.argv[1]) == "off4":
elif str(sys.argv[1]) == "off5":
  print "No valid input specified\n"

print 'Number of arguments:', len(sys.argv), 'arguments.'
  • As far as I can see you can run piface.pfio.init(False) to not initialize the ports. Though you'd need a script to run it without the parameter on boot.
    – Gerben
    Jul 3, 2013 at 14:36
  • @Gerben Thanks, didn't think of passing options in the call, will check the possibilities. I eventually worked round it - built a deamon process in Python that monitors the status of the inputs, and watches for triggers from external processes. The daemon initialises the board on startup but then runs continuously in the background, reporting status changes and reacting to triggers. Probably not the most elegant solution in the world but it works. Not bad given brand new system and language.
    – Pyromancer
    Jul 4, 2013 at 14:35
  • Sound quite elegant actually. Glad you got it to work.
    – Gerben
    Jul 4, 2013 at 17:46
  • Looks like theyve kinda abandoned python2, most of the stuff in now python3 Apr 18, 2014 at 10:58

1 Answer 1


By the way, there are more up-to-date Python libraries for PiFace: https://github.com/piface/pifacedigitalio/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.