How mteinum/erlang_pi_lcd works
Project type and purpose
• This is an Erlang/OTP application running on a Raspberry Pi that controls an Adafruit 16×2 LCD via an MCP23017 I²C I/O-expander.
• It bundles a small C-based driver (i2c_drv.so) for accessing the Pi’s I²C bus and an OTP‐style Erlang layer for supervising and exposing LCD functions.
File structure
• Top level:
• c_src/ – C driver source (i2c_drv.c) and Makefile
• src/ – Erlang modules: i2c.erl (port interface), mcp.erl (MCP23017 GenServer), lcd.erl (LCD API), lcd_app.app.src, lcd_app.erl (application entry), lcd_sup.erl (supervisor)
• rebar.config – build configuration for rebar3
• Build outputs:
• priv/i2c_drv.so (dynamically built by make via rebar3 hooks)
• compiled BEAM files under _build/
README
• Confirms OTP application, no external dependencies beyond standard Erlang runtime and the C driver.
• Describes high-level API (lcd:message/1, lcd:create_char/2, etc.)
• Notes build steps: rebar3 compile triggers C compilation into priv/, then Erlang compile.
Main components
a. Hardware & OS
• Raspberry Pi hardware
• Linux I²C kernel driver
• Physical devices: MCP23017 I/O expander → LCD module
b. Native driver layer
• c_src → i2c_drv.so (linked‐in driver)
• Exposed as a port or linked NIF to Erlang
c. Erlang/OTP layers
• Erlang VM / BEAM
• lcd_app application
• Supervisor tree:
– lcd_app (Application)
– lcd_sup (root supervisor)
– mcp (GenServer handling MCP23017 commands)
– lcd (GenServer exposing high-level display API)
d. Build & deployment
• rebar3 orchestrates C compilation and Erlang compilation
• Development shell vs. production release
Relationships & data flow
• Erlang lcd GenServer → mcp GenServer (JSON/RPC-style calls)
• mcp GenServer → C driver (via port/NIF calls)
• C driver → Linux I²C subsystem → MCP23017 → LCD HW
• Application → Supervisor → Worker processes
Architectural patterns & design principles
• OTP application / supervision tree for fault‐tolerance
• GenServer abstraction for both MCP23017 and LCD
• Separation of concerns:
• Hardware access in C → single shared driver
• Business logic & API in Erlang
• Priv directory pattern for native code