Pin names
The LCD1602 comes in 2 possible configurations: I2C configuration and standard configuration. The I2C configuration is usually simpler to use. The following table summarizes the key differences:
* Controlling the backlight requires another I/O pin.
You can select the desired configuration by setting the
pins attribute. Set it to “i2c” for the I2C configuration, or “full” for the standard configuration (the default).
I2C configuration
pin
Ground
pin
Supply voltage
pin
I2C data line
pin
I2C clock line
i2cAddress attribute.
The I2C configuration simulates a PCF8574T chip that controls the LCD module. Normally, you wouldn’t have to worry about this as the LiquidCrystal_I2C library takes care of the communication with the chip.
PCF8574T pin mapping
The following table shows how the PCF8574T I/O expander pins are mapped to the HD44780 LCD controller:
For an example of controlling the LCD using direct I2C commands (without the LiquidCrystal_I2C library), see I2C Protocol for LCD.
Standard configuration
pin
Ground
pin
Supply voltage
pin
Contrast adjustment (not simulated)
pin
Command/Data select
pin
Read/Write. Connect to Ground.
pin
Enable
pin
Parallel data 0 (optional, 8-bit mode only)
pin
Parallel data 1 (optional, 8-bit mode only)
pin
Parallel data 2 (optional, 8-bit mode only)
pin
Parallel data 3 (optional, 8-bit mode only)
pin
Parallel data 4
pin
Parallel data 5
pin
Parallel data 6
pin
Parallel data 7
pin
Backlight anode
pin
Backlight cathode
Normally, you’d configure the chip in 4-bit parallel mode, which means you only need to connect RS, E, D4, D5, D6, and D7 pins to Arduino.
Arduino code example
When you initialize the LiquidCrystal library in your code, you need to pass the pin numbers to the constructor. The following example uses pin numbers that match a typical setup:Attributes
string
default:"full"
Set to “i2c” for I2C configuration
string
default:"0x27"
I2C address (I2C configuration only)
string
default:"black"
The color of the text
string
default:"green"
The color of the backlight
string
default:"A00"
Font variant: “A00” or “A02” (see Font section below)
Font
The LCD1602 uses the Hitachi HD44780 LCD Controller chip. The chip comes with a built-in font, as well as the ability to define up to 8 custom characters. There are two versions of the chip’s ROM with two different fonts: HD44780UA00, which includes Japanese katakana characters, and HD44780UA02, which includes Western European characters. Wokwi simulates the HD44780UA00 variant by default, but you can switch to the HD44780UA02 variant by setting thevariant attribute to “A02”.
A00 variant
The HD44780UA00 font has 256 characters, with the following ranges:A02 variant
The HD44780UA02 font has 256 characters, with the following ranges:User defined characters
You can define custom characters using the createChar method of the LiquidCrystal (or LiquidCrystal_I2C) library. The custom characters are the first 8 characters in the font, with indexes from 0 to 7. You can print them to the LCD display using thewrite() method, or using C string escape sequence, such as "\x07".
The following code example defines a heart shaped character, stores it at index 3, and then uses it to display the text “I (heart) Arduino”:
loop() in the code sample above to slowly reveal the heart icon, line-by-line: