RoadTest: PiFace Digital
Author: Gough Lui
Creation date:
Evaluation Type: Independent Products
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?: Gertboard, Arduino.
What were the biggest problems encountered?: Documentation is not well gathered, especially for languages other than Python. Some time required to get familiar with the board due to non-straightforward documentation (lots of chasing around). Board performance in terms of update rate was relatively limited in testing.
Detailed Review:
PiFace Digital Review by Gough Lui
Let me first say that it is an honour to have been selected to be a Roadtest Reviewer for the PiFace Digital. I would like to thank element14/Farnell/Newark for their support of the community and manufacture of the PiFace Digital boards. Of course, these reviews are not "paid for" as such (although reviewers do get to keep the review items), and so I will be as impartial as possible and I won't hesitate to say what really needs to be said. I hope this review serves the community well. Of course, if you find this review helpful, please like and share it! Also feel free to visit my homepage - http://goughlui.com
The PiFace Digital is an add-on board, similar in style to an Arduino shield, designed to plug directly into the GPIO header port on the Raspberry Pi. If offers digital input and output and library functions for use in C, Python and Scratch.
The specifications on the board, from the datasheet (http://www.farnell.com/datasheets/1686131.pdf) is as follows:
Unfortunately, I feel that the specs provided are a bit unclear - for example, how much current and voltage can the open-collector outputs handle, are the relays using any of the output channels, what are the ratings on the relays, what voltage levels are required or tolerated at the inputs? I think we can improve upon this, although possibly at the risk of scaring a few beginners. That's one reason why I went through the components and their key features in the next section!
As usual, the guys at element14/Farnell/Newark did a good job of packaging the item and shipped it really quickly. The item itself comes in a thin glossy cardboard box with colour printing on the outside in 'element14' style.
The rear of the box gives a clear warning - "The relays must not be used to switch voltages greater than 20V or currents greater than 5A." It's probably a good idea to heed this warning for safety reasons given the close proximity of low-voltage components to the relays. Any shorting or arcing would mean the destruction of your Pi and everything connected to it (quite possibly)!
The board itself is wrapped in a metallic static shielding bag, and the box also contains a single Regulatory Compliance and Safety Information sheet.
In addition to echoing the warning on the rear of the box, there are some important pieces of advice - namely:
"PiFace(tm) Digital requires up to 200mA at 5v. If powered from the same power supply as the Raspberry Pi, the power supply shall be capable of delivering 650-900mA for model A and 850-1400mA for model B."
and
"Maximum voltage on all digital input/output pins is 5V."
So if you didn't bother to read that piece of paper, you would have probably missed out on that since it doesn't seem to appear on the online datasheets. The physical documentation provided with the product is not quite enough, so it's prudent to at least read the datasheet online provided by element14/Farnell/Newark at http://www.farnell.com/datasheets/1686131.pdf
The board itself is a double layer PCB with green solder resist and white sikscreening. The top of the board is populated with the ICs, relays, switches, terminal connector blocks and jumper posts. The jumpers come pre-configured for most users preferences. The silkscreening clearly identifies the parts but due to the way the board is populated, it doesn't provide much configuration guidance on its own, so the datasheet must be consulted.
The bottom of the PCB is pretty much bare, with the exception of the female DIL header connector to plug into the Raspberry Pi. There is also a rubber foot on the bottom.
The board itself fits well into the Raspberry Pi footprint, the rubber foot elevating the otherwise unsupported side of the PiFace Digital by leaning on the HDMI connector for support. The board also appears to rest on the audio output connector - the through hole legs seem to sit proud so that the board is just slightly elevated from flush. It's really nothing bad - there's no risk of shorts.
The height of the board with the relays, and the fact that all the wires will point outwards really rules out the possibility of using existing enclosures to house this combination. The board is also slightly weighty, and when inverted, the weight of the relays does try to lever the board slightly away from the base on the unsupported side - if there were holes on the PiFace board that aligned with the Raspberry Pi mounting holes, standoffs could be used to help mechanically secure the boards together. This isn't generally necessary for quick prototyping, but may be a concern if eventually pressed into service.
Lets take a closer look at the parts involved in doing the work. The main IC is a Microchip MCP23S17 16-bit I/O expander with Serial Interface. This version connects using high-speed SPI, up to 10Mhz, and provides a 16-bit bidirectional I/O. It appears that this is split as eight inputs, and eight outputs. The eight inputs appear to be connected with a series resistor (probably to make them 5v tolerant, as the chip is fed with 3.3v and inputs are not stated in the datasheet to be 5v tolerant) - and the eight outputs are connected to the darlington transistor array (for the open collector outputs). Further information can be found from the datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
The IC next to it is a Texas Instruments ULN2803A Darlington Transistor Array. This is used to drive the open collector outputs. Unfortunately, the datasheet specifications are a bit thin, however, it states the absolute maximum collector-emitter voltage is 50v, with up to 500mA on a single output and 2.5A total for the substrate. Of course, in these harsh conditions, it is likely that the chip will dissipate significant amounts of heat - however, it does mean the chip itself is quite durable. If you are using greater than 5v on the outputs shared with the relays, you must read and configure the jumper accordingly to disconnect the snubber diodes for the relays. More information is in the datasheet here: http://www.ti.com/lit/ds/symlink/uln2803a.pdf
The other major components on the board are the Omron G5LA-1 5V DC Single-Pole Cube Relay. The relay is specified for:
The datasheet for this component can be obtained here: http://components.omron.com/components/web/pdflib.nsf/0/4F7D9D9CA026C97E862573930070AC4F/$file/G5LA_E_0911.pdf
The board also features LEDs on each output channel to indicate their status, which can be very useful for a quick visual confirmation.
Getting started with a new prototyping device can be a bit daunting at times. If you look carefully, at the board, you will see the URL http://piface.openlx.org.uk silkscreened on. Unfortunately, at the time of review, this was a false lead which led to an error about posterous spaces shutting down (where, it seems, an initial forum of PiFace developers and enthusiasts gathered).
This has since been updated to point to the PiFace blog at http://pifacedigital.wordpress.com
It isn't a critical problem, as element14/Farnell/Newark provide their own datasheet specific to the PiFace Digital at http://www.farnell.com/datasheets/1686131.pdf which gives guidance on getting started and a quick tour of the device which should be sufficient for most to get started with interfacing the device to the real world. It also alludes to more tantalizing features such as the ability to stack PiFace Digital boards by using a PiFace Rack (when will we see this!?!) to expand the I/O possibilities by assigning unique addresses to each PiFace Digital board. It is definitely essential reading.
One of the disappointments is that a full schematic for the unit is not available as it could be easier to see just how the jumpers integrate into the system schematically rather than by description of their effects - but for most people, this isn't critical.
The datasheet also leads to several Manchester University (MU) pages. A few searches leads to more fruit - the other important links are at:
It is interesting to see that the datasheet provided at MU gives some more data about the board. For example, it details that the board is reliant on the 3v3, 5v, 0v, SPI MOSI, SPI MISO, SPI SCLK, SPI 10 CE0 N, SPI 10 CE1 N lines.
For the audacious hobbyist, this means that anything else can still be used if you wish. Unfortunately, as the connector on the board does not "pass through", you will need to do some modifications to make it happen. The plastic bumper as alluded to in the MU datasheet is already attached to the underside of the board - so don't worry about that!
The easiest way forward for users with an already working Raspbian distribution (you do have one don't you?) would be to follow the Farnell datasheet. Just in case you wondered, the second to final step wget -O - http://pi.cs.man.ac.uk/download/install.txt | bash executes the text file containing
sudo apt-get install -y python-dev python-gtk2-dev git
pushd ~/
git clone https://github.com/thomasmacpherson/piface.git
pushd piface/python
sudo python setup.py install
popd
sudo piface/scripts/spidev-setup
popd
That should placate some nervous users, while also illustrating what is actually happening - the library files are being cloned from thomasmacpherson's github and built. Getting setup with an existing installation was as simple as the datasheet makes it out to be - just key in a few commands, give it a little time and it's ready to be rebooted. If you don't already have an installation - there are two methods - either you start with a fresh installation of Raspbian from http://www.raspberrypi.org/downloads and then follow the instructions for an existing installation, or alternatively, you could use the pre-made builds that MU has hosted (although I have not tried them, in the future they could be outdated).
Aside from adding a layer of protection to the vulnerable GPIO ports, the provision of simple-to-use libraries for C, Python and Scratch is another distinguishing factor making it much easier to code your own programs. The provision of an emulator for Python sweetens the deal as well.
As I'm most familiar with C, we'll put the C library to the test.
The first thing we will begin with is the basic PiFace emulator (just to check everything is working) at piface/scripts/piface-emulator. In this, we can see what the present polled values are, and we can even modify the values graphically.
When you do this, you will notice that inputs 0-3 are shared with the push button and outputs 0-1 are shared by the relay coils. By removing JP4, it is possible to disconnect the snubber diodes, and removing JP5 and JP6 will disconnect the relay coils thus making the outputs independent. Removing JP7 will disconnect the power to LEDs as well.
The Enable Pullups checkbox seems to cause an issue though - the console window behind warns of Attribute Error: 'module' object has no attribute 'write_pullups'.
For the following experiments, it may be important to keep in mind that my Raspberry Pi is overclocked to 950Mhz on-demand but is being controlled via VNC, thus the timings may vary.
Experiment: Input Sampling Frequency
To test input frequency, I connected a signal generator (my DSONano v2 with BenF firmware) set to output a 1khz square wave. I then read 1 000 values from the connected port using a simple C program and wrote the output to stdout. By looking at the number of values high and low, we can deduce the maximum sampling frequency.
But not so fast! In order to work with C, you need to follow the instructions in the README.md file inside ~/piface, otherwise the libraries will not be installed correctly. Unfortunately, I tried that with my installation - and it failed to work correctly, automake failing with exit status: 1. It alludes to "Libtool library used but `LIBTOOL' is undefined" - something wrong with libtool. A quick sudo apt-get install libtool fixed that right up.
#include <stdio.h>
#include <libpiface-1.0/pfio.h>
int arrayvalues[1000];
int arraycount=0;
int main (void) {
pfio_init();
while (arraycount<1000) {
arrayvalues[arraycount]=pfio_digital_read(7);
arraycount++;
}
arraycount=0;
while (arraycount<1000) {
printf("%d ",arrayvalues[arraycount]);
arraycount++;
}
return (0);
}
The result from this experiment? The sampling rate appears to be in the order of about 10Khz - with around 10 samples per period. This definitely isn't anything spectacular, and there was the occasional jitter as well.
Experiment: Output Frequency
On the Raspberry Pi, the program running simply did this:
#include <stdio.h>
#include <libpiface-1.0/pfio.h>
int main (void) {
pfio_init();
while (1) {
pfio_digital_write(7,0);
pfio_digital_write(7,1);
}
return (0);
}
While this was running, I had my DSO Nanov2 connected to the output with a pull-up resistor. The result hovered between 2.6khz to 3Khz. Again, not particularly fast for digital writes unfortunately, and the jittering (because the Pi is running a whole lot more than just the interface board) makes it unsuitable for high-speed time-critical applications.
Experiment: Musical Relays
Feeling a bit patriotic, I decided to abuse the relays (well, just one of them) to make some music. This is Advance Australia Fair, as rendered by the PiFace's Omron relays:
If you want to try it for yourself, the code (ugly as heck) follows:
#include <stdio.h>
#include <time.h>
#include <libpiface-1.0/pfio.h>
int noteperiod[] = {3822, 3405, 3034, 2863, 2551, 2272, 2024, 1911, 1702, 1517, 1431};
// C D E F G A B c d e f
// 0 1 2 3 4 5 6 7 8 9 10
int songnote[] = {4, 7, 4, 2, 4, 7, 7, 7, 9, 8, 7, 6, 7, 8, -1, 4, 7, 4, 2, 0, 4, 4, 5, 9, 8, 7, 6, 5, 4, -1, 4, 5, 6, 7, 4, 4, 2, 2, 4, 5, 7, 10, 9, 8, -1, 4, 5, 6, 7, 5, 4, 7, 7, 8, 9, 7, 8, 6, 7, 9, 10, 9, 8, 7, 6, 5, 4, 7, 9, 7, 8, 6, 7, -1};
int songdura[] = {2, 2, 2, 2, 2, 3, 1, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 3, 1, 2, 2, 2, 2, 2, 2, 2, 4, 2, 3, 1, 2, 2, 3, 1, 2, 2, 2, 2, 2, 2, 2, 4, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 3, 1, 6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 1, 3, 1, 6, -1};
int i = 0;
int n = 0;
int o = 0;
int main (void) {
pfio_init();
while (!(songnote[i]==-1 && songdura[i]==-1)) {
if(songnote[i]!=-1) {
n = songdura[i]*125000/noteperiod[songnote[i]];
while (n>0) {
pfio_digital_write(0,o);
o=~o;
usleep(noteperiod[songnote[i]]);
n--;
}
} else {
usleep(songdura[i]*125000);
}
usleep(50000);
i++;
}
pfio_digital_write(0,0);
pfio_deinit();
return (0);
}
If you've been daunted by the prospect of damaging your Raspberry Pi board and held off from doing things that required the use of the GPIO header - fear no more. The PiFace is a relatively inexpensive add-on that is easy to get started with and relatively easy to use. It is also very versatile in being able to be programmed using C, Python or Scratch. It appears to be made with sensible educational "features" in mind, such as emulation and disable jumpers and is great for the novice beginner, right up to the intermediates as a "no hassle" interface. If anything, it's great to just have these to plug and unplug from your Raspberry Pi, leaving all the wire mess connected to the PiFace, and know that your Raspberry Pi is safe. The availability of GPIO is one of the things which set apart prototyping platforms from more general consumer devices such as tablets or ARM based TV sticks - if you're not using it, you really aren't getting all the flexibility from your Pi!
The specifications and documentation is a bit piecemeal at the moment, and it can take a while to track down the exact numbers you might be looking for - but hopefully this review has given readers the confidence to experiment and some solid numbers to start from. What is achievable is really up to the reader's imagination, and knowledge of circuit construction and programming (to an extent). I feel that it's a great way to achieve greater educational benefit from the Raspberry Pi as it gives the Pi a way of interacting with "real life" directly.
It is nice to see that the board is made from top-notch branded components from Microchip, Texas Instruments and Omron. It is also nice to see the numerous screw-down terminal connector blocks provided and pre-populated. Despite the value price, it seems that these were corners that weren't cut.
The more advanced users could probably buy the chips and wire them up for a bit less - if you are bothered, go right ahead! Advanced users will probably see little need for the indicator LEDs and relays as well.
One of the disadvantages (if it can be said to be one) is that the PiFace Digital does not offer analog input (duh!). I don't mean to criticise the board, but more to make users aware that this board does not offer any analog to digital conversion - thus all the signals into the inputs are digital TTL 0-5v signals. People looking to use temperature, light and pressure sensors should probably look elsewhere.
Another unfortunate thing is the lack of a pass-through connection on the GPIO pins. While it does make the system "idiot proof", it also means that the pins not used by the Pi-Face are "inaccessible", at least, not with some modifications and soldering. The board itself also obscures the flex connections for the upcoming camera module - so those who want to experiment with that might need a longer piece of flex or to plan more carefully.
The board itself is a good fit for the Raspberry Pi, but its increased height and wire connection terminal blocks means that it is incompatible with most, if not all enclosures which may be a little disappointing. Nothing a bit of handiwork can't fix though. The board itself is a bit heavier with the relays, and so the board can lift slightly from the base when inverted. When seated, the solder joints for the input terminal blocks and switches are butted up against the top of the audio output connector. While it's not a shorting hazard, it does make the board fit slightly-off-level.
In case of catastrophe, the two ICs on the PiFace board will likely be the victims. This is a bit of a safety buffer, but as the chips are surface mounted, should any harm come to the board, it might be a bit difficult to replace the ICs.
If anything, I'm nitpicking - if all you need is a handful of digital I/Os at a relatively slow rate, and something that's off-the-shelf at a value price with quality components and ease of use that won't scare off beginners, it's hard to go past the PiFace Digital.
For the more advanced and adventurous, it's still hard to go past a Gertboard which is a little more expensive (around AU$15 more) but offers more I/O opportunities including a motor controller, Analog to Digital and Digital to Analog capabilities. It is, however, less easy to use for a beginner due to a steeper learning curve, doesn't include any relays for high current applications or onboard switches and fits much less neatly in with the Raspberry Pi.