2.9 I2C LCD1602 Module

Overview

In this lesson, you will learn about LCD1602. LCD1602, or 1602 character-type liquid crystal display, a kind of dot matrix module to show letters, numbers, characters and so on.

Components Required

../_images/list_2.9.png

Fritzing Circuit

In this example, we will get the first pin GND of LCD1602 connected to GND, the second pin VCC to 5V, the third pin SDA to the pin SDA 20 and the forth pin SCL to the pin SCL 21.

../_images/image113.png

Schematic Diagram

../_images/image446.png

Note

The SDA and SCL of the Mega2560 board are the pins 20 and 21.

Code

Note

  • You can open the file 2.9_i2clcd1602.ino under the path of sunfounder_vincent_kit_for_arduino\code\2.9_i2clcd1602 directly.

  • The LiquidCrystal I2C library is used here, you can install it from the Library Manager.

    ../_images/lib_liquidcrystal_i2c.png

Upload the codes to the Mega2560 board, the content that you input in the serial monitor will be printed on the LCD.

Note

About the ASCII code and the character input in the serial monitor, please refer to 1.8 Serial Read.

Code Analysis

By calling the library LiquidCrystal_I2C.h, you can easily drive the LCD.

#include "LiquidCrystal_I2C.h"

Library Functions:

LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows)

Creates a new instance of the LiquidCrystal_I2C class that represents a particular LCD attached to your Arduino board.

  • lcd_AddR: The address of the LCD defaults to 0x27.

  • lcd_cols: The LCD1602 has 16 columns.

  • lcd_rows: The LCD1602 has 2 rows.

void init()

Initialize the lcd.

void backlight()

Turn the (optional) backlight on.

void nobacklight()

Turn the (optional) backlight off.

void display()

Turn the LCD display on.

void nodisplay()

Turn the LCD display off quickly.

void clear()

Clear display, set cursor position to zero.

void setCursor(uint8_t col,uint8_t row)

Set the cursor position to col,row.

void print(data,BASE)

Prints text to the LCD.

  • data: The data to print (char, byte, int, long, or string).

  • BASE (optional): The base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).

Phenomenon Picture

../_images/image115.jpeg