Reference

Note

Functions and classes in pifacedigitalio.core have been imported into the main namespace. pifacedigitalio.digital_write() is the same as pifacedigitalio.core.digital_write().

class pifacedigitalio.core.InputEventListener(chip=None)

Listens for events on the input port and calls the mapped callback functions.

>>> def print_flag(event):
...     print(event.interrupt_flag)
...
>>> listener = pifacedigitalio.InputEventListener()
>>> listener.register(0, pifacedigitalio.IODIR_ON, print_flag)
>>> listener.activate()
class pifacedigitalio.core.PiFaceDigital(hardware_addr=0, bus=0, chip_select=0, init_board=True)

A PiFace Digital board.

Attribute :input_pins – list containing pifacecommon.mcp23s17.MCP23S17RegisterBitNeg.
Attribute :input_port – See pifacecommon.mcp23s17.MCP23S17RegisterNeg.
Attribute :output_pins – list containing pifacecommon.mcp23s17.MCP23S17RegisterBit.
Attribute :output_port – See pifacecommon.mcp23s17.MCP23S17Register.
Attribute :leds – list containing pifacecommon.mcp23s17.MCP23S17RegisterBit.
Attribute :relays – list containing pifacecommon.mcp23s17.MCP23S17RegisterBit.
Attribute :switches – list containing pifacecommon.mcp23s17.MCP23S17RegisterBit.

Example:

>>> pfd = pifacedigitalio.PiFaceDigital()
>>> pfd.input_port.value
0
>>> pfd.output_port.value = 0xAA
>>> pfd.leds[5].turn_on()
pifacedigitalio.core.deinit(bus=0, chip_select=0)

Stops interrupts on all boards. Only required when using digital_read() and digital_write().

Parameters:
  • bus (int) – SPI bus /dev/spidev<bus>.<chipselect> (default: {bus})
  • chip_select (int) – SPI chip select /dev/spidev<bus>.<chipselect> (default: {chip})
pifacedigitalio.core.digital_read(pin_num, hardware_addr=0)

Returns the value of the input pin specified.

Note

This function is for familiarality with users of other types of IO board. Consider accessing the input_pins attribute of a PiFaceDigital object:

>>> pfd = PiFaceDigital(hardware_addr)
>>> pfd.input_pins[pin_num].value
0
Parameters:
  • pin_num (int) – The pin number to read.
  • hardware_addr (int) – The board to read from (default: 0)
Returns:

int – value of the pin

pifacedigitalio.core.digital_read_pullup(pin_num, hardware_addr=0)

Returns the value of the input pullup specified.

Note

This function is for familiarality with users of other types of IO board. Consider accessing the gppub attribute of a PiFaceDigital object:

>>> pfd = PiFaceDigital(hardware_addr)
>>> hex(pfd.gppub.value)
0xff
>>> pfd.gppub.bits[pin_num].value
1
Parameters:
  • pin_num (int) – The pin number to read.
  • hardware_addr (int) – The board to read from (default: 0)
Returns:

int – value of the pin

pifacedigitalio.core.digital_write(pin_num, value, hardware_addr=0)

Writes the value to the input pin specified.

Note

This function is for familiarality with users of other types of IO board. Consider accessing the output_pins attribute of a PiFaceDigital object:

>>> pfd = PiFaceDigital(hardware_addr)
>>> pfd.output_pins[pin_num].value = 1
Parameters:
  • pin_num (int) – The pin number to write to.
  • value (int) – The value to write.
  • hardware_addr (int) – The board to read from (default: 0)
pifacedigitalio.core.digital_write_pullup(pin_num, value, hardware_addr=0)

Writes the value to the input pullup specified.

Note

This function is for familiarality with users of other types of IO board. Consider accessing the gppub attribute of a PiFaceDigital object:

>>> pfd = PiFaceDigital(hardware_addr)
>>> hex(pfd.gppub.value)
0xff
>>> pfd.gppub.bits[pin_num].value = 1
Parameters:
  • pin_num (int) – The pin number to write to.
  • value (int) – The value to write.
  • hardware_addr (int) – The board to read from (default: 0)

Previous topic

Simple Web Control

This Page