Using the PiFace Rack

Difficulty: medium

How to setup and use the PiFace rack with multiple PiFace Digitals in your projects.

Addressing multiple PiFace Digitals

Addressing different PiFace Digital boards is simple, you are just required to specify the number of the board you wish to address, in your read and write commands.
p.digital_write(pin_number, value, board_number)
p.digital_read(pin_number, board_number)

Example commands

p.digital_write(5, 1, 2) # writes pin5 on board2 high
p.digital_read(2, 3) # reads pin2 (on board3)

Note: As with the PiFace Digital’s pin numbers, the PiFace Digital boards are numbered 0-3.

Example code

The following example code turns each LED/output on four PiFace Digitals on and then off.
from time import sleep
import pifacedigitalio as p
p.init()
while(True):
    for value in range (0,2):
       for board in range (0 , 4): # for use with four boards, reduce this for fewer boards
          for pin in range (0,8):
             p.digital_write(pin,value,board)
             sleep(0.02)