Search

Raspberry Pi PiFace Control and Display information

Raspberry Pi PiFace Control and Display information

I have been given a PiFace Control and Display http://piface.openlx.org.uk for review by the nice folks over at element14.

I have written my review at http://www.element14.com/community/roadTestReviews/1626

This post will explain in some depth what the board is and how it works.

Warning: technical stuff ahead. Anything you are unsure of feel free to ask in the comments and I will clarify it for you.

The PiFace Control and Display is a 2×16 LCD display mounted on a daughterboard for the Raspberry Pi. It has 5 normal switches and one 3-way rocker switch that could be used to scroll left and right for example. It also has an infrared receiver so the Raspberry Pi can use an infrared remote control.

The LCD is a yellow backlit HD44780 2 rows by 16 columns display using a standard 16 pin connector. The screen is a standard part available off the shelf should it become damaged and can be replaced simply by desoldering the connector and soldering on the new part, a task that would take someone experienced with soldering a matter of a minute or two.

The board connects to the Raspberry Pi using a MCP23S17 16-bit input/output port expander with interrupt output. This chip uses the SPI interface on the Raspberry Pi and means that the I/O pins on the Raspberry Pi are still available for use.

The downside to this is that you cannot read the pins directly, you need to go through the MCP23S17.

This is not as difficult as it sounds, there are libraries and examples available that once installed will make it simple to write to the display.

I prefer to code in C and to get the board working all I had to do was:
cd
git clone https://github.com/piface/libmcp23s17.git
git clone https://github.com/piface/libpifacecad.git
cd libmcp23s17/ && make && cd -
cd libpifacecad/ && make

To test the board:
make example
./example

This will turn on and write to the display, and wait for switches to be pressed.

One of the most useful pieces of code I have written for this board is to show the IP address and time.

#include
#include
#include
#include
#include

void centre_on_lcd(char text[], int line)
{
int len;
char trim[256];
snprintf(trim, sizeof(trim), "%s", text);

if(strlen(trim) > 16)
{
trim[16] = 0;
}
len = strlen(trim) / 2;
pifacecad_lcd_set_cursor(8 - len, line);
pifacecad_lcd_write(trim);
}

void main(void)
{
FILE *pp;
char *line, buffer[256];
int i;

time_t rawtime;
struct tm * timeinfo;

pifacecad_open();
pifacecad_lcd_backlight_on();
pifacecad_lcd_cursor_off();
pifacecad_lcd_blink_off();
while(1)
{
pp = popen("ifconfig | grep Bcast | cut -c21- | cut -d' ' -f1", "r");

if (pp != NULL)
{
while (1)
{
char buf[1000];
line = fgets(buf, sizeof buf, pp);
if (line == NULL) break;
snprintf(buffer, sizeof(buffer), "%s\n", line);
}
i = 0;
while(i < 250 && (buffer[i] == '.' || (buffer[i] >= '0' && buffer[i] < ='9'))) i++; buffer[i] = 0x0; fclose(pp); } centre_on_lcd(buffer, 0); time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime(buffer, sizeof(buffer), "%X", timeinfo); buffer[8] = 0; centre_on_lcd(buffer, 1); sleep(1); } pifacecad_close(); }

Related posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.