8 Replies Latest reply on May 20, 2018 7:11 AM by smile123

    Piface CAD - Event/Interrupt for keys

    xylophone

      Have you successfully writen a python script supporting the switch event from the PiFace CAD?

      I can't get it to work.

      The display is fine, and I can poll the state of the switches satisfactorily.

      Also no success with infrared events, although again the poll application shows that the receiver is working fine.

       

      I tried running the sample train times and radio application examples, and whilst they show something, there is no way to interact with it since the buttons don;t register.

       

      I was wondering if there was an interrupt not configured somewhere...

      I think the syntax I tried is correct (and anyway the example programs run without error)

       

      Any ideas appreciated!

       

       

       

      xylo

        • Re: Piface CAD - Event/Interrupt for keys
          andrewrobinson

          Could you try the following test code?

          1 of 1 people found this helpful
            • Re: Piface CAD - Event/Interrupt for keys
              xylophone

              Hi Andrew

              thanks for this code.

              I ran it and got a blank (but backlit) display.

              There is no activity.

              If I press buttons nothing happens (from the code it looks like I should see stuff on the shell window?)

              I ran another app which writes to the lcd and it works, as I said, but no event action...

               

              Regards,

               

              Tim

              • Re: Piface CAD - Event/Interrupt for keys
                xylophone

                Hello again

                 

                I'm afraid I can't get this to work and can only assume that either the CAD board or the original PI is faulty in some way.

                I don't understand how the low level software interacts with data changes on the GPIO interface from the buttons on the CAD board - I assume they're somehow coded into SPI?

                 

                As I said, writing to the display is fine, as is explictly reading the state of the switches. I just can't get the event callback to work at all.

                 

                I think I have an early model B - it has 256K RAM - I'm not sure what other info I should look for. I don't really want to send it back just in case, but I don't have access to another PI to see if it's the PI itself.

                 

                The OS is the latest Raspbian, updated python etc., including downloading the beautiful soup stuff so the traintimes demo will run.

                (Again, this one shows up manchester piccadilly times fine, but you can't change to another station because the buttons don't work...

                 

                As a former hardware and software designer I am frustrated with my lack of hardware specific knowledge on this system... but in the first place I kinda expected it to "just work".

                 

                Any further pointers would be great - I'd like to interest my children in this but until it interacts I'm not feeling very hopeful to capture their attention!

                 

                 

                Cheers,

                 

                Tim

                  • Re: Piface CAD - Event/Interrupt for keys
                    xylophone

                    Hmm - update!

                    If I do this on the Python3 terminal shell  it works OK - my problem is using IDLE3.

                    I wonder if there is something I've missed in running the apps from the IDE shell?

                    Sorry I didn't clarify this before....

                     

                     

                     

                    Kind Regards,

                     

                    Tim

                    • Re: Piface CAD - Event/Interrupt for keys
                      pkilcoyne

                      Hi there,

                      I'm having the exact same problem as yourself. Just wondering have you found a solution?

                       

                      Also, I put together the following script:

                       

                      import time, os

                      import pifacecad

                       

                      cad = pifacecad.PiFaceCAD()

                      listener = pifacecad.SwitchEventListener(cad)

                       

                      def button_pressed(event):

                              print('you pressed', event.pin_num)

                       

                       

                      listener.register(0, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(1, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(2, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(3, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(4, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(5, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(6, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                      listener.register(7, pifacecad.IODIR_FALLING_EDGE, button_pressed)

                       

                      listener.activate()

                       

                      ***********

                       

                      I run it initially, via "python3 myscript.py", and nothing happens when I press switch 1 for example.

                       

                      I quit the programme via a CTRL C but the next time I run it I get printed to my terminal screen: "you pressed 1"

                       

                      Does this make sense?

                       

                      Is this script running as expected?

                       

                      Thank you,

                       

                      Paul

                  • Re: Piface CAD - Event/Interrupt for keys

                    Your post got orphaned.

                    Re: orphaned discussions

                     

                    You can move it to the PiFace discussion group

                    PiFace Control and Display

                    by using the Move button under the Actions heading on the

                    right-hand side of your screen.