2.9 I2C LCD1602 Module¶
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.
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.
The SDA and SCL of the Mega2560 board are the pins 20 and 21.
You can open the file
2.9_i2clcd1602.inounder the path of
LiquidCrystal I2Clibrary is used here, you can install it from the Library Manager.
Upload the codes to the Mega2560 board, the content that you input in the serial monitor will be printed on the LCD.
About the ASCII code and the character input in the serial monitor, please refer to 1.8 Serial Read.
By calling the library LiquidCrystal_I2C.h, you can easily drive the LCD.
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.
Initialize the lcd.
Turn the (optional) backlight on.
Turn the (optional) backlight off.
Turn the LCD display on.
Turn the LCD display off quickly.
Clear display, set cursor position to zero.
void setCursor(uint8_t col,uint8_t row)
Set the cursor position to col,row.
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).