PiFace Control and Display - Review

Table of contents

RoadTest: PiFace Control and Display

Author: gregoryfenton

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?: HD44780 display

What were the biggest problems encountered?: Going to sleep once I had it. It is such fun!

Detailed Review:

PiFace Control and Display

Review by Gregory Fenton


Manufacturer: PiFace,http://piface.openlx.org.uk

Model: PiFace Control And Display (PiFaceCAD)

Supplied by: Element14,http://element14.com

 

Youtube video:

 

First impressions:

There are lots of switches

Infrared receiver built in

Pins to LCD display are a little long. This has pros and cons and will be discussed later.

It's green again, I am noticing a pattern with the PiFace stuff!

R1 is tiny! R1 is a variable resistor used for contrast adjustment and is only 2mm in size. There are pads on the board surrounding R1 to retrofit a larger (in size) SMT variable resistor.

It should be possible to desolder the LCD display daughterboard and resolder a different one should you choose to. If you choose a different sized display be sure to modify the libraries.


Mounting:

Only supported on 2 sides out of 4, potential for shorts with C6 on the Raspberry Pi board.

Has a cutout section for S5 on the Raspberry Pi board, and clearance for S2.

When fitting on a PiFace PiRack there is a stability issue. It only fits on the top port of the PiRack but is very precarious in that position.

It can be fitted lower down with some difficulty due to the infrared receiver but that effectively blocks the IR port.

It is a pity that the pins on SV1 are not extended into a female header so the board can be extended without the use of a PiRack.


Board information:

The LCD is a standard 16x2 HD44780 compatible LCD display.

Pins used:

GPIO 23: IR receiver


Requirements:

* Raspberry Pi

* Raspbian OS

* SPI pins enabled, http://www.piface.org.uk/guides/setting_up_pifacecad/Enabling_SPI/

* PiFaceCAD python software:

<pre>   sudo apt-get install python3-pifacecad

    sudo reboot</pre>

 

To test the hardware, type in the following in a terminal:

<pre>    cd /usr/share/doc/python3-pifacecad/examples

    python3 sysinfo.py</pre>

This should show the IP address, temperature and memory usage. Press Ctrl-C to exit the program.


As I do not program in python I chose to install the C libraries for the board:

<pre>    cd

    git clone https://github.com/piface/libmcp23s17.git

    git clone https://github.com/piface/libpifacecad.git

    cd libmcp23s17/ && make && cd -

    cd libpifacecad/ && make</pre>

To test whether all is working type in the following:

<pre>    make example

    ./example</pre>

This should turn on the LCD backlight and display the ubiquitous "Hello, World!" message on the display.


If all is well this far you can control the board and read switches directly from the command line using the pifacecad command:

<pre>    make pifacecad<pre>

We can use this command to turn on and off the backlight:

<pre>    ./pifacecad backlight on</pre>

clear the display:

<pre>    ./pifacecad clear</pre>

and to display a message:

<pre>    ./pifacecad write "PiFaceCAD\nRules!"</pre>

The pifacecad program has a number of commands, use --help to show them:

<pre>    ./pifacecad --help</pre>


At this point we are able to write our own C programs and use the PiFaceCAD board. Here is the source of one I wrote to test the functionality:

<pre>#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include "pifacecad.h"


/*

    PiFaceCAD sample code

    Author: Gregory Fenton, http://labby.co.uk

    I did the pixel stuff by hand and it took ages!

    Feel free to improve on the Santa *<(:-{)>)

*/


int main(void)

{

  uint8_t pifacelogo[] = {

      //piface logo top characters

      0b00001, 0b00111, 0b01111, 0b11111, 0b11111, 0b11110, 0b11110, 0b11111,

      0b11100, 0b11110, 0b11111, 0b11111, 0b11111, 0b01111, 0b01110, 0b11110,

      //piface logo bottom characters

      0b11111, 0b11111, 0b01111, 0b01111, 0b00111, 0b00011, 0b00000, 0b00000,

      0b01100, 0b01000, 0b10100, 0b10100, 0b11010, 0b11111, 0b00000, 0b00000 };

  uint8_t santa[] = {

      //left 3 characters of Santa

      0b00000, 0b00001, 0b00011, 0b00111, 0b00111, 0b00111, 0b00111, 0b00111,

      0b01111, 0b01111, 0b10000, 0b01111, 0b01000, 0b01010, 0b10101, 0b10010,

      0b10001, 0b10000, 0b10111, 0b10100, 0b10011, 0b01011, 0b01001, 0b00111,

      //right 3 characters of Santa

      0b00010, 0b10101, 0b11010, 0b10000, 0b10000, 0b11000, 0b11100, 0b11100,

      0b11110, 0b11110, 0b00001, 0b11110, 0b00010, 0b01010, 0b10101, 0b01001,

      0b10001, 0b00001, 0b11101, 0b00101, 0b11001, 0b11010, 0b10010, 0b11100 };

 

  uint8_t checkerboard[8] = {

      // checkerboard pattern

      0b10101, 0b01010, 0b10101, 0b01010, 0b10101, 0b01010, 0b10101, 0b01010 };

 

  int i, j, address, dir;

  int delay = 250 * 1000;

  char buffer[256], sub[14] = "";

  uint8_t switches;

 

  snprintf(buffer, sizeof(buffer), " %s ",

    "Press any PiFace Control and Display button to exit");

  pifacecad_open();

  pifacecad_lcd_backlight_on();

  pifacecad_lcd_cursor_off();

  pifacecad_lcd_blink_off();

  pifacecad_lcd_store_custom_bitmap(0, pifacelogo);

  pifacecad_lcd_store_custom_bitmap(1, pifacelogo + 8);

  pifacecad_lcd_store_custom_bitmap(2, pifacelogo + 16);

  pifacecad_lcd_store_custom_bitmap(3, pifacelogo + 24);

  pifacecad_lcd_store_custom_bitmap(4, checkerboard);

  pifacecad_lcd_write_custom_bitmap(0);

  pifacecad_lcd_write_custom_bitmap(1);

  pifacecad_lcd_write(" PiFace CAD\n");

  pifacecad_lcd_write_custom_bitmap(2);

  pifacecad_lcd_write_custom_bitmap(3);

  address = pifacecad_lcd_get_cursor_address();

  pifacecad_lcd_write(" Element14 ");

  sleep(1);

  pifacecad_lcd_set_cursor_address(address);

  pifacecad_lcd_write(" Review by ");

  sleep(1);

  pifacecad_lcd_set_cursor_address(address);

  pifacecad_lcd_write(" GregoryFenton ");

  sleep(1);

  pifacecad_lcd_set_cursor_address(address);

  pifacecad_lcd_write(" labby.co.uk ");

  pifacecad_lcd_store_custom_bitmap(0, santa);

  pifacecad_lcd_store_custom_bitmap(1, santa + 24);

  pifacecad_lcd_store_custom_bitmap(2, santa + 8);

  pifacecad_lcd_store_custom_bitmap(3, santa + 32);

  sleep(3);

  i = j = dir = 1;

  //pifacecad_lcd_write_custom_bitmap(4);

  while(1)

  {

      pifacecad_lcd_store_custom_bitmap(0, santa + j);

      pifacecad_lcd_store_custom_bitmap(1, santa + j + 24);

      pifacecad_lcd_store_custom_bitmap(2, santa + j + 8);

      pifacecad_lcd_store_custom_bitmap(3, santa + j + 32);

      pifacecad_lcd_set_cursor_address(address);

      snprintf(sub, 15, "%10s", buffer + i);

      sub[0] = 4;

      sub[13] = 4;

      pifacecad_lcd_write(sub);

      usleep(delay);

      i++;

      j += dir;

      if(j == 8)

          dir = -1;

      if(j == 0)

          dir = 1;

      if(i > strlen(buffer) - 13)

          i = 0;

      switches = pifacecad_read_switches();

      if(switches != 0xff)

          break;

      }

      pifacecad_lcd_clear();

      pifacecad_lcd_write("Goodbye\nlabby.co.uk");

      pifacecad_close();

 

      return 0;

}

</pre>

 

Hopefully this will help somebody to get the best out of their PiFaceCAD board.

 

I am extremely happy with the board, and getting it working took only a few minutes to install the libraries and example code.

 

I heartily recommend this product.


As us ex-squaddies say, “This is a Gucci bit of kit!”


PiFace, you have a winner!


Many thanks to PiFace and Element14 for giving me the opportunity to review this board.

Anonymous
  • The PiFaceCAD uses the SPI bus via a MCP23S17 port expander. This has 16 ports:


    HD44780 Data 4 | PortB0 |
    HD44780 Data 5 | PortB1 |
    HD44780 Data 6 | PortB2 |
    HD44780 Data 7 | PortB3 | --- MCP23S17 -- SPI -- Raspberry Pi
    HD44780 Enable | PortB4 |
    HD44780 RW     | PortB5 |
    HD44780 RS     | PortB6 |
    Backlight      | PortB7 |
    SW1            | PortA0 |
    SW2            | PortA1 |
    SW3            | PortA2 |
    SW4            | PortA3 |
    SW5            | PortA4 |
    SW6            | PortA5 |
    SW7            | PortA6 |
    SW8            | PortA7 |


    If we used the 8 bit mode there would not be enough free ports on the port expander and only 4 switches would be available.
    This could be safely ignored if you used a different port expander such as the PCA9505/06 (40 ports) from NXP. Note that this IC uses I2C rather than SPI.
    Going for a port expander with 40 ports and using 8 bits for data transfer to the HD44780 would take up 20 GPIO ports leaving 20 more for your own use (a second display? LED bar graph? 20 more switches?)

  • ehm... I don't get the 4-bit 8-bit part... My display uses I2C, so it's always 4 wires... Is the PiFace Control and Display also using I2C or SPI?

  • The LCD is the same, you would just need to interface the screen with the Pi.
    This board takes care of all that without any effort on your part.
    There are plenty of guides on interfacing to HD44780 displays online, my code would work as above if you converted the stuff that writes to the LCD to the commands yours uses.
    A good place to stat would be this guide over on AdaFruit which explains exactly how to wire it up and code for it.

     

    If you need a hand, just shout :)
    I have done this on an Arduino in the past, it is really quite straightforward. Messy with a load of wires, but straightforward.

     

    One tip, if you get stuck on "should I do 4 bit or 8 bit mode?" go for 4 bit mode. Less wires and easier to get working. If this means nothing to you, don't worry.. it will eventually.

  • Great review! I applied for this roadtest myself (wasn't selected image) but I have this display: http://www.dfrobot.com/index.php?route=product/product&path=53_130&product_id=135#.Uqds3FWbmpg

     

    Will that work with your code too?

    Thanks for the review!