API

LCD

I2C LCD Display driver for 1602 and 2004 displays controlled via I2C

LCD data sheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

Ported to MicroPython from https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

class lcd_i2c.lcd_i2c.LCD(addr: int, cols: int, rows: int, charsize: int = 0, i2c: None = None)[source]

Bases: object

Driver for the Liquid Crystal LCD displays that use the I2C bus

_command(value: int, mode: int = 0) None[source]

Send 8 bits command to I2C device

Parameters

value (int) – The value

_expander_write(value: int) None[source]

Write data to I2C device (port expander)

Parameters

value (int) – The value to send

_pulse_enable(value: int) None[source]

Pulse Enable (EN) pin

Parameters

value (int) – The value to send

_write_4_bits(value: int) None[source]

Write 4 bits to I2C device

Parameters

value (int) – The value to send

property addr: int

Get the LCD I2C bus address

Returns

LCD I2C bus address

Return type

int

autoscroll() None[source]

Set text ‘right justified’ from the cursor

backlight() None[source]

Turn backlight on

property backlightval: int

Get the backlight value

Returns

Backlight value of the LCD

Return type

int

begin() None[source]

Set the LCD display in the correct begin state

Must be called before anything else is done

Turn the blinking cursor on

Turn off blinking cursor

@see no_blink

Turn on blinking cursor

@see blink

property charsize: int

Get the size in dots of the LCD

Returns

Dot size of the LCD

Return type

int

clear() None[source]

Remove all the characters currently shown

Next print/write operation will start from the first position on LCD display.

property cols: int

Get the number of columns of the LCD

Returns

Number of columns of the LCD

Return type

int

create_char(location: int, charmap: None) None[source]

Fill the first 8 CGRAM locations with custom characters

Parameters
  • location (int) – The location to store the custom character

  • charmap (List[int]) – The charmap aka custom character

cursor() None[source]

Turn the underline cursor on

Cursor can blink or not blink. Use the methods @see blink and @see no_blink for changing the cursor blink status.

cursor_off() None[source]

Hide cursor

@see no_cursor

cursor_on() None[source]

Show cursor

@see cursor

property cursor_position: None

Get the current cursor position

Returns

Cursor position as tuple(column, row) as (x, y)

Return type

Tuple[int, int]

display() None[source]

Turn the display on

Show the characters on the LCD display, this is the normal behaviour. This method should only be used after no_display() has been used.

@see no_display

get_backlight() bool[source]

Get the backlight status

Returns

The backlight status

Return type

bool

home() None[source]

Set cursor to home position (0, 0)

Next print/write operation will start from the first position on the LCD display.

left_to_right() None[source]

Set text flow left to right

no_autoscroll() None[source]

Set text ‘left justified’ from the cursor

no_backlight() None[source]

Turn backlight off

Turn the blinking cursor off

no_cursor() None[source]

Turn the underline cursor off

no_display() None[source]

Turn the display off

Do not show any characters on the LCD display. Backlight state will remain unchanged. Also all characters written on the display will return, when the display in enabled again.

@see display

print(text: str) None[source]

Print text on LCD

Parameters

test – Text to show on the LCD

right_to_left() None[source]

Set text flow right to left

property rows: int

Get the number of rows of the LCD

Returns

Number of rows of the LCD

Return type

int

scroll_display_left() None[source]

Scroll the display to the left by one

scroll_display_right() None[source]

Scroll the display to the right by one

set_backlight(new_val: None) None[source]

Compatibility API functions for backlight

Parameters

new_val (Union[int, bool]) – The new backlight value

set_cursor(col: int, row: int) None[source]

Set the cursor

Parameters
  • col (int) – The new column of the cursor

  • row (int) – The new row of the cursor

HD44780 Constants

lcd_i2c.const.EN = <Mock name='mock.const()' id='140067930468656'>

Enable bit

lcd_i2c.const.LCD_1LINE = <Mock name='mock.const()' id='140067930468656'>

1 line command

lcd_i2c.const.LCD_2LINE = <Mock name='mock.const()' id='140067930468656'>

2 line command

lcd_i2c.const.LCD_4BITMODE = <Mock name='mock.const()' id='140067930468656'>

4 bit mode command

lcd_i2c.const.LCD_5x10DOTS = <Mock name='mock.const()' id='140067930468656'>

5x10 dots display command

lcd_i2c.const.LCD_5x8DOTS = <Mock name='mock.const()' id='140067930468656'>

5x8 dots display command

lcd_i2c.const.LCD_8BITMODE = <Mock name='mock.const()' id='140067930468656'>

8 bit mode command

lcd_i2c.const.LCD_BACKLIGHT = <Mock name='mock.const()' id='140067930468656'>

Activate backlight command

lcd_i2c.const.LCD_BLINKOFF = <Mock name='mock.const()' id='140067930468656'>

Set curor no blink command

lcd_i2c.const.LCD_BLINKON = <Mock name='mock.const()' id='140067930468656'>

Set curor blink command

lcd_i2c.const.LCD_CLEARDISPLAY = <Mock name='mock.const()' id='140067930468656'>

Clear display command

lcd_i2c.const.LCD_CURSORMOVE = <Mock name='mock.const()' id='140067930468656'>

Move cursor command

lcd_i2c.const.LCD_CURSOROFF = <Mock name='mock.const()' id='140067930468656'>

Turn cursor off command

lcd_i2c.const.LCD_CURSORON = <Mock name='mock.const()' id='140067930468656'>

Turn cursor on command

lcd_i2c.const.LCD_CURSORSHIFT = <Mock name='mock.const()' id='140067930468656'>

Shift cursor command

lcd_i2c.const.LCD_DISPLAYCONTROL = <Mock name='mock.const()' id='140067930468656'>

Control display command

lcd_i2c.const.LCD_DISPLAYMOVE = <Mock name='mock.const()' id='140067930468656'>

Display move command

lcd_i2c.const.LCD_DISPLAYOFF = <Mock name='mock.const()' id='140067930468656'>

Turn display off command

lcd_i2c.const.LCD_DISPLAYON = <Mock name='mock.const()' id='140067930468656'>

Turn display on command

lcd_i2c.const.LCD_ENTRYLEFT = <Mock name='mock.const()' id='140067930468656'>

Set display entry mode as left command

lcd_i2c.const.LCD_ENTRYMODESET = <Mock name='mock.const()' id='140067930468656'>

Set entry mode command

lcd_i2c.const.LCD_ENTRYRIGHT = <Mock name='mock.const()' id='140067930468656'>

Set display entry mode as right command

lcd_i2c.const.LCD_ENTRYSHIFTDECREMENT = <Mock name='mock.const()' id='140067930468656'>

Set display entry mode as shift decrement command

lcd_i2c.const.LCD_ENTRYSHIFTINCREMENT = <Mock name='mock.const()' id='140067930468656'>

Set display entry mode as shift increment command

lcd_i2c.const.LCD_FUNCTIONSET = <Mock name='mock.const()' id='140067930468656'>

Set function command

lcd_i2c.const.LCD_MOVELEFT = <Mock name='mock.const()' id='140067930468656'>

Move display shift left command

lcd_i2c.const.LCD_MOVERIGHT = <Mock name='mock.const()' id='140067930468656'>

Move display shift right command

lcd_i2c.const.LCD_NOBACKLIGHT = <Mock name='mock.const()' id='140067930468656'>

Deactivate backlight command

lcd_i2c.const.LCD_RETURNHOME = <Mock name='mock.const()' id='140067930468656'>

Return to home position command

lcd_i2c.const.LCD_SETCGRAMADDR = <Mock name='mock.const()' id='140067930468656'>

Set CGRAM address command

lcd_i2c.const.LCD_SETDDRAMADDR = <Mock name='mock.const()' id='140067930468656'>

Set DDRAM address command

lcd_i2c.const.RS = <Mock name='mock.const()' id='140067930468656'>

Register select bit

lcd_i2c.const.RW = <Mock name='mock.const()' id='140067930468656'>

Read/Write bit