Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
๐ Ready to explore and create with us? Click [here] and join today!
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๏
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.
Schematic Diagram๏
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.inounder the path ofsunfounder_vincent_kit_for_arduino\code\2.9_i2clcd1602directly.The
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.
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๏