Skip to content

The PiFace Digital input/output module for Arch Linux ARM

License

Notifications You must be signed in to change notification settings

codelitt/pifacedigitalioArch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pifacedigitalioArch

The PiFace Digital Input/Output module for Arch Linux ARM.

The PiFace Digital IO module uses Python 3 and is incompatible with Python 2

Installation from bare Arch Linux Arm

$ ./install.sh

Install script will ask you if you want to install dependency packages 3 times. Select "y" and hit enter for each if the package has not been previously installed"

If gpio-admin was installed then make sure to log out and then back in again.

Examples

Basic usage

>>> import pifacedigitalio as p
>>> p.init()       # initialises the PiFace Digital board 
>>> p.init(False)  # same as above w/out resetting ports

>>> pfd = p.PiFaceDigital(1) # creates a PiFace Digtal object (board1)
>>> pfd.leds[1].turn_on()    # turn on the second LED
>>> pfd.leds[2].toggle()     # toggle third LED
>>> pfd.switches[3].value    # check the status of switch3
0
>>> pfd.relays[0].value = 1  # turn on the first relay

>>> led0 = p.LED(0)  # create an LED object (pin0, board0)
>>> led0.turn_on()   # turn on the LED
>>> led0.value = 1   # turn on the LED

>>> led3_2 = p.LED(3, 2)  # create an LED object (pin3, board2)
>>> led3_2.turn_on()      # turn on the LED

>>> switch2 = p.Switch(2) # create a Switch object (pin2, board0)
>>> switch2.value         # is the switch pressed?
0
>>>

>>> p.digital_write(0, 1)    # writes pin0 (board0) high
>>> p.digital_write(5, 1, 2) # writes pin5 on board2 high
>>> p.digital_read(4)        # reads pin4 (on board0)
0
>>> p.digital_read(2, 3)     # reads pin2 (on board3)
1

Polymorphism

>>> class Chicken(pfio.Relay):
...     def __init__(self):
...         pfio.Relay.__init__(self, 0)
...     def wobble(self):
...         self.turn_on()
...
>>> chick1 = Chicken()
>>> chick1.wobble()      # Turns on relay0 (connected to a robot chicken)

Interrupts

>>> import pifacedigitalio as p
>>> p.init()
>>> pfd = p.PiFaceDigital()
>>>
>>> # create two functions
>>> def test(interupt_bit, input_byte):
...     print("Input pins: %s" % bin(input_byte))
...     pfd.leds[0].toggle()
...
>>> def test2(interupt_bit, input_byte):
...     print("Input pins: %s" % bin(input_byte))
...     pfd.leds[7].toggle()
...
>>> ifm = p.InputFunctionMap()       # create the input function map
>>> ifm.register(0, 0, test)         # and register some input/callbacks
>>> ifm.register(index=3, into=0, callback=test2, board=0)
>>> p.wait_for_input(ifm, loop=True) # loop=False, wait_for_input() will return

About

The PiFace Digital input/output module for Arch Linux ARM

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 95.0%
  • Shell 5.0%