API

The LCD class interfaces to the LCD driver via I2C and provides a set of high-level user functions to display text, turn the display on and off, etc.

Parameters:
  • width (int, default: 20 ) –

    The character width of the display.

  • height (int, default: 4 ) –

    The number of lines in the display.

  • i2c_address (int, default: 32 ) –

    The address of the display on the I2C bus.

  • i2c_bus (int | str, default: 1 ) –

    The I2C bus that the device is connected to.

Cursor

Bases: Enum

The style of cursor displayed. One of:

  • LCD.Cursor.NONE: No visible cursor
  • LCD.Cursor.BLINK: A blinking character cursor
  • LCD.Cursor.UNDERSCORE: An underscore cursor

backlight(on)

Turn the backlight on or off.

Parameters:
  • on (bool) –

    If set to True, the backlight will be on.

clear_display()

Clear the display.

clear_line(line, character=' ')

Erase the contents of a line.

Parameters:
  • line (int) –

    The line number to clear. Line numbers start from zero.

  • character (str, default: ' ' ) –

    The character to use to overwrite the current content. Defaults to a space.

display(on)

Turn the display on or off.

Parameters:
  • on (bool) –

    If set to True, the display will be on. Otherwise, the display will be blanked. (The data is preserved and will be visible when the display is turned on again).

home()

Return the cursor to the home position (0, 0) and undo any shifts of the display.

move_to(line, position)

Set the cursor to a given position.

Parameters:
  • line (int) –

    The line number to move to. Line numbers start from 0.

  • position (int) –

    The character position to move to, starting from 0.

Raises: ValueError: If either the line number or character position are out of range.

print(s)

Write text to the display.

Parameters:
  • s (str) –

    The string to write.

print_at(line, position, s)

Print text at a specified location. Just a shortcut for move_to() and print().

Parameters:
  • line (int) –

    The line number to write to (lines are numbered from 0).

  • position (int) –

    The character position in the line to start at.

  • s (str) –

    The string to write.

set_cursor(style)

Select the type of cursor to be displayed. Select underline, blinking, or no cursor.

Parameters:
  • style (Cursor) –

    Specifies the type of cursor to use.