{"id":14978058,"url":"https://github.com/bulletmark/pifaceio","last_synced_at":"2025-10-28T07:31:14.233Z","repository":{"id":57452637,"uuid":"14385982","full_name":"bulletmark/pifaceio","owner":"bulletmark","description":"Provides a Python interface to the PiFace Digital peripheral board for the Raspberry Pi.","archived":false,"fork":false,"pushed_at":"2025-01-28T00:33:28.000Z","size":48,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-28T01:30:08.497Z","etag":null,"topics":["piface","piface-board","piface-digital","pifacedigitalio","python","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bulletmark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-11-14T05:24:13.000Z","updated_at":"2025-01-28T00:33:32.000Z","dependencies_parsed_at":"2024-09-18T23:02:32.715Z","dependency_job_id":null,"html_url":"https://github.com/bulletmark/pifaceio","commit_stats":{"total_commits":66,"total_committers":2,"mean_commits":33.0,"dds":"0.015151515151515138","last_synced_commit":"886408f3d776dd7035bb76d4e31213bd66843a59"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fpifaceio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fpifaceio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fpifaceio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fpifaceio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bulletmark","download_url":"https://codeload.github.com/bulletmark/pifaceio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238614447,"owners_count":19501458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["piface","piface-board","piface-digital","pifacedigitalio","python","raspberry-pi"],"created_at":"2024-09-24T13:56:48.029Z","updated_at":"2025-10-28T07:31:14.228Z","avatar_url":"https://github.com/bulletmark.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### PIFACEIO\n[![PyPi](https://img.shields.io/pypi/v/pifaceio)](https://pypi.org/project/pifaceio/)\n\nThis package provides a Python interface to the [PiFace Digital][pifaceboard]\nperipheral I/O board for the [Raspberry Pi][rpi].\nA [PiFace Digital][pifaceboard] board offers 8 digital inputs and 8\ndigital outputs. This package allows a Python program to read the inputs\nand write the outputs on the board via the Raspberry Pi SPI bus.\n\nMultiple [PiFace Digital][pifaceboard] boards are supported, on either\nor both of the RPi SPI bus chip selects. This pifaceio package is\nfocussed on simplicity and performance for polled implementations and is\nan alternative to the official [pifacedigitalio][] Python package for\nthe [PiFace Digital][pifaceboard] board. In my simple benchmark of\npolled reads and writes ([see next\nsection](#performance-benchmarks-against-pifacedigitalio)), pifaceio\nperforms an order of magnitude faster, and with much less overhead than\n[pifacedigitalio][].\n\nInterrupts are not supported. See [pifacedigitalio][] for interrupt and\nother functionality.\n\nThe pifaceio package is implemented in pure Python code using only the\nPython standard library, uses no external 3rd party packages, and is\ncompatible with Python version 3.6 and later.\n\n#### Performance Benchmarks Against pifacedigitalio\n\nA small [`benchmark`](benchmark) program is included in the\nrepository. It produces the following sample of simple polled read and\nwrite performance comparisons between [pifacedigitalio][] and\n[pifaceio][] on a Raspberry Pi2B.\n\n|Function                              |`pifacedigitalio`|`pifaceio` |Speedup\n|--------------------------------------|-----------------|-----------|--------\n|Input reads per second                |1740             |16317      |x 9.4\n|Output writes per second              |884              |11590      |x 13.1\n|Input reads per second (classic API)  |1773             |11128      |x 6.3\n|Output reads per second (classic API) |889              |9140       |x 10.3\n\n### INSTALLATION\n\nThe [pifaceio pypi package][pifaceio] is available from [PyPi][] so you\ncan install it using [pip][]. If [pip][] is not already installed run:\n\n```sh\nsudo apt-get install python3-pip\n```\n\nThen use pip to install the [pifaceio][] package:\n\n```sh\nsudo pip3 install -U pifaceio\n```\n\nTo set up permissions/groups/udev etc for spidev device on RPi, run the\nincluded script and then reboot.\n\n```sh\nsudo pifaceio-install-spidev.sh\n```\n\n### UPGRADE\n\n```sh\nsudo pip3 install -U pifaceio\n```\n\n### USAGE\n\nBoard addresses, input pins, and output pins are always numbered from 0.\n\nIn general, you start with a once-off allocation of a PiFace board\ninstance at startup with:\n\n```python\npf = pifaceio.PiFace()\n```\n\nDefault is first PiFace board (0). Optionally takes an argument 0 to 7\nfor up to 8 PiFace board addresses. Create multiple PiFace() instances\nif you want to use multiple boards in parallel.\n\nThere are also other (rarely needed) options to disable the input pull\nup resistors, and to invert the input and output bit polarities. See\npifaceio.py for details.\n\nAt each poll time, e.g. every part second, read all the inputs (i.e. the\nsingle input byte) with:\n\n```python\npf.read() # returns the input byte you can use directly if you prefer\n```\n\nThen read and write individual pins according to your logic with:\n\n```python\nin_val = pf.read_pin(pin_in)\n# ..\npf.write_pin(pin_out, out_val)\n# ..\n```\n\nFinally, write all the outputs at the end of processing (i.e. write the\nsingle output byte) with:\n\n```python\npf.write() # optionally, takes an output byte to write directly\n```\n\nNote that `read_pin()` is just a convenience method wrapping a bit\ntest around the previously read input byte from `read()` and\n`write_pin()` is just a convenience method wrapping a bit set/clear\naround the output byte pending it being written by `write()`. You don't\nhave to use `read_pin()` or `write_pin()` if you just want to read,\ntest/manipulate, and write the 8 bit input and/or output byte directly.\nIn that case you would just use `read()`, and `write()` only in your\napplication.\n\n### EXAMPLES\n\nSimple example to just reflect all PiFace 8 inputs to the 8 outputs\nevery 10 msec, on the default first PiFace board:\n\n```python\nimport pifaceio, time\npf = pifaceio.PiFace()\n\nwhile True:\n    pf.write(pf.read())\n    time.sleep(.01)\n```\n\nSame example, but do it across 4 PiFace boards:\n\n```python\nimport pifaceio, time\npifaces = [pifaceio.PiFace(n) for n in range(4)]\n\nwhile True:\n    for pf in pifaces:\n        pf.write(pf.read())\n    time.sleep(.01)\n```\n\nSimple example to test if both input pin 0 and 1 are on at same time,\nand then set output pin 7 if true:\n\n```python\nimport pifaceio\npf = pifaceio.PiFace()\n...\n# Fetch inputs (i.e. single byte)\npf.read()\nfirst_two_inputs_on = pf.read_pin(0) and pf.read_pin(1)\n\n# Now write that state to output pin 7\npf.write_pin(7, first_two_inputs_on)\n\n# Do final (actual) write when all output pin states are set.\npf.write()\n```\n\nSimulated \"interrupt\" processing example by light-weight poll every 10 msecs:\n\n```python\nimport pifaceio, time\npf = pifaceio.PiFace()\n\ndef process_change():\n    'On any changed inputs, read inputs and write outputs'\n    pf.write_pin(7, pf.read_pin(0) and pf.read_pin(1))\n\n    # .. etc .. do logic using pf.read_pin() and pf.write_pin()\n\n# Loop forever polling inputs ..\nlast = None\nwhile True:\n    data = pf.read()\n\n    # Do processing only on change\n    if last != data:\n        last = data\n        process_change()\n        pf.write()        # note write() only writes if output changes\n\n    time.sleep(.01)\n```\n\n### PIFACE PACKAGE BACKWARDS COMPATIBILITY\n\nAs an alternative API, pifaceio also implements the \"classic\" API from\nthe [pifacedigitalio][] and it's predecessor [piface][] packages. The\nclassic API will work compatibly, but performance is slightly degraded\ncompared to reading and writing the single input and output bytes using\nthe canonical new and preferred pifaceio API described above. However,\nperformance is still significantly superior to the original\n[pifacedigitalio][] and [piface][] packages as shown in the above\n[performance\ncomparison](#performance-benchmarks-against-pifacedigitalio) section.\n\n```python\n#import piface.pfio as pf (change this line ..)\n#import pifacedigitalio as pf (or this line .., to the following line)\nimport pifaceio as pf\n\n# The following calls should be approximately compatible:\npf.init()\nvalue = pf.digital_read(pin)\npf.digital_write(pin, value)\npf.deinit()\n```\n\nYou can also use multiple boards with this compatibility interface, e.g.\nas follows where board can be from 0 to 7.\n\n```python\nvalue = pf.digital_read(pin, board)\npf.digital_write(pin, value, board)\n```\n\n### LICENSE\n\nCopyright (C) 2013 Mark Blakeney. This program is distributed under the\nterms of the GNU General Public License.\nThis program is free software: you can redistribute it and/or modify it\nunder the terms of the GNU General Public License as published by the\nFree Software Foundation, either version 3 of the License, or any later\nversion.\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\nPublic License at \u003chttps://en.wikipedia.org/wiki/GNU_General_Public_License\u003e for more details.\n\n[rpi]: http://www.raspberrypi.org\n[pifaceboard]: http://www.element14.com/community/docs/DOC-69001/l/piface-digital-2-for-raspberry-pi\n[piface]: http://github.com/thomasmacpherson/piface\n[pifacedigitalio]: http://github.com/piface/pifacedigitalio\n[PyPi]: https://pypi.python.org/pypi\n[pip]: http://www.pip-installer.org/en/latest\n[pifaceio]: https://pypi.python.org/pypi/pifaceio\n\n\u003c!-- vim: se ai et syn=markdown: --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulletmark%2Fpifaceio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbulletmark%2Fpifaceio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulletmark%2Fpifaceio/lists"}