MojoScale Studio Docs
API Reference

lcd

Character LCD native Berry module.

Studio Docs Displays

import lcd

The lcd module drives HD44780-style character displays through firmware. Use it for status screens, numeric readouts, simple menus, and device-local feedback. Create an LCD object for each physical screen, then call display operations on that object.

Quick example

import lcd

screen = lcd.LCD(0x27, 16, 2)
screen.print_at(0, 0, "Generator")
screen.print_at(0, 1, "RPM: 1800")

engine = lcd.LCD(0x27, 16, 2)
status = lcd.LCD(0x3F, 20, 4)
engine.print_at(0, 0, "Engine")
status.print_at(0, 0, "System online")

battery = [0x0E, 0x1F, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00]
screen.create_char(0, battery)
screen.print_at(12, 0, "BAT ")
screen.write_char(0)

importlcd

Character LCD native Berry module.

The lcd module drives HD44780-style character displays through firmware. Use it for status screens, numeric readouts, simple menus, and device-local feedback. Create an LCD object for each physical screen, then call display operations on that object.

API 28 available

lcd.LCD(address: int, columns: int = None, rows: int = None, sda: int = None, scl: int = None, frequency: int = None, port: int = None, rs_bit: int = None, en_bit: int = None, bl_bit: int = None) -> lcd_screen

Create and initialize an independent character LCD screen.

Each returned object owns its own I2C address, geometry, backpack bit mapping, and display state. Multiple LCD objects can share the same I2C bus when their addresses are different.

Parameters
Name Type Pass as Required Description
address int positional or keyword Yes I2C address, usually 0x27 or 0x3f.
columns int positional or keyword No Optional number of text columns. Defaults to 16.
rows int positional or keyword No Optional number of text rows. Defaults to 2.
sda int positional or keyword No No description yet.
scl int positional or keyword No No description yet.
frequency int positional or keyword No No description yet.
port int positional or keyword No No description yet.
rs_bit int positional or keyword No No description yet.
en_bit int positional or keyword No No description yet.
bl_bit int positional or keyword No No description yet.
Returns

lcd_screen lcd_screen object.

lcd.LCD().clear() -> None

Clear the whole display and move the cursor home.

lcd.LCD().clear_line(row) -> None

Clear one zero-based row and leave the cursor at its start.

Parameters
Name Type Pass as Required Description
row int positional or keyword Yes Required value.

lcd.LCD().home() -> None

Move the cursor to column 0, row 0 without clearing text.

lcd.LCD().set_cursor(column, row) -> None

Move the text cursor using zero-based coordinates.

Parameters
Name Type Pass as Required Description
column int positional or keyword Yes Required value.
row int positional or keyword Yes Required value.

lcd.LCD().print(text) -> None

Print text at the current cursor position.

Parameters
Name Type Pass as Required Description
text str positional or keyword Yes Required value.

lcd.LCD().print_at(column, row, text) -> None

Move the cursor and print text in one call.

Parameters
Name Type Pass as Required Description
column int positional or keyword Yes Required value.
row int positional or keyword Yes Required value.
text str positional or keyword Yes Required value.

lcd.LCD().backlight(enabled) -> None

Turn the LCD backlight on or off.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Required value.

lcd.LCD().display(enabled) -> None

Show or hide LCD text without clearing stored text.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Required value.

lcd.LCD().cursor(enabled) -> None

Show or hide the hardware text cursor.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Required value.

lcd.LCD().create_char(index, data) -> None

Define one custom character slot, 0 through 7.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Required value.
data any positional or keyword Yes Required value.

lcd.LCD().write_char(index) -> None

Write a custom character at the current cursor position.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Required value.

lcd.LCD().close() -> bool

Release this LCD device handle.

lcd.LCD().Example

screen = lcd.LCD(address=0x27, columns=16, rows=2) screen.print_at(0, 0, "Ready") second = lcd.LCD(address=0x3F, columns=20, rows=4) second.print_at(0, 0, "Second screen")

lcd.begin(address: int, columns: int = None, rows: int = None) -> None

Legacy: initialize the module-level default LCD.

Prefer ``screen = lcd.LCD(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.

Parameters
Name Type Pass as Required Description
address int positional or keyword Yes I2C address, usually 0x27 or 0x3f.
columns int positional or keyword No Optional number of text columns. Defaults to 16.
rows int positional or keyword No Optional number of text rows. Defaults to 2.
Returns

None None.

lcd.clear() -> None

Legacy: clear the default display and move the cursor home.

Returns

None None.

lcd.clear_line(row: int) -> None

Legacy: clear one row on the default display.

Parameters
Name Type Pass as Required Description
row int positional or keyword Yes Zero-based text row to clear.
Returns

None None.

lcd.home() -> None

Legacy: move the default cursor to column 0, row 0.

Returns

None None.

lcd.set_cursor(column: int, row: int) -> None

Legacy: move the default text cursor.

Parameters
Name Type Pass as Required Description
column int positional or keyword Yes Zero-based text column.
row int positional or keyword Yes Zero-based text row.
Returns

None None.

lcd.print(text: str) -> None

Legacy: print text on the default display.

Parameters
Name Type Pass as Required Description
text str positional or keyword Yes String to display.
Returns

None None.

lcd.print_at(column: int, row: int, text: str) -> None

Legacy: move the default cursor and print text in one call.

Parameters
Name Type Pass as Required Description
column int positional or keyword Yes Zero-based text column.
row int positional or keyword Yes Zero-based text row.
text str positional or keyword Yes String to display.
Returns

None None.

lcd.backlight(enabled: bool) -> None

Legacy: set the default LCD backlight state.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Boolean. True turns the backlight on; False turns it off.
Returns

None None.

lcd.display(enabled: bool) -> None

Legacy: set whether default LCD text output is visible.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Boolean. True shows the display; False hides it.
Returns

None None.

lcd.cursor(enabled: bool) -> None

Legacy: show or hide the default hardware text cursor.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword Yes Boolean. True shows the cursor; False hides it.
Returns

None None.

lcd.create_char(index: any, data: list) -> None

Legacy: define one custom character on the default LCD.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Custom character slot from 0 to 7.
data list positional or keyword Yes List, bytes, or string containing 8 row values.
Returns

None None.

lcd.write_char(index: any) -> None

Legacy: write a custom character on the default LCD.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Custom character slot from 0 to 7.
Returns

None None.