I have a Raspberry, a relay plus and a motor control. In python, I'm not able to address the both instructions at the same time.

I use : pfr ton initialize :

#Now initialise your Relay+.
pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR_DC)
pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY)

Seems to be that I cannot use both instructions at the same time. In this case only the relays work. But I can't start or stop the motor.


But is I hash out the pfr RELAY, the motor instruction work. What am I doing wrong?

1 Answer 1


You are using the variable pfr twice, so the first assignment gets lost. If you change your code to use different variable names like so:

pfr_motor = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR_DC) 
pfr_relay = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY)



should work. Similarly, if you want to do something with the relay, use the pfr_relay variable.

By the way, these are very basic programming constructs (variables and object references) so make sure you get comfortable with programming in general and programming in Python in specific before attempting more complicated code.

UPDATE: I've done a quick check in the PiFaceRelayPlus docs, and found the following example code (executed in the Python Shell):

>>> pfrp = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR)
>>> pfrp.inputs[2].value
>>> pfrp.relays[3].turn_on()
>>> pfrp.motor[2].forward()

According to this example, you should only have 1 reference to your PiFaceRelayPlus (the pfrp = ... line). The first argument of PiFaceRelayPlus is the add-on board you used (in your case the Motor DC board). Once initialized through this assignment, you can now use the inputs[], relays[] and motor[] lists to access motors and relays at the same time.

  • Indeed, very basic,
    – user54435
    Oct 3, 2016 at 14:55
  • You need to start somewhere, tx anyway...
    – user54435
    Oct 3, 2016 at 14:57
  • @ home test :Even if I use
    – user54435
    Oct 3, 2016 at 20:37
  • Even if I use the different variables, it still overwrites the previous : import pifacerelayplus import time # Now initialise your Relay+. pfr_relay = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) pfr_motor = #pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR_DC) while True: pfr_relay.relays[0].set_high() time.sleep(1) print("Pin 0 GPIO = " + str(pfr_relay.x_pins[0].value))
    – user54435
    Oct 3, 2016 at 20:40
  • After reading the docs, I've updated my answer.
    – Phil B.
    Oct 5, 2016 at 3:07

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.