element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 673 subscribers
  • Views 16621 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 in reply to urkraft

    Dear Raymond, Daniele,

     

    Thanks so much for your help. Raymod's procedure fixed the problem. I also learned a lot about device trees.

     

    I a bit concerned about this, though. The Piface is targeting on absolute beginners, such as high school students.

    Without this detailed knowledge the board won't work and causes a lot of fustration. I know, that the problem arises from the rasbian image,

    however, a work-around in the piface package would be great. I am not sure, if this is possible.

     

    By the way:

    I used the board for home automation. I attached door switches, an RFID-reader-Keypad and a 433MHz transmitter (element14 nr. 1304024) to the Piface.

    it works like a charme, If the door opens without RFID-identification, the buzzer sounds and light goes on an a send messages to my Telegram account.

     

    Prisemut

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

    The world is constantly evolving. Unfortunately i have not had time to learn about the new method of handling devices that has been introduced recently, but i believe that it was introduced because it is perceived as progressive. What was unfortunate, in my opinion, was that no fore-warning was given to the general public prior to its introduction (at least none that i managed to pick up on - and i check out raspberrypi.org almost daily) when existing drivers that are actively in use cannot work with the new method, and then this combination of events occurred simultaneously:

    • launch of the Raspberry Pi 2 B
    • release of the new kernel with the new device handling capability - and with the new method enabled by default thus requiring reconfiguration for the old drivers to function as expected
    • the blog sites with the necessary information were disabled in order to better handle the increased traffic due to the launch

    These changes had a great impact on all Raspberry Pi installations that were actively using the I2C and the SPI interfaces. Given that there are lots of Raspberry Pi's in existence using these interfaces for a very wide range of applications i am very much surprised (in a very negative way) about the way this was handled. I only hope that they have learned from this experience and take steps to make sure that it never happens in this way again. I very much prefer to find out about these things from the right sources and not from people guessing at what the correct solution is to the problems. I found that all of the suggestions were lacking and did not solve all of my problems. It was not until i stumbled upon the new raspi-config configuration function that all of my problems disappeared. A lot of problems did disappear when i used Daniele's suggestion, but one of my most important installations that i ran in headless mode and relied on ssh to access and control refused to accept ssh connections afterwards. That was totally unacceptable for my purposes. But, luckily i checked out for new functionality in the raspi-config tool and got lucky - that fixed absolutely every problem that i was experiencing.

     

    When i get some free time i would like to explore the benefits and capabilities of the new device handling system and learn how to configure them - most preferably with information directly from the source and not from hackers guessing at how things should be done. In the immortal words of Dijkstra: "Testing can only prove the presence of bugs - not their absence." And in this situation i believe that hacking our way to a solution can possibly be used to uncover what does not work, but cannot be relied upon to find out what is necessary in situations such as we have just experienced without in depth, detailed knowledge about exactly what has changed. Modern systems are far too complex to be able to anticipate all possible scenarios.

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

    I'm a complete newcomer to raspberry and piface though have a programming background if you go far enough back. I'm trying to get raspberry pi 2 to talk to the piface relay plus board. I don't know if my problems are related to the above or not but I've tried disabling device tree as suggested.

     

    When I try to run the sample program in the documentation with the relay board I get "no piface relay plus board detected (hardware_addr=0, bus=0,chip_select=0).

     

    I've added the following lines to my config.txt file:

    dtparam=i2c_arm=on

    dtparam=spi=on

    device_tree=

     

    in /dev spidev0.0 and spidev0.1 are present.

     

    any ideas please ?

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

    It truly amazes me that people insist on following the advice of hackers and changing the configuration files instead of using the tools that are specifically supplied for fixing the problems that you are experiencing! Oh well, i guess you enjoy having unnecessary problems to solve and finding solutions to the problems you create that ensure that you will experience new "surprises" around the bend. The real solution to the problem is to use the raspi-config choice that i have explained in excruciating detail in different threads, but keep on hacking with the config.text and give yourself the thrill of unexpected surprises.

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

    I was only asking....

     

    The changes I made to config.txt were as documented by a Raspberry Pi Engineer & Forum Moderator in the article on the Raspberry forum with the post entitled "I2C, SPI, I2S, LIRC, PPS, stopped working? Read this."

     


     

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

    After plugging along with all the other postings and finding things not working, I followed your directions and all is well with the world.  My PiFace is working like a charm!!  Thank you!!

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

    Hello Dave,

     

    Glad that the directions were useful and your PiFace is working!

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

    I have another question regarding the PiFace Digital 2. I have a program that uses the GPIO of the Raspberry Pi 2 B. The program works and has been tested and works at 900 kHz (frequency divider). I used 3.3 v digital signals for testing but need to use 5v in the actual application. I thought I could use the PiFace and just connect my signals to it and everything would be fine. The more I read about it, it appears that I need to ditch my GPIO setup / digital read/write code and use the new stuff for the PiFace Digital 2 in order to use 5 v TTL signals. Can anyone confirm this for me? Or, preferably just give me a pin mapping between the PiFace and GPIO.

     

    Thanks.

    Paul

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

    Why bother with the PiFace - you could just use 3.3 to 5V level converters.

     

    MK

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

    Hello Paul,

     

    Firstly, i would like to point out that some information has been released after i made my original posting, and it can be found here: http://www.piface.org.uk/assets/docs/PiFace-Digital2_getting-started.pdf

     

    Next, i should also point out that i am having difficulty understanding exactly what you are trying to communicate but will attempt to reply nonetheless.

     

    If your concerns are about use of the inputs at the green connection blocks along the top of the board you should be aware that they appear to have been designed to work by being connected to and from the ground contact (refer to page 10 of the document at the link i have posted above). If you are planning on connecting circuits that switch between 5v and ground there you will most likely fry you circuits.

     

    Aside from that, i can inform you that i have not been using my PiFace Digital 2 card and the RaspberryPi that i had it mounted on for some months now, but i just fired them up and updated all software ("sudo apt-get update" followed by "sudo apt-get dist-upgrade" and "Y" to confirm that i wanted to update all approx. 50 packages that needed updating, then "sudo reboot" afterwards to start using the changes) and used the emulator to confirm that everything was still functional - which appeared to be the case.

     

    Hope this was helpful.

     

    Regards,

    raymond

    • 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