Elcdx (elcdx v0.1.1)

View Source

Elixir library for communicating with ELCD LCD display modules via UART.

This library provides a simple and efficient way to control LCD displays through UART communication. It supports various LCD operations including:

  • Text display with automatic line wrapping
  • Cursor control (show/hide)
  • Screen clearing and positioning
  • Scrolling text functionality
  • Multiple display sizes support

Example

{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0")

Elcdx.clear(lcd)
Elcdx.print(lcd, "Hello, World!")
Elcdx.move(lcd, 0, 1)
Elcdx.print(lcd, "Line 2 text")

Configuration

The library supports various LCD configurations:

  • 16x2 (default)
  • 20x4
  • Custom sizes

Default UART settings:

  • Baud rate: 19200
  • Data bits: 8
  • Stop bits: 1
  • Parity: None

Summary

Functions

Clears the LCD display.

Hides the cursor.

Shows the cursor.

Moves the cursor to the specified position.

Displays text on the LCD.

Starts a new LCD connection.

Stops the LCD connection and cleans up resources.

Types

start_option()

@type start_option() ::
  {:device, String.t()}
  | {:speed, pos_integer()}
  | {:lines, pos_integer()}
  | {:columns, pos_integer()}

t()

@type t() :: Elcdx.Driver.t()

Functions

clear(lcd)

@spec clear(t()) :: :ok | {:error, term()}

Clears the LCD display.

Example

Elcdx.clear(lcd)

cursor_off(lcd)

@spec cursor_off(t()) :: :ok | {:error, term()}

Hides the cursor.

Example

Elcdx.cursor_off(lcd)

cursor_on(lcd)

@spec cursor_on(t()) :: :ok | {:error, term()}

Shows the cursor.

Example

Elcdx.cursor_on(lcd)

move(lcd, column, line)

@spec move(t(), non_neg_integer(), non_neg_integer()) :: :ok | {:error, term()}

Moves the cursor to the specified position.

Parameters

  • lcd: LCD instance
  • column: Column position (0-based)
  • line: Line position (0-based)

Example

Elcdx.move(lcd, 5, 1)  # Move to column 5, line 1

print(lcd, text, opts \\ [])

@spec print(t(), String.t(), keyword()) :: :ok | {:error, term()}

Displays text on the LCD.

Parameters

  • lcd: LCD instance
  • text: Text to display
  • opts: Display options
    • :show_cursor - Show cursor (default: false)
    • :scroll - Enable scrolling for long text (default: true)

Examples

Elcdx.print(lcd, "Hello World")
Elcdx.print(lcd, "Long text that will scroll", scroll: true)
Elcdx.print(lcd, "Cursor visible", show_cursor: true)

start_link(device, opts \\ [])

@spec start_link(String.t(), [start_option()]) :: {:ok, t()} | {:error, term()}

Starts a new LCD connection.

Parameters

  • device: UART device path (e.g., "/dev/ttyUSB0")
  • opts: Optional configuration
    • :speed - UART baud rate (default: 19200)
    • :lines - Number of display lines (default: 2)
    • :columns - Number of display columns (default: 16)

Examples

{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0")
{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0", speed: 9600, lines: 4, columns: 20)

stop(lcd)

@spec stop(t()) :: :ok

Stops the LCD connection and cleans up resources.

Example

Elcdx.stop(lcd)