HD44780-based LCD driver

This module provides a simple interface for controlling character LCDs based on the HD44780 driver. It supports displaying text, controlling the cursor position, and creating custom characters on the LCD screen.

Example

from machine import Pin
import time
from lcd_hd44780 import LcdHd44780

# Initialize the LCD with control pins (RS, E) and data pins (D4, D5, D6, D7)
lcd = LcdHd44780(rs=26, e=25, d=[13, 10, 9, 27])

# Move cursor to line 1, column 3 and display text
lcd.move_to(1, 3)
lcd.write("Hello, World!")

lcd.move_to(2, 5)
lcd.write("MicroPython")

Authors

  • Shujen Chen et al. Raspberry Pi Pico Interfacing and Programming with MicroPython

  • Tomas Fryza

Modification history

  • 2024-11-11 : Added Sphinx-style comments for documentation.

  • 2024-10-26 : Added demo method to demonstrate usage of the display.

  • 2023-10-17 : File created, initial release.

class lcd_hd44780.LcdHd44780(rs, e, d)[source]

Bases: object

command(cmd)[source]

Send a command byte to the LCD controller. This method writes to the command register of the LCD (RS = 0).

Parameters:

cmd – The command byte to send to the LCD.

custom_char(addr, charmap)[source]

This method writes the pixel data for the custom character to one of the 8 available character generator RAM (CGRAM) locations.

Parameters:
  • addr – The address (0 to 7) in the CGRAM to store the custom character.

  • charmap – A list of 8 bytes representing the custom character’s pixel pattern.

Note

Inspired by peppe8o and MicrocontrollersLab.

data(val)[source]

Send a data byte to the LCD controller. This method writes to the data register of the LCD (RS = 1).

Parameters:

val – The data byte to send to the LCD.

move_to(line, column)[source]

Move the cursor to a specified position on the LCD. The method supports two lines.

Parameters:
  • line – The line number (1 or 2).

  • column – The column number (1 to 20).

write(s)[source]

Display a string of characters on the LCD. This method writes each character of the string to the LCD, one by one.

Parameters:

s – The string of characters to display on the LCD.

lcd_hd44780.demo()[source]

Demonstrates the usage of the LcdHd44780 class by initializing an LCD display, positioning text, and displaying a sample message.