> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LCD1602 Display

> An LCD with 2 lines, 16 characters per line

An LCD with 2 lines, 16 characters per line.

## 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:

| Property                   | Standard      | I2C                |
| -------------------------- | ------------- | ------------------ |
| Number of Arduino I/O pins | 7\*           | 2 (SCL/SDA)        |
| Backlight control          | Optional      | Yes                |
| Library name               | LiquidCrystal | LiquidCrystal\_I2C |

\* 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

<ParamField path="GND" type="pin">
  Ground
</ParamField>

<ParamField path="VCC" type="pin">
  Supply voltage
</ParamField>

<ParamField path="SDA" type="pin">
  I2C data line
</ParamField>

<ParamField path="SCL" type="pin">
  I2C clock line
</ParamField>

The default I2C address of the LCD1602 module is 0x27. You can change the address by setting the `i2cAddress` attribute.

<Note>
  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.
</Note>

#### PCF8574T pin mapping

The following table shows how the PCF8574T I/O expander pins are mapped to the HD44780 LCD controller:

| PCF8574T Pin | HD44780 Pin |
| ------------ | ----------- |
| P0           | RS          |
| P1           | R/W         |
| P2           | E           |
| P3           | Backlight   |
| P4           | D4          |
| P5           | D5          |
| P6           | D6          |
| P7           | D7          |

For an example of controlling the LCD using direct I2C commands (without the LiquidCrystal\_I2C library), see [I2C Protocol for LCD](https://wokwi.com/projects/454410801703852033).

### Standard configuration

<ParamField path="VSS" type="pin">
  Ground
</ParamField>

<ParamField path="VDD" type="pin">
  Supply voltage
</ParamField>

<ParamField path="V0" type="pin">
  Contrast adjustment (not simulated)
</ParamField>

<ParamField path="RS" type="pin">
  Command/Data select
</ParamField>

<ParamField path="RW" type="pin">
  Read/Write. Connect to Ground.
</ParamField>

<ParamField path="E" type="pin">
  Enable
</ParamField>

<ParamField path="D0" type="pin">
  Parallel data 0 (optional, 8-bit mode only)
</ParamField>

<ParamField path="D1" type="pin">
  Parallel data 1 (optional, 8-bit mode only)
</ParamField>

<ParamField path="D2" type="pin">
  Parallel data 2 (optional, 8-bit mode only)
</ParamField>

<ParamField path="D3" type="pin">
  Parallel data 3 (optional, 8-bit mode only)
</ParamField>

<ParamField path="D4" type="pin">
  Parallel data 4
</ParamField>

<ParamField path="D5" type="pin">
  Parallel data 5
</ParamField>

<ParamField path="D6" type="pin">
  Parallel data 6
</ParamField>

<ParamField path="D7" type="pin">
  Parallel data 7
</ParamField>

<ParamField path="A" type="pin">
  Backlight anode
</ParamField>

<ParamField path="K" type="pin">
  Backlight cathode
</ParamField>

<Note>
  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.
</Note>

#### 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:

```cpp theme={null}
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  lcd.begin(16, 2);
  // you can now interact with the LCD, e.g.:
  lcd.print("Hello World!");
}

void loop() {
  // ...
}
```

You can also [try this example on Wokwi](https://wokwi.com/projects/294342288335700490).

## Attributes

<ParamField path="pins" type="string" default="full">
  Set to "i2c" for I2C configuration
</ParamField>

<ParamField path="i2cAddress" type="string" default="0x27">
  I2C address (I2C configuration only)
</ParamField>

<ParamField path="color" type="string" default="black">
  The color of the text
</ParamField>

<ParamField path="background" type="string" default="green">
  The color of the backlight
</ParamField>

<ParamField path="variant" type="string" default="A00">
  Font variant: "A00" or "A02" (see Font section below)
</ParamField>

## Font

The LCD1602 uses the [Hitachi HD44780 LCD Controller chip](https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller). 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 the `variant` attribute to "A02".

### A00 variant

The HD44780UA00 font has 256 characters, with the following ranges:

| Range   | Description                    |
| ------- | ------------------------------ |
| 0-7     | User defined characters        |
| 8-31    | Blank characters               |
| 32-127  | Standard ASCII characters      |
| 128-160 | Blank characters               |
| 161-255 | Japanese katankana and symbols |

### A02 variant

The HD44780UA02 font has 256 characters, with the following ranges:

| Range   | Description                                                         |
| ------- | ------------------------------------------------------------------- |
| 0-7     | User defined characters                                             |
| 8-31    | Blank characters                                                    |
| 32-127  | Standard ASCII characters (characters 92, 126, 127 differ from A00) |
| 128-255 | Western european and Cyrillic characters, symbols                   |

### User defined characters

You can define custom characters using the [createChar](https://www.arduino.cc/en/Reference/LiquidCrystalCreateChar) 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 the `write()` 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":

```cpp theme={null}
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

uint8_t heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
};

void setup() {
  lcd.createChar(3, heart);
  lcd.begin(16, 2);
  lcd.print("  I \x03 Arduino");
}

void loop() { }
```

You can also [run this example on Wokwi](https://wokwi.com/projects/294395602645549578).

You can modify any custom character while the program is running. This method is useful for creating simple animations. For example, change `loop()` in the code sample above to slowly reveal the heart icon, line-by-line:

```cpp theme={null}
void loop() {
  uint8_t heart2[8] = {0};
  for (int i = 0; i < 8; i++) {
    heart2[i] = heart[i];
    lcd.createChar(3, heart2);
    delay(100);
  }
  delay(500);
}
```

## Simulator examples

* [LiquidCrystal Hello World](https://wokwi.com/projects/294342288335700490)
* [LiquidCrystal I2C Hello World](https://wokwi.com/projects/344891772964438612)
* [Direct I2C control (without library)](https://wokwi.com/projects/454410801703852033)
* [LiquidCrystal Custom characters](https://wokwi.com/projects/294395602645549578)
* [Electronic Safe](https://wokwi.com/projects/344891391763022419)
* [DS1307 Clock](https://wokwi.com/projects/298783436806554120)
