LCD Display Driver for Rust
A Rust library for controlling character LCD displays (HD44780 compatible) via GPIO pins on Linux systems. This crate provides a simple and safe interface for displaying text on LCD screens commonly used in embedded projects.
Features
- 4-bit and 8-bit mode support: Flexible pin configuration
- Thread-safe GPIO control: Built on top of
gpio-cdev - Simple API: Easy to use with clear method names
- Linux compatibility: Works with any Linux system that exposes GPIO via
/dev/gpiochip* - HD44780 compatible: Works with most character LCD displays
Hardware Requirements
- Linux system with GPIO support (Raspberry Pi, BeagleBone, etc.)
- HD44780 compatible character LCD display
- Appropriate wiring between GPIO pins and LCD
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Here's a simple example showing how to use the library:
use ;
API Documentation
LCD Modes
The library supports two modes:
LCD_Mode::FourBit: Uses 4 data pins (D4-D7)LCD_Mode::EightBit: Uses 8 data pins (D0-D7)
Main Methods
LCD::new(rs, en, data_pins, mode)
Creates a new LCD instance.
rs: Register Select pinen: Enable pindata_pins: Vector of data pins (4 for FourBit mode, 8 for EightBit mode)mode: LCD_Mode enum value
lcd.begin(columns, rows)
Initializes the LCD display with the specified dimensions.
lcd.print(text)
Displays text at the current cursor position.
lcd.set_cursor(column, row)
Sets the cursor position (0-indexed).
lcd.clear()
Clears the display and returns cursor to home position.
lcd.get_columns() / lcd.get_rows()
Returns the configured display dimensions.
GPIO Pin Management
The GPIO_Pin struct handles individual GPIO pin control:
GPIO_Pin::new(chip_path, line_offset)
Creates a new GPIO pin instance.
chip_path: Path to GPIO chip (e.g., "/dev/gpiochip0")line_offset: Pin number on the chip
Wiring Guide
4-bit Mode (Recommended)
LCD Pin | Description | GPIO Pin
--------|-------------------|----------
VSS | Ground | GND
VDD | Power (+5 V) | +5 V
V0 | Contrast | Potentiometer center
RS | Register Select | Your choice
RW | Read/Write Select | GND
Enable | Enable | Your choice
D4 | Data 4 | Your choice
D5 | Data 5 | Your choice
D6 | Data 6 | Your choice
D7 | Data 7 | Your choice
A | Backlight + | +5 V
K | Backlight - | GND
8-bit Mode
Similar to 4-bit mode but also connect D0, D1, D2, D3 data pins.
Examples
Basic Text Display
lcd.begin;
lcd.print;
Multi-line Display
lcd.begin;
lcd.set_cursor;
lcd.print;
lcd.set_cursor;
lcd.print;
lcd.set_cursor;
lcd.print;
lcd.set_cursor;
lcd.print;
Clearing and Updating
lcd.clear;
lcd.set_cursor;
lcd.print;
Error Handling
The library uses Result types for error handling. Most methods that can fail return Result<(), Box<dyn std::error::Error>>.
Common errors:
- GPIO chip not found
- Permission denied (run with appropriate privileges)
- Invalid pin numbers
- Hardware connection issues
Performance Notes
- The library includes appropriate delays for LCD timing requirements
- 4-bit mode is generally recommended for most applications
- Operations are blocking and not suitable for real-time applications
Contributing
Contributions are welcome! Please feel free to:
- Open issues for bugs or feature requests
- Submit pull requests
- Improve documentation
- Add examples
License
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
Acknowledgments
- Built on top of the excellent
gpio-cdevcrate - Inspired by the Arduino LiquidCrystal library
- HD44780 datasheet and community documentation
Changelog
v0.1.0
- Initial release
- 4-bit and 8-bit mode support
- Basic LCD operations (print, clear, cursor control)
- Linux GPIO support via gpio-cdev