Coder Social home page Coder Social logo

pifacedigitalio's Introduction

pifacedigitalio

The PiFace Digital Input/Output module (PyPI).

Use this module to use PiFace Digital and PiFace Digital 2 hardware in Python3

Install

Make sure you are using the lastest version of Raspbian:

$ sudo apt-get update
$ sudo apt-get upgrade

Enable SPI (e.g. use raspi-config)

$ sudo raspi-config

select `Interface Options` > `SPI` > `Yes` and then select `Finish`

If you need to install pip3

$ sudo apt install python3-pip

Install pifacedigitalio with the following command:

Python 3:
$ sudo pip3 install pifacecommon
$ sudo pip3 install pifacedigitalio

Examples

To run an example program clone this repo

$ git clone https://github.com/piface/pifacedigitalio.git

Test by running the blink.py program:

$ python3 pifacedigitalio/examples/blink.py

Documentation

http://pifacedigitalio.readthedocs.org/

pifacedigitalio's People

Contributors

csoutreach avatar jwurzer avatar psytester avatar tompreston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pifacedigitalio's Issues

Compatible with Piface RTC Module?

This should really be in the FAQ! I'm building a time-based code-lock with PiFace and an RPi (code will be published with a FL license, not to worry!), and because codes are time-critical I'd like a real-time clock. If I know for a fact that the RTC from PiFace is compatible with the Piface DIO board, I'll buy that, but I can't find mention of that in the RTC docs or on either issue tracker. It seems a strange omission..

Thanks!

Python Future Module

The incompatibility with Python 3 is mostly due to the print function. We can use:

from __future__ import print_function

which will allow us to use the print function in Python 2.7.

Will need to check for other incompatibilities first.

Missing module and slight fix to README

This package does not load when you try to use it because asm_generic_ioctl is missing from the list of modules in setup.py so it does not get installed.

Also, README.md should say "sudo python3 setup.py install".

Listener/interrupt Not working on Version 1 Piface

Hello,

I am having trouble getting the simple listener examples to work. I am using latest version of Raspbian on an original Raspberry Pi board with the original (version 1?) of the piface, with Python 3.

The piface emulator works just fine on inputs and outputs, and simple input and output examples work fine as well, so I know that the code is communicating with the piface board:

import pifacedigitalio
pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object
pfd.leds[1].turn_on() # turn on/set high the second LED
print(pfd.input_pins[0].value)
0

The last statement properly prints a 1 when run while the input 0 switch is pressed.

However, when I try the following listener example, nothing works when input 0 switch is pressed:

import pifacedigitalio

def toggle_led0(event):
... event.chip.leds[0].toggle()
...
pifacedigital = pifacedigitalio.PiFaceDigital()
listener = pifacedigitalio.InputEventListener(chip=pifacedigital)
listener.register(0, pifacedigitalio.IODIR_FALLING_EDGE, toggle_led0)
listener.activate()

Have googled this and been unable to come up with anything. Do I need to explicitly enable interrupts or some other feature? Would really appreciate some help with this. Thanks!

Problems with PiFace Emulator and Scratch

I have three PiFaces connected to a PiRack, which work well with python3 commands of the type p.digital_write(0,1,2) to switch on LED 0 on Board 2. I have downloaded the newest version of the Emulator (my RPi says it's the newest version), but this does not look like the picture of one as shown in the PiFace Guide; mine does not have the "View" option, so I cannot select which Board number I wish to address. Is there something else I need to do?

Similarly, I want to use these PiFaces with Scratch. I have carried out all the Guide instructions to enable Scratch to be used with the PiFace, but my version of Scratch does not produce the option to “Host Mesh” or “Join Mesh” when I shift-click the Share option. Instead I get “Stop Hosting Mesh” so, again, I assume I have an earlier version of Scratch, even though the RPi assures me I have the newest version. I cannot therefore configure the control instructions to talk to the PiFace at all (not even to Board 0) . Could someone please tell me what to try next?

Add uninstall script

  • Use the record flag to track which files are installed.

    $ sudo python3 setup.py install --record installedfiles.txt

  • Create an uninstall.sh script.

How to do software de-bounce?

What's a good way to do a software de-bounce when using interrupts on the PiFace? I've tried with just a sleep in the interrupt routine, hoping it would just pause that thread/process and then do another evaluation after the sleep. It didn't work that well though, sometimes it misses interrupts because of this (like if the return to 0 is within my 100ms sleep then I won't get another interrupt to indicate that the pin is now 0, even if the previous interrupt was 1.

SimpleWebControl

Hey,

does anyone know how to turn a relay on or off using the simplewebcontrol script?

setup.py does not check for pifacecommon version

pifacedigitalio v2 requires pifacecommon v2 but the installer only checks for any version of pifacecommon.

Packages and modules should contain version numbers so that this is detected and the correct dependency versions are installed.

A temporary fix is to install pifacecommon manually from: github.com/piface/pifacecommon

Pi face was working and now is not

My piface was working. Then I dropped my motor and cables were disconnected from one of the 2 relays on the board. Now I can't seem to control my board. I use the emulator but it seems to have no effect on my outputs. No LEDs light up on demand anymore. Is there a way to determine if my board is ruined?.... A way to test it besides the emulator / Python.

Add Content-length to simplewebcontrol example to increase compatibility.

I had the problem that the HTTPRequest node (a HTTP client) from the godot engine doesn't handle the JSON content from the simplewebcontrol server example (examples/simplewebcontrol.py). The JSON content was always discarded. I have to add the Content-length property to the header at the simplewebcontrol example. I think this changes could also increase the compatibility of other HTTP clients and browsers. The pull request #42 adds the necessary changes.

Raspberry pi 2 Piface digital 2

There seems to be a problem with simple InputEventListener.
The emulator works as well as output pins and input pins.
After trying several programs, I attempted the examples.
Blink works, presslights does not, whackamole does.

Two boards and 3 SD cards have been tried, with update and upgrade.
Have I missed something?
Thanks

Documentation - Examples

Line 5 in examples starts off with board1. Very confusing to noob, as factory setting is board0, ,and most noobs will only have one board. Have seen complaints about this elsewhere. Knew it was a doc problem, since Pi face worked on pfio under Python 2.7

Event in callbacks should be optional.

The InputEventListener.register function should have a flag to optionally send events to callback functions.

import pifacedigitalio

def somefunction():
    """This function has no event argument."""
    pass

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, somefunction, send_event=False)
l.activate()

somefunction is not passed an event object because send_event was set to False in the register function. send_event will default to True.

I'm not sure whether this should be implemented or not because it allows programmers to be inconsistent in callback definitions and you can just ignore the event anyway.

It is useful for directly calling existing library functions, that don't accept event objects. For example:

import robot

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, robot.walk, send_event=False)
l.activate()

robot.walk() is not expecting any event objects so we do not send it any. Currently this can be wrapped up with:

import robot

def do_robot_walk(event):
    robot.walk()

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, do_robot_walk)
l.activate()

PHP and pifacedigitalio

Hello,

i've just started with the Piface.
I have a PHP code that opens my Python script, this works fine.
And the Python script works on the Raspberry Pi (in the terminal).

But when i place this, in the Python script, the PHP script stops and doesn't do anything :

import pifacedigitalio
pifacedigitalio.init()

Can anyone please help me?

Sorry for my bad english.

Greetings Hendrik

Missing required files from tar.gz on PYPI

Tried to install 3.0.0 using pip from PYPI. The tarball on PYPI is missing files required by setup.py. These files are in github, but missing from the tarball.

README.md
CHANGELOG
etc ...

raspberry pi 2 and piface 2 - board not found

I bought all new and tried to run some sample code.
But the board will not be found not under X nor on the
console. I've tried python and ruby as well.

The python output is

root@raspberrypi:/home/pi# python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio as pfio;
>>> pfio.init();
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pifacedigitalio/core.py", line 166, in init
    raise failed_boards[0]
pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).
>>>

any ideas?

root@raspberrypi:/home/pi# uname -a
Linux raspberrypi 3.18.5-v7+ #225 SMP PREEMPT Fri Jan 30 18:53:55 GMT 2015 armv7l GNU/Linux

root@raspberrypi:/home/pi# dpkg -l | grep pif
ii  python-pifacecommon                   4.0.0-1                                 all          The PiFace common functions module.
ii  python-pifacedigitalio                3.0.4-1                                 all          The PiFace Digital I/O module.
ii  python3-pifacecommon                  4.0.0-1                                 all          The PiFace common functions module.
ii  python3-pifacedigital-scratch-handler 2.0.5-1                                 all          The PiFace Digital Scratch Handler.
ii  python3-pifacedigitalio               3.0.4-1                                 all          The PiFace Digital I/O module.


root@raspberrypi:/home/pi# gem list
*** LOCAL GEMS ***
ffi (1.9.6)
piface (0.4.1)

outputs status

hello,

i've just re-install my piface and so upgrade to the 3.0.5 version.
but i was using the command : pfio.read_output() and it's not working anymore.

how can i know now the status of all my outputs?

thanks for help.

ps: excuse my english, i'm french

Relays don't swicth off after being on for more than 5 minutes

I noticed that the indicator LED goes on/off but the relay itself doesn't.

If I slap the raspberry pi box it turns off. It seems to be a physical issue but I already tested all the other 3 pifaces i have and they behave the same way.

Have someone faced this issue before?

Setup: Raspberry 2 and Piface Digital 2

Cannot Allocate Memory when using Interrupts

So i created a fairly simple python program counting pulses using interrupts and i tested it on the bench with a single input for a couple of days and everything seemed to work well, when i started to use it for real i had 5 inputs and the pulse frequency was a bit higher, after around 22 hours the counting would stop. When i looked into why it could see that Python3 memory use was going up and up everytime a pulse was counted. The first thing i did was to create a test program that only counted and the problem persists with the pi eventually giving the error Cannot Allocate Memory - my test code is here;

def testcount(event):
global Count1
Count1 += 1
print(Count1)

Setup the Digital IO to watch for Rising Edge only

pifacedigital = pifacedigitalio.PiFaceDigital()

listener = pifacedigitalio.InputEventListener(chip=pifacedigital)
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, testcount)
listener.activate()

Here is a screen shot of the pi back on the bench showing the memory use rising. it only rises when a pulse is received

sc2

There is no CI to automatically update PyPi

According to The Hitchiker's Guide, PyPi is the right solution to distribute Python software as it is cross-platform (many Linuxes, macOS and Windows I think).

GitHub supports Travis CI to automatically test and deploy (push to PyPi) software, which is something pifacedigitalio and friends require. With this change, bug fixes and improvements in the form of Pull Requests can reach users without too much intervention.

Tasks include:

  • Research Travis CI
  • Write CI configuration
  • Link project to Travis CI

Pifacedigitalio for C

Hello,
I need the library Pifacedigitalio for C, Is there any version for this language?

I need to use the InputEventListener function but I can not find any equivalent for C.

Could you help me?

Thank you.

interupt prpblems

I have a fresh install on my Pi and I cannot get the interupt code working i run
sudo python3 presslights.py

it just sits there and doesn't respond to switch presses. I have tried other example code and I get nothing on any of the interupts that I've tried.

I have no idea what the problem is, eventually i press ctrl-x-c and get

^X^CException KeyboardInterrupt: KeyboardInterrupt() in <module 'threading' from '/usr/lib/python3.2/threading.py'> ignored
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
self._target(_self._args, *_self._kwargs)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/interrupts.py", line 160, in watch_port_events
events = epoll.poll()
KeyboardInterrupt

Please help as I've just bought 5 pi faces for some school projects.

Thanks
Martyn

Piface Digital nt working in Buster

Any reads from the piface chip are all returning 0. I don’t know if it’s a kernel issue or what.

Has this been tested on Buster?

OS Version: | Raspbian GNU/Linux 10 (buster)
Kernel Version: | 4.19.66-v7+

Another PiFace interrupt problem

Hi,

I'm having a problem with interrupts. I have a Pi 3 Mod B connected to a PiRack with 3 PiFaces installed; the PiFaces are set to addresses 0, 1 and 2. I installed Raspbian Jessie and all updates plus the pifacedigitalio packages on the Pi, then ran 'sudo apt-get update/upgrade' to update everything. I also ensured the SPI was enabled using raspi-config. The PiRack jumpers are set to external power for all slots, and both the PiRack and the Pi are powered from a common 5V/4A switched power supply. Nothing else is plugged into the Pi (e.g. USB, HDMI, etc.). The SPI jumpers on the PiRack are J1/3/5/7 set to 2-3 and J2/4/6/8 set to 1-2. I modified the blink.py program to test it all out:

from time import sleep
import pifacedigitalio

DELAY = 1.0 # seconds

def int_event0(event):

print('In interrupt event 0: pin - ' + str(event.pin_num) + ', dir - ' + str(event.direction))

def int_event1(event):

print('In interrupt event 1: pin - ' + str(event.pin_num) + ', dir - ' + str(event.direction))

def int_event2(event):

print('In interrupt event 2: pin - ' + str(event.pin_num) + ', dir - ' + str(event.direction))

def main():
pifacedigitalio.init()
pf0 = pifacedigitalio.PiFaceDigital(hardware_addr=0)
listener0 = pifacedigitalio.InputEventListener(chip=pf0)
listener0.register(0, pifacedigitalio.IODIR_FALLING_EDGE, int_event0, settle_time=0.1)
listener0.register(1, pifacedigitalio.IODIR_FALLING_EDGE, int_event0, settle_time=0.1)
listener0.register(2, pifacedigitalio.IODIR_FALLING_EDGE, int_event0, settle_time=0.1)
listener0.register(3, pifacedigitalio.IODIR_FALLING_EDGE, int_event0, settle_time=0.1)
listener0.activate()

pf1 = pifacedigitalio.PiFaceDigital(hardware_addr=1)
listener1 = pifacedigitalio.InputEventListener(chip=pf1)
listener1.register(0, pifacedigitalio.IODIR_FALLING_EDGE, int_event1, settle_time=0.1)
listener1.register(1, pifacedigitalio.IODIR_FALLING_EDGE, int_event1, settle_time=0.1)
listener1.register(2, pifacedigitalio.IODIR_FALLING_EDGE, int_event1, settle_time=0.1)
listener1.register(3, pifacedigitalio.IODIR_FALLING_EDGE, int_event1, settle_time=0.1)
listener1.activate()

pf2 = pifacedigitalio.PiFaceDigital(hardware_addr=2)
listener2 = pifacedigitalio.InputEventListener(chip=pf2)
listener2.register(0, pifacedigitalio.IODIR_FALLING_EDGE, int_event2, settle_time=0.1)
listener2.register(1, pifacedigitalio.IODIR_FALLING_EDGE, int_event2, settle_time=0.1)
listener2.register(2, pifacedigitalio.IODIR_FALLING_EDGE, int_event2, settle_time=0.1)
listener2.register(3, pifacedigitalio.IODIR_FALLING_EDGE, int_event2, settle_time=0.1)
listener2.activate()

while True:
    pf0.leds[7].toggle()
    pf1.leds[7].toggle()
    pf2.leds[7].toggle()
    sleep(DELAY)

if name == "main":
main()

When I run it as 'sudo python3 blink.py' the LEDs on all 3 PiFaces start blinking, but when I press any of the 4 buttons on the PiFaces (which should generate interrupts) nothing happens. Any suggestions?

Thanks

Event handler hanging/dying?

Hi,

I think I may have a problem with pifacedigitalio, but I'm not sure. I have a RPi Model B, all the latest updates, with 2 PiFaces connected via a PiRack. I have 8 door sensor switches connected to the 8 inputs on first PiFace, and an event handler defined to track door opens/closes. The 2nd PiFace has 2 motion sensors connected and a relay that trips when my house power goes out, connected to the inputs. I have separate event handlers for the door sensors, the 2 motion sensors and another one for the power-out relay. When I run my Python app it all works perfectly - door opens/closes get logged, motions and power outages get detected, etc. However, when I let everything run overnight at some point both of the event handlers (motion & power) for the 2nd PiFace stop working (the door interrupts on the 1st PiFace continue to work with no problem) and the events are no longer detected. I thought it might be a bug in my Python event handler code, so I left it running in a console window and no exceptions were displayed. If I interrupt the program and restart it everything works again, which makes me tend to think it's a sw problem, but I'm not sure how to verify.

Is there any way I can regularly check the status of the event handlers in my program to verify they are still active?

Thanks.

John

PiFace Digital 2 isn't detected

Evening folks,

I recently got my hands on a PiFace Digital 2, however, I'm struggling to make my Raspberry detect it.

Following the instructions found on the official page, I started by installing the latest Rasbian Stretch Lite and getting everything up to date:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade

I enabled SPI using raspi-config and downloaded the necessary modules with pip, since they weren't in the repositories anymore:

    sudo pip3 install pifacedigitalio
    sudo pip3 install pifacecommon

Full of hope, I started a Python3 session and wrote the commands found on this page:

    import pifacedigitalio
    pfd = pifacedigitalio.PiFaceDigital()

For my efforts however, I was awarded with this error message:

    Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/local/lib/python3.5/dist-packages/pifacedigitalio/core.py", line 82, in __init__self.init_board()
        File "/usr/local/lib/python3.5/dist-packages/pifacedigitalio/core.py", line 107, in init_board
    h=self.hardware_addr, b=self.bus, c=self.chip_select))pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).

Thus, I've found a bunch of people with the same problem but no solution. I've double checked everything a few times and made sure SPI is enabled. Any suggestions?

Piface Digital 2 InterruptEnableException

Hi all

I am VERY new to Raspberry pi and linux in general, so please excuse the noob questions.

I have followed the Piface Digital 2 installation instructions to the letter, however receive an interrupt error on line 213 of the Interrupts.py script when I try to run the blink.py script. I am using python 2 by default, but have tried to run the blink.py script under both python 2 and 3. I have attached response in both versions.

At first I thought the problem may relate to the SPI driver, but I have enabled the port and tested it by bridging the MOSI and MISO pins and running spidev_test.c. I receive the correct response.

python 2

start using python2

python 3

start using python3

Any help would be greatly appreciated.
Kind regards
Simon

Can not set pullup values

digital_write_pullup() does not work because it calls read_pullup() which is a typo. Should be read_pullups(). Same bug exists in the github piface repo.

Need a little more documentation on the pullup stuff. E.g. what is the default setting? Can you pull up, pull down, or leave floating?

Raspberry Pi 2, Piface Digital 2 interrupt

There seems to be a problem with simple InputEventListener.
The emulator works as well as output pins and input pins.
After trying several programs, I attempted the examples.
Blink works, presslights does not, whackamole does partially.
Two boards and 3 SD cards have been tried, with update and upgrade following instructions.

Have I missed something?

Additional information has been observed.
When rebooting, an error flashes by which says:
"Error loading module spi-bcm 2708 no such module."

lsmod shows: spi_bcm2835 4253 0
also shows: snd_bcm2835 19761 6

/lib/modules/4.0.8-v7+/kernel/drivers/spi/ has two files: spi-bcm2708.ko and spi-bcm2835.ko
The actual device shows to be bcm2709.

Thanks for any help on resolved the interrupt issue, which appears to be related to the bcm module

Install Issue

Having a problem with the installation of piface on a Pi 3

Went through all the steps and get the following form the console
pi@raspberrypi:~ $ sudo apt-get install python{,3}-pifacedigitalio
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pifacedigitalio
E: Unable to locate package python3-pifacedigitalio

Tried cloning and I get the same result.

Board resets on calling PiFaceDigital()

With reference to the sample code

pfd = pifacedigitalio.PiFaceDigital()

has the effect of resetting the pins to default values.

Maybe this is intentional or a bug? I don't know

Anyway, the workaround that I use is the following

pfd = pifacedigitalio.PiFaceDigital(init_board=False)

Note, that the board still needs to be initialised at least once after initial boot.

ImportError: No module named 'pifacecommon'

Just started a new install of Stretch. I could not load through apt-get tried pip3. Pip3 said it was ok.
This is the error that I got

Traceback (most recent call last):
File "facke_bubble1.py", line 3, in
import pifacedigitalio
File "/usr/local/lib/python3.5/dist-packages/pifacedigitalio/init.py", line 18, in
from pifacecommon.interrupts import (
ImportError: No module named 'pifacecommon'

Problem when deactivating the SwitchEventListener

Hej

I am trying to exit my Python program when pressing a Button from the PiFace. A Event Listener is used, like described at the examples. It seems that "listener.deactivate()" makes a join on active thread. If it is the main thread of the process it fails and lead to a python hang up.
I attach a demo code:

#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 03.04.2015

@author: stj
'''

import os
import sys
import distutils.spawn
import pifacecad
import time

def checkExecutableProgram(program):
    print('check '+program)
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK) 

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                print(' is executable')
                return exe_file

    return None

def getExecutableFileList (searchPath, extra=['py']):
    print('crawl '+searchPath)
    pL = []
    for (dirpath, dirnames, filenames) in os.walk(searchPath):
        for f in filenames:
#            if (f.endswith('py') is True) or (checkExecutableProgram(f) is not None):
#if (f.endswith('py') is True):
            if (checkExecutableProgram(f) is not None):            
                pL.append(os.path.join(dirpath,f))
    return pL


def printToLCD(line1, line2):
    global cad

    prtStr = line1 + '\n' + line2
    cad.lcd.clear()
    cad.lcd.write(prtStr)

def updateDisplayFiles():
    global gIndx
    global gFL
    global gFLlen

    if gIndx < 0:
        printToLCD('<none>','<none>')
        return
    l1 = '> ' + gFL[gIndx]
    l2 = '<none>' if (gIndx+1 >= gFLlen) else gFL[gIndx+1] 
    printToLCD(l1,l2)

def moveUp(e):
    global gIndx

    if gIndx > 0:
        gIndx -= 1
    updateDisplayFiles()

def moveDown (e):
    global gIndx

    if gIndx < gFLlen-1:
        gIndx += 1
    else:
        gIndx = gFLlen - 1
    updateDisplayFiles()

def execute(e):
    global gIndx

    if gIndx < 0:
        printToLCD('nothing to execute','')
    else:
        printToLCD('execute','wait ...')
    os.system( gFL[gIndx])
    #execfile(gFL[gIndx] , {} )
    printToLCD('finished','')

def printEvent(e):
    print(e)


def exitCB (e):
    global listener

    listener.deactivate()
    sys.exit(0)


if __name__ == '__main__':
    global cad
    global listener
    global actionHandler

    cad = None
    listener = None
    gFL = getExecutableFileList(os.path.expanduser("~"))
    gFLlen = len(gFL)
    gIndx = -1 if gFLlen < 1 else 0

    actionHandler ={
        6 : moveUp,
        7 : moveDown,
        5 : execute,
        4 : exitCB
        }

    cad = pifacecad.PiFaceCAD()
    cad.lcd.backlight_on()


    printToLCD('starter v.1.0', 'select file')
    time.sleep(2)
    updateDisplayFiles()
    try:
        listener = pifacecad.SwitchEventListener(chip=cad)
        for i in range(8):
            h = actionHandler.get(i, printEvent)
            listener.register(i, pifacecad.IODIR_FALLING_EDGE, h)
        listener.activate()
    except Exception as e:
        print(e)
        listener.deactivate()

    sys.exit(0)

and the consol error print:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/pifacecommon/interrupts.py", line 339, in handle_events
    function(event)
  File "stjStarter.py", line 99, in exitCB
    listener.deactivate()
  File "/usr/lib/python3/dist-packages/pifacecommon/interrupts.py", line 220, in deactivate
    self.dispatcher.join()
  File "/usr/lib/python3.2/threading.py", line 844, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

Interrupts with Multiple PiFace boards

Hi all,

I am having a problem with interrupts when using multiple PiFace boards. I have a Model A Pi connected to multiple PiFace boards via a PiFace Rack.

If I have only 1 PiFace connected I can receive interrupts fine. Once I connect a second PiFace with different hardware address my interrupts are no longer received.

I have tried receiving interrupts using pifacecommon and pifacedigitalio methods.

pifacedigitalio test code is as follows

import pifacedigitalio as p
import pifacedigitalio.version as pfdioV
import pifacecommon.version as pfcV
import time

quit = False

def print_flag(event):
    print("You pressed button ", event.pin_num)

def stop_listening(event):
    global quit
    quit = True

p.init()

print("pifacedigitalio version = ", pfdioV.__version__)
print("pifacecommon version = ", pfcV.__version__)

pfd = p.PiFaceDigital(0)

l = p.InputEventListener(pfd)

l.register(0, p.IODIR_OFF, print_flag)
l.register(1, p.IODIR_OFF, print_flag)
l.register(2, p.IODIR_OFF, print_flag)
l.register(3, p.IODIR_OFF, stop_listening)

l.activate()

while not quit:
    time.sleep(1)

l.deactivate()

pifacecommon test code is

import pifacecommon.core
import pifacecommon.interrupts
import pifacecommon.mcp23s17
import time

quit = False

def print_flag(event):
    print("You pressed button ", event.pin_num)

def stop_listening(event):
    global quit
    quit = True

port = pifacecommon.mcp23s17.GPIOB
chip = pifacecommon.mcp23s17.MCP23S17()

listener = pifacecommon.interrupts.PortEventListener(chip=chip, port=port)

listener.register(0, pifacecommon.interrupts.IODIR_FALLING_EDGE, print_flag)
listener.register(1, pifacecommon.interrupts.IODIR_FALLING_EDGE, print_flag)
listener.register(2, pifacecommon.interrupts.IODIR_FALLING_EDGE, print_flag)
listener.register(3, pifacecommon.interrupts.IODIR_FALLING_EDGE, stop_listening)

listener.activate()

while not quit:
    time.sleep(1)

listener.deactivate()

Not sure if I am missing something or if there is an issue. I have tried on multiple PIs using multiple PiFaces.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.