element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum PiFace Digital 2 - setup and use
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 35 replies
  • Subscribers 672 subscribers
  • Views 15250 views
  • Users 0 members are here
  • raspberry_pi
  • piface_digital_2
  • raspeberry_pi_accessories
Related

PiFace Digital 2 - setup and use

urkraft
urkraft over 10 years ago

PiFace Digital 2

 

Introduction

 

I used the PiFace Get Started Guide created by Joseph Man for the previous version of the PiFace Digital as my starting point as i was unable to find any documentation specifically for the PiFace Digital 2 and as both designs appeared to be very similar with only the changes necessary in order to accommodate the 40 pin GPIO of the Raspberry Pi B+ and to allow the physical mating without any obstructions as well as a radical improvement of the layout . There were nevertheless a few things in that document which required further investigation and improvising in order to get it to work.

 

Although the Raspberry Pi B+ is capable of supplying power to a greater electrical load than its predecessor with the correct configuration and an adequate power supply, i do not believe that it is a good idea to rely on it to be able to take the load that this type of card could represent under certain circumstances. Since i did not have any extra power supplies to use to power the output of the PiFace card i had to use the 5V from the Raspberry Pi B+, so i used my powered USB hub to connect all by usb devices (mouse, keyboard, and sound card) in order to reduce the load on the Raspberry Pi's power supply. By doing this and only testing one output at a time i was quite sure that there was little likelihood of me experiencing problems due to overloading the power supply and i also did not need to make any changes to the default jumper configuration that the PiFace came with. My PiFace came with all the 2-pin jumpers shorted and JP1 and JP2 had the two left pins short circuited when viewed as shown in the picture below. Hopefully the official documentation will be available by the time i can get a hold of a good power supply for the PiFace and gadgets to control with it.

 

Configuring the Raspberry Pi B+ for the PiFace Digital 2

Before i connected the PiFace Digital 2 i did all the general preliminary configuration necessary for a Raspberry Pi  B+ (referred to as "RPi" from now on). I installed the Raspbian operating system on my RPi, booted it up, did all my special configurations, rebooted, logged in, updated everything to the latest versions by typing the following the following commands in the console:

 

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo reboot

 

After it had done all the work and was up again, i logged in again and enabled the SPI driver by making the necessary changes via raspi-config and by editing the raspi-blacklist.conf file. First, the raspi-config changes (in the console):

 

sudo raspi-config

 

This starts the configuration software for the Raspberry Pi. You need to navigate down to the "Advanced Options" menu with the down arrow key, tab to <Select>, press "Enter", arrow down to "A5 SPI", tab to <Select>, hit "Enter", highlight <Yes> with the appropriate arrow key and press "Enter", hit "Enter" again on <OK>, tab to <Finish> and hit "Enter". You should then be back in the console again. Enter:

 

sudo shutdown -Ph now

 

After the Pi has shut down, remove all connections, connect the PiFace Digital 2, reconnect everything - saving the power connection for last, and log in at the prompt when it is up again, then, in the console type:

 

sudo nano /etc/modprobe.d/raspi-blacklist.conf

 

Make sure that there is a hash (#) at the start of the line "blacklist spi-bcm2708" in the file and save the file and exit. Then, in the console again, type:

 

sudo apt-get update

wget http://pi.cs.man.ac.uk/download/install.txt | bash

sudo apt-get install python3-pifacedigitalio python-pifacedigitalio

sudo apt-get install python3-pifacedigital-emulator

sudo apt-get install python3-pifacedigital-scratch-handler

sudo reboot

 

After the last reboot is finished you can login start the LXDE GUI (startx) and you will find an icon for the "Pi Face Digital" emulator on the desktop. Double click it and click the "Enable" menu and choose "Output Control". This enables controlling the output of the output on the Pi Face Digital via the emulator buttons. Go wild! Test all of the output signals as well as the 4 input signals that the buttons were connected to without any further hardware configuration or connections.

 

When you are finished playing around with the emulator you are ready to play around with Python.

 

First steps with Python

 

To use PiFace Digital 2 with Python you need to import the pifacedigitalio module by typing the following line at the beginning of your Python script:

 

import pifacedigitalio as pfio

 

Before using it the board must be initialized with a call to init(), like this:

 

pfio.init()

 

There are three main functions to control the interface:

 

pfio.digital_read(pin_number)

 

which returns 1 or 0 depending on the state of the input numbered pin_number

 

pfio.digital_write(pin_number, state)

 

sets the output numbered pin_number to state 0 or 1. State 1 turns the LED on and enables the open collector to sink current

 

pfio.digital_write_pullup(pin_number, state)

 

sets a 10k pullup on input numbered pin_number to be state 0 or 1. State 1 is pullup enabled.

 

Based on this information you should be able to follow the examples of reading and writing to the PiFace Digital 2 that Joseph Man gives in that section of his document - but just remember to import the correct module and not the one that he refers to. Alternatively, you can download the Python2 script that i have made and attached to this document and play around with that (more about that further down in this document). But you should make sure that you have really understood which connection terminals are controlled by the signals you will be activating with Python. Hopefully this will be quite clear after reading the next section.

 

Tour of the PiFace Digital 2

 

image

Picture Description:

IO connection terminals: Starting from the bottom right corner of the picture above and working counter clockwise along the PCB edge

  • (O-0) first up are the 3 connection terminals for the first relay which is controlled by output 0. The first terminal is connected to the Normally Open (NO) terminal of the relay, the second is connected to the Common (C) terminal, and the third to the Normally Closed (NC) terminal.
  • (O-1) next are the 3 connection terminals for the second relay which are controlled by output 1. The first terminal is connected to the Normally Open (NO) terminal of the relay, the second is connected to the Common (C) terminal, and the third to the Normally Closed (NC) terminal.
  • Next are two ground connections, followed by a 5V connection.
  • Then on the top edge of the card starting from the right is a 5V connection followed by the 8 terminals that are connected to the open collector outputs (the orange connection blocks). These are controlled by output 0 through 7 in that order. The corresponding surface mounted LEDs can be seen just below. Note that output 0 controls the first relay, LED 0, and the open collector 0.
  • Next up to the left of the outputs along the top edge are the input terminal connections (the green blocks), beginning with input 0 through to input 7, then lastly a connection for ground. Below these are the 4 push button switches. Input 0 through 3 are controlled by the status of the switches as well as the signal levels of the input teminals. For example, either S0 must be activated or the signal level at input terminal 0 must be high or both must be active for input 0 to be interpreted as '1'.

 

I have tested every input and output on my PiFace Digital 2 - both with the emulator and with my own Python3 script (actually the only input i tested with my script was the push button input signals) - and everything worked as expected.

 

The led_show.py Python3 script

 

This is only a simple script that i wrote to test the Python module which is used specifically for controlling the PiFace Digital 2 card. Of course, it simultaneously tests all of the on-board LED's and push button switches. I used the emulator to perform the other hardware tests described later in this document.

 

Be aware that you do need to have successfully installed all of the Python modules as described at the beginning of this document for this script to work, and it has to be run with root privileges by (for example) using the following command from the same directory that you have placed the script:

 

sudo python3 led_show.py

 

It is a very simple and primitive script, but it demonstrates how to initialize the module and how to read from and write to the PiFace Digital 2 board.

 

How i tested all of the IO using the emulator

 

To test the inputs i simply read the signals at each of them in turn before and after shorting them to the ground terminal which is beside the input 7 terminal. I also read the push button signals before and after pushing them.

 

To test the outputs i used an LED in series with a 180Ω resistor and tested each output in turn as follows. I connected the 5V terminal that is beside the output 0 terminal to the 180Ω resistor, and the other end of the resistor to the anode of the LED (the longest terminal on a new LED), and from the cathode of the LED to the output terminal being tested. Writing a 1 to the output being tested turned the LED on, and writing 0 turned it off (exactly as with the respective on-board LED). To test the relays required a slightly different approach. Here, i connected the same circuit, but with the cathode of the LED connected to the Common (C) terminal of the output relay being tested. I also grounded either the Normally Closed (NC) terminal or the Normally Open (NO) terminal. If it was the NC terminal that was grounded then the LED would light up when a 0 signal was sent to the output that controlled it, and it would go out if a 1 signal was sent to it. If it was the NO terminal that was grounded than it would function in the opposite way.

 

I hope this information is helpful while you are waiting on the official documentation.

Attachments:
led_show.py.zip
  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 10 years ago

    I Appreciate all the work you have done. You are right about the lack of docs. I have got the digital 2 working, however can you share how the relays are operated?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • urkraft
    urkraft over 10 years ago in reply to Former Member

    Hello James,

     

    Thought i explained that at the end of my description about setup and use found here: http://www.element14.com/community/thread/39390/l/piface-digital-2--setup-and-use where i wrote:

     

    "To test the relays required a slightly different approach. Here, i connected the same circuit, but with the cathode of the LED connected to the Common (C) terminal of the output relay being tested. I also grounded either the Normally Closed (NC) terminal or the Normally Open (NO) terminal. If it was the NC terminal that was grounded then the LED would light up when a 0 signal was sent to the output that controlled it, and it would go out if a 1 signal was sent to it. If it was the NO terminal that was grounded than it would function in the opposite way."

     

    You can modify the Python code that i supplied to manipulate the LED's that share the same outputs.

     

    Let me know if there is anything specifically that you would like for me to elaborate on?

     

    Regards,

    raymond

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Hi Raymond,

     

    many thanks for your detailed giude!

    I am a linux newbie and I'm struggling to setup piface digital2 on my brand new RaspberryPi B+. Actually all steps from your procedure completed without errors but virtual device GPIO is missing and as a result pifacedigital-emulator gives an exception on startup.

    I did look for /dev/spidev0.0 and /dev/spidev0.1 and they are present (so I guess kernel module is ok).

    I did also look for /sys/class/gpio which is present, and tested doing echo 25 > /sys/class/gpio/export, it actually create /sys/class/gpio/gpio25 so permissions are ok.

     

    Any idea on what to check next would be very appreciated!

     

    Thanks,

     

    Daniele

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • urkraft
    urkraft over 10 years ago in reply to Former Member

    Hello Daniele,

     

    Firstly, i would like to point out that official documentation for the PiFace Digital 2 is now available, and that it should be used instead of the document that i published when it was still undocumented.

     

    And now i address your problem:

     

    I am almost certain that your problems are due to you running this command that was included in my document:

     

    sudo rpi update

     

    I apologize deeply for including it in my documentation. I have found out a short while ago that that command is only meant to be used for advanced Raspberry Pi users to test an experimental version of the kernel. Unfortunately some major changes are introduced in the latest experimental version which i am quite sure are responsible for the problems you are experiencing. You need to roll back to the last official version by issuing the following 2 commands (and NEVER use the above command unless in a normal Raspberry Pi working environment):

     

    sudo apt-get --reinstall install libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0 raspberrypi-bootloader

    sudo reboot

     

    After the Raspberry Pi has rebooted and you log in the problem should no longer be there.

     

    Again, i apologize for including the command that has caused you these problems. When i created the document that i had published i included it because i found a reference somewhere on the internet suggesting that it always be used when updating the Raspberry Pi. That source did not mention anything about it's real purpose.

     

    Regards,

    raymond

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • urkraft
    urkraft over 10 years ago

    Please DO NOT use this command which is included in the documentation above:

     

    sudo rpi update

     

    The command invokes an experimental version of the kernel and is not meant for use by normal Raspberry Pi users. I apologize for including it in the documentation that i published. When i created the document i was not aware of it's true purpose. Unfortunately i am not allowed to edit my own document in order to correct it.

     

    Regards,

    raymond

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to urkraft

    Hi Raymond,

     

    thank you for the explaination.

    I made a little bit more of research and I found out about overlays... Not that I master this concept but the basic effect is that I have to explictly enable additional devices to be inserted in device tree by adding a line in config.txt

    So I gave it a shot and added to my config.txt the following two lines:

     

    dtparam=spi=on

    dtoverlay=bcm2708-rpi-b-plus.dtb

     

    After rebooting everything is working perfectly. Now, if this change introduced in firmware is a 'preview' of what is coming in the future, I think that keeping my current firmware (and config) is ok even in case of future upgrades, correct?

    In any case thank you very much for your help!

     

    Regards,

     

    Daniele

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    Hi,

    I more or less have the same problem as Daniele.

     

    I use a Raspi B with a Piface Digital 1. Everything worked fine until yesterday.

    Yesterday I upgraded the Raspian to version 3.18.5+. The piface python stopped working with:

         IOError: [Errno 2] No such file or directory: '/sys/devices/virtual/gpio/gpio25/value'

     

    The virtual/gpio directory does not exist anymore and I don't know how to create it with the links.

     

    Now I started from scratch with a blank SD card and the 31.01.2015 raspian image and python3-pifacedigitalio.

    Same error.

    The spi devs are there:

    ls  /dev/spi*

    /dev/spidev0.0  /dev/spidev0.1

     

    Daniele's config.txt trick  did not help.

     

    gpio readall yields:

     

    +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+

    | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

    +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

    |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |

    |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |

    |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |

    |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |

    |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |

    |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |

    |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |

    |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |

    |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |

    |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |

    |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |

    |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0     | 10  | 8   |

    |     |     |      0v |      |   | 25 || 26 | 1 | ALT0 | CE1     | 11  | 7   |

    +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

    |  28 |  17 | GPIO.17 |   IN | 0 | 51 || 52 | 0 | IN   | GPIO.18 | 18  | 29  |

    |  30 |  19 | GPIO.19 |   IN | 0 | 53 || 54 | 0 | IN   | GPIO.20 | 20  | 31  |

    +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

    | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

    +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+

     

    Any idea, what's going wrong?

     

    Thanks,

    Prisemut

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • urkraft
    urkraft over 10 years ago in reply to Former Member

    Prisemut:

     

    I have explained in great detail how to fix this problem in post 17 of the discussion titled "i2c stopped working". There are many other posts there about possible solutions, but i believe that the solution i have described is the intended one by the developers of the Raspberry Pi. I have tested it extensively and it is the only solution that i have found that has solved all the prolems that i have experienced.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • urkraft
    urkraft over 10 years ago in reply to Former Member

    Since this site is the absolutely most exasperating site i have ever experienced, i decided to copy the solution i have posted elsewhere and post it again here (it is easier than explaining how to navigate in it):

     

    As i have pointed out earlier, the problems appear to be due to changes in the kernel after updating the Raspbian software by issuing these commands:

     

    sudo apt-get update

    sudo apt-get dist-upgrade

     

    and rebooting. This procedure is highly recommended to keep your raspi updated with the latest updates that have been thoroughly tested (and we need to avoid using the "sudo rpi-update" command because that is not meant to be used by normal users but rather by developers and testers). But after doing this the problems with the drivers start because the new kernel comes configured to use the new device tree by default (rather unfortunate, in my opinion). Ok then. What to do? Well i found out that there is also a new update available for raspi-config, and that has a configuration setting which allows you to set up your raspi correctly depending on which device solution you prefer to use. So the first thing you need to do after upgrading the raspi software is to upgrade your raspi-config tool. This is done from the raspi-config tool, and you start the tool with this command:

     

    sudo raspi-config

     

    When the tool starts, you need to navigate down to the "Advanced Options" choice using the arrow-down key, then press the "Tab" key to highlight "Select", then hit "Enter". In the Advanced Options meny, navigate down to the "Update" choice using the arrow-down key, then hit the "Tab" key to highlight "Select", then hit the "Enter" key. This starts the process of updating the tool. When it is finished you will be returned to the raspi-config tool. Back in the tool, navigate down to the "Advanced Options" with the down-arrow, hit the "Tab" key to highlight "Select", hit "Enter", navigate down to "Device Tree" with the down-arrow key, hit "Tab" to highlight "Select", hit "Enter", hit the "Tab" key until "No" is highlighted (in response to the question "Would you like the kernel to use Device Tree?"), then hit "Enter". Hit "Enter" again when it indicates that "Device Tree is disabled" and "Ok" is highlighted. "Tab" to "Finish", then hit "Enter". Now reboot again:

     

    sudo reboot

     

    When the raspi is up again and you log in everything should work again.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    Hi Prise,

     

    I am not an expert but I did find some information googling for raspberry pi device tree overalys. In any case, if you put a line like:

     

    device_tree=

     

    in config.txt the firmware sould revert to old behaviour. I read on some topics that this function will be disabled in the future firmwares so this is only a temporary fix.

    Please note that model B (without plus) overlay should be bcm2708-rpi-b.dtb

    On my image, these files were located in /boot/ check if they are present!

    There is also a debug mode (write a line with dtdebug=1) on config.txt

     

    I hope this help, maybe have a look here as well https://github.com/raspberrypi/documentation/blob/master/configuration/device-tree.md#32-pi-parameters

     

    Regards,

     

    Daniele

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube