LcdDisplay.HD44780.MCP23017 (lcd_display v0.3.0)

View Source

Knows how to commuticate with HD44780 type display through the 16-bit I/O expander MCP23017. You can turn on/off the backlight and change the LED color by switching on/off red, green and blue.

Usage

iex(2)>  Circuits.I2C.detect_devices
Devices on I2C bus "i2c-1":
* 32  (0x20)

1 devices detected on 1 I2C buses
config = %{
  i2c_bus: "i2c-1",          # I2C bus name
  i2c_address: 0x20,         # 7-bit address
  rows: 2,                   # the number of display rows
  cols: 16,                  # the number of display columns
  font_size: "5x8"           # "5x10" or "5x8"
}

# Start the LCD driver and get the initial display state.
{:ok, display} = LcdDisplay.HD44780.MCP23017.start(config)

# Run a command and the display state will be updated.
{:ok, display} = LcdDisplay.HD44780.MCP23017.execute(display, {:print, "Hello world"})

# Turn on/off `:red`, `:green` and `:blue` to change the backlight color.
{:ok, display} = LcdDisplay.HD44780.MCP23017.execute(display, {:red, false})

# Pick a random backlight color.
{:ok, display} = LcdDisplay.HD44780.MCP23017.execute(display, :random_color)

Pin assignment

This module assumes the following pin assignment:

GPIOA

MCP23017HD44780
GPA0-
GPA1-
GPA2-
GPA3-
GPA4-
GPA5-
GPA6LED RED
GPA7LED GREEN

GPIOB

MCP23017HD44780
GPB0LED BLUE
GPB1DB7 (Data Bus 7)
GPB2DB6 (Data Bus 6)
GPB3DB5 (Data Bus 5)
GPB4DB4 (Data Bus 4)
GPB5E (Enable)
GPB6-
GPB7RS (Register Select)

Summary

Types

The configuration options.

Functions

Executes the specified command and returns a new display state.

Initializes the LCD driver and returns the initial display state.

Types

config()

@type config() :: %{
  optional(:rows) => String.t(),
  optional(:cols) => pos_integer(),
  optional(:font_size) => pos_integer()
}

The configuration options.

display_driver()

@type display_driver() :: LcdDisplay.HD44780.Driver.t()

rgb_key()

@type rgb_key() :: :red | :green | :blue

Functions

execute(display, command)

Executes the specified command and returns a new display state.

set_random_color(display)

@spec set_random_color(display_driver()) :: display_driver()

start(config)

@spec start(config()) :: {:ok, display_driver()} | {:error, any()}

Initializes the LCD driver and returns the initial display state.