HiPi
Perl Modules for Raspberry Pi
Version 0.92 - released 28 March 2024

HiPi::Interface::SerLCD

This module provides an interface to LCD devices using the SparkFun SerLCD controller.

It uses HiPi::Device::SerialPort 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::SerLCD;

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

Optional params 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      => '/dev/ttyAMA0'
baudrate        => 9600
parity          => 'none',
stopbits        => 1,
databits        => 8,

If you are using a Pi 3 with default settings, the header pins
on the Rpi gpio are connected to the mini uart. You will therefore need
to specify the device to override the default.

devicename      => '/dev/ttyS0'

Example complete constructor call:

my $lcd = HiPi::Interface::SerLCD->new( 
    width            => 16,
    lines            => 4,
    backlightcontrol => 1,
    devicename       => '/dev/ttyS0',
);

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 :

  • SRX_CURSOR_OFF
  • SRX_CURSOR_BLINK
  • SRX_CURSOR_UNDERLINE

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

Set the backlight light level. Valid value for $percent is a number between 0 and 100

$lcd->backlight( 25 );

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 );

Update the baudrate to the new value set in 'baudrate' property. Following this command, the backback will require a hard reset.

use HiPi qw( :lcd );
.....
$lcd->baudrate( HTV2_BAUD_9600 );
$lcd->update_baudrate;

Set the geometry stored in the backpack with the 'width' and 'lines' values passed in the $lcd constructor. Some implementations may require a hard reset for the device after this method is called

$lcd->update_geometry();

Toggles splash screen display on / off

$lcd->toggle_splashcreen();

Sets the current top 2 lines of text as the splash screen.

$lcd->set_splashcreen();

If the SerLCD gets into an unknown state, call this to reset the LCD to default settings.

$lcd->init_lcd();