HiPi
Perl Modules for Raspberry Pi
Version 0.91 - released 25 February 2024

HiPi::Interface::LCDBackpackPCF8574

This module provides an interface to LCD devices using common PCF8574 based backpacks.

It uses HiPi::Interface::PCF8574 as a backend.

Methods

%params contains a number of key value pairs

Required key value pairs are width and lines. You must specify the geometry of your LCD:

use HiPi qw( :lcd );
use HiPi::Interface::LCDBackpackPCF8574;

my $lcd = HiPi::Interface::LCDBackpackPCF8574->new( 
    width =>  16,
    lines =>  4,
);

Options and their defaults

backlightcontrol => 0

        specify if methods setting the level of backlight can be used.
        The method $lcd->backlight will only work if you set
        backlightcontrol => 1 in the constructor.

devicename      => ( raspbi board version == 1 ) 
                   ? '/dev/i2c-0' : '/dev/i2c-1'

address         => 0x3F

        Consult the PCF8574 documentation for the address of your device.
        ICs with an A in the name ( PCF8574AT ). Generally have a default
        of 0x3f. Those without ( PCF8574T ) generally have a default of
        0x27.
        Use i2cdetect -y 1 to check for your device.

Example complete constructor call:

my $lcd = HiPi::Interface::LCDBackpackPCF8574->new( 
    width            => 16,
    lines            => 4,
    devicename       => '/dev/i2c-1',
    address          => 0x27
    backlightcontrol => 1
);
    
$lcd->init_display;

Usage Example

my $lcd = HiPi::Interface::LCDBackpackPCF8574->new(
    address => 0x3f,
    width => 16,
    lines => 4,
    backlightcontrol => 1,
);

$lcd->backlight(1);
$lcd->init_display();
$lcd->enable(1);
$lcd->clear;
$lcd->set_cursor_position(0,0);
$lcd->send_text('Hello World');
sleep 10;
$lcd->backlight(0);
$lcd->clear;
$lcd->enable(0);

After power on reset you must initialise the display using $lcd->init_display.

You may call the method again to reset the display at any time.

$lcd->init_display();

Switch the LCD on / off

$lcd->enable( 1 ); # on
$lcd->enable( 0 ); # off

Set the current cursor position.

# set the position to the leftmost column of the top row.
$lcd->set_cursor_position(0, 0);

Move the cursor one position to the left

$lcd->move_cursor_left();

Move the cursor one position to the right

$lcd->move_cursor_right();

Move the cursor to the top left postion

$lcd->home();

Clear all text and move the cursore position to the top left.

$lcd->clear();

Set the cursor mode. Valid constants for mode are :

  • HD44780_CURSOR_OFF
  • HD44780_CURSOR_BLINK
  • HD44780_CURSOR_UNDERLINE

use HiPi qw( :lcd );
.....
$lcd->set_cursor_mode( HD44780_CURSOR_BLINK );

Set the backlight on or off. This only has an effect if backlightcontrol => 1 was used in the constructor

$lcd->backlight( 1 );

Send $text to be 'printed' at the current cursor position.

$lcd->send_text( 'Hello World' );

Send a raw HD44780 command. $command can be one of :

  • HD44780_CLEAR_DISPLAY
  • HD44780_HOME_UNSHIFT
  • HD44780_CURSOR_MODE_LEFT
  • HD44780_CURSOR_MODE_LEFT_SHIFT
  • HD44780_CURSOR_MODE_RIGHT
  • HD44780_CURSOR_MODE_RIGHT_SHIFT
  • HD44780_DISPLAY_OFF
  • HD44780_DISPLAY_ON
  • HD44780_CURSOR_OFF
  • HD44780_CURSOR_UNDERLINE
  • HD44780_CURSOR_BLINK
  • HD44780_SHIFT_CURSOR_LEFT
  • HD44780_SHIFT_CURSOR_RIGHT
  • HD44780_SHIFT_DISPLAY_LEFT
  • HD44780_SHIFT_DISPLAY_RIGHT

use HiPi qw( :lcd );
.....
$lcd->send_command( HD44780_DISPLAY_OFF );