| Crates.io | lcd_display |
| lib.rs | lcd_display |
| version | 0.1.0 |
| created_at | 2025-08-25 17:37:58.999976+00 |
| updated_at | 2025-08-25 17:37:58.999976+00 |
| description | A Rust library for controlling character LCD displays (HD44780 compatible) via GPIO pins on Linux systems |
| homepage | https://github.com/gabrieldelmonte/lcd_display_rust |
| repository | https://github.com/gabrieldelmonte/lcd_display_rust |
| max_upload_size | |
| id | 1809855 |
| size | 14,413 |
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.
gpio-cdev/dev/gpiochip*Add this to your Cargo.toml:
[dependencies]
lcd_display = "0.1.0"
Here's a simple example showing how to use the library:
use lcd_display::{GPIO_Pin, LCD, LCD_Mode};
fn main() {
// Control pins
let rs = GPIO_Pin::new("/dev/gpiochip1", 03).expect("Error while opening RS pin!");
let en = GPIO_Pin::new("/dev/gpiochip1", 04).expect("Error while opening EN pin!");
// Data pins
let d4 = GPIO_Pin::new("/dev/gpiochip0", 12).expect("Error while opening D4 pin!");
let d5 = GPIO_Pin::new("/dev/gpiochip3", 26).expect("Error while opening D5 pin!");
let d6 = GPIO_Pin::new("/dev/gpiochip0", 14).expect("Error while opening D6 pin!");
let d7 = GPIO_Pin::new("/dev/gpiochip1", 01).expect("Error while opening D7 pin!");
let data_pins = vec![
d4,
d5,
d6,
d7
];
let mut lcd = LCD::new(
rs,
en,
data_pins,
LCD_Mode::FourBit
);
lcd.begin(20, 4);
lcd.set_cursor(0, 0);
lcd.print("Hello!");
lcd.set_cursor(0, 1);
lcd.print("LCD");
lcd.set_cursor(0, 2);
lcd.print("with");
lcd.set_cursor(0, 3);
lcd.print("Rust!");
std::thread::sleep(std::time::Duration::from_secs(30));
lcd.clear();
}
The library supports two modes:
LCD_Mode::FourBit: Uses 4 data pins (D4-D7)LCD_Mode::EightBit: Uses 8 data pins (D0-D7)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 valuelcd.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.
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 chipLCD 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
Similar to 4-bit mode but also connect D0, D1, D2, D3 data pins.
lcd.begin(16, 2);
lcd.print("Hello World!");
lcd.begin(20, 4);
lcd.set_cursor(0, 0);
lcd.print("Line 1");
lcd.set_cursor(0, 1);
lcd.print("Line 2");
lcd.set_cursor(0, 2);
lcd.print("Line 3");
lcd.set_cursor(0, 3);
lcd.print("Line 4");
lcd.clear();
lcd.set_cursor(1, 1);
lcd.print("Centered Text!");
The library uses Result types for error handling. Most methods that can fail return Result<(), Box<dyn std::error::Error>>.
Common errors:
Contributions are welcome! Please feel free to:
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
gpio-cdev crate