LCD Display Driver (MCP23008, MCP23017)
Overview
Driver for LCD displays using MCP23008 or MCP23017 I/O Expander modules. Uses I2C interface.

Compatible Modules
- LCD1602
- LCD1604
- LCD2002
- LCD2004
Specifications (MCP23008)
- 8-bit remote bidirectional I/O port
- High-speed I2C interface (MCP23008)
- Hardware address pins
- Configurable interrupt output pin
- Configurable interrupt source
- Polarity Inversion register for input port data polarity config.
I2C Address
The I2C address can be changed by modifying the A0, A1, A2 jumpers. (May vary by module manufacturer)

A0 | A1 | A2 | I2C Address |
---|---|---|---|
Low | Low | Low | 0x20 |
Low | Low | High | 0x21 |
Low | High | Low | 0x22 |
Low | High | High | 0x23 |
High | Low | Low | 0x24 |
High | Low | High | 0x25 |
High | High | Low | 0x26 |
High | High | High | 0x27 |
Supported GPIO
- Raspberry Pi 0~4
- Raspberry Pi 5
- BeagleBone Black/Green
- Jetson Nano
- FT232H, FT2232H, FT4232H
- MCP2221
Commands
[INIT]
Enters initial configuration settings.
Item | Type | Description |
---|---|---|
Chipset | WRITE | Select the chipset. (MCP23008,MCP23017) |
Column Count * | WRITE | Enter the number of columns of the display. |
Row Count * | WRITE | Enter the number of rows of the display. |
Dots | WRITE | Select the dot size of the display. (5×8,5×10) |

[SET_CURSOR]
Moves the cursor to the specified position.
Item | Type | Description |
---|---|---|
Column | WRITE | Enter the column position. (leftmost is 0) |
Row | WRITE | Enter the row position. (topmost is 0) |
[PRINT]
Displays text on the display.
Item | Type | Description |
---|---|---|
Text | WRITE | Enter the text to display at the current cursor position. |
[CLEAR]
Clears all content displayed on the screen and moves the cursor to HOME (top-left corner).
[HOME]
Moves the cursor to HOME (top-left corner).
[DISPLAY_ON]
Turns on the display.
[DISPLAY_OFF]
Turns off the display.
[CURSOR_ON]
Shows the cursor.
[CURSOR_OFF]
Hides the cursor.
[BLINK_ON]
Makes the cursor blink.
[BLINK_OFF]
Stops the cursor from blinking.
[SCROLL_LEFT]
Moves the displayed text one position to the left. Executing this command at regular intervals creates a left-scrolling effect.
[SCROLL_RIGHT]
Moves the displayed text one position to the right. Executing this command at regular intervals creates a right-scrolling effect.
[LEFT_TO_RIGHT]
Displays text from left to right based on the current cursor position.
[RIGHT_TO_LEFT]
Displays text from right to left based on the current cursor position.
[AUTO_SCROLL_ON]
Automatically scrolls left by the text length each time text is displayed.
[AUTO_SCROLL_OFF]
Turns off auto-scroll.
[BACKLIGHT_ON]
Turns on the backlight.
[BACKLIGHT_OFF]
Turns off the backlight.
[CREATE_CHAR]
Creates custom characters and loads them into positions 0~7 of the display’s internal storage (CGRAM). Up to 8 custom characters can be loaded.
Item | Type | Description |
---|---|---|
CGRAM Position | WRITE | Enter the CGRAM position to store the custom character. (0~7) |
Custom Character * | WRITE | Enter the custom character as a byte array. |
You can easily get the byte array using the Custom Character Generator. (Set Data Type to Hex)
[WRITE_CHAR]
Displays a custom character at the current cursor position.
Item | Type | Description |
---|---|---|
CGRAM Position | WRITE | Enter the CGRAM position to display at the current cursor position. (0~7) |
Example
Objective
Display the current date and time on the LCD display.
Parts
Part | Quantity |
---|---|
Raspberry Pi 4 * | 1 |
LCD Module | 1 |
Wiring
Connect the following pins horizontally to each other.
LCD Module | GPIO |
---|---|
VCC(5V) | 5V |
GND | GND |
DAT (SDA) | 2 (I2C1 SDA) |
CLK (SCL) | 3 (I2C1 SCL) |

Project Link