1.1.7 I2C LCD1602¶
Introduction¶
LCD1602 is a character type liquid crystal display, which can display 32 (16*2) characters at the same time.
Required Components¶
In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
---|---|---|
Raphael Kit |
337 |
You can also buy them separately from the links below.
COMPONENT INTRODUCTION |
PURCHASE LINK |
---|---|
Schematic Diagram¶
T-Board Name |
physical |
SDA1 |
Pin 3 |
SCL1 |
Pin 5 |

Experimental Procedures¶
Step 1: Build the circuit.

Step 2: Setup I2C (see I2C Configuration. If you have set I2C, skip this step.)
Step 3: Change directory.
cd ~/raphael-kit/python/
Step 4: Run.
sudo python3 1.1.7_Lcd1602.py
After the code runs, you can see Greetings!, From SunFounder
displaying on the LCD.
Note
If you get the error
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
, you need to refer to I2C Configuration to enable the I2C.If you get
ModuleNotFoundError: No module named 'smbus2'
error, please runsudo pip3 install smbus2
.If the error
OSError: [Errno 121] Remote I/O error
appears, it means the module is miswired or the module is broken.If the code and wiring are fine, but the LCD still does not display content, you can turn the potentiometer on the back to increase the contrast.
Code
Note
You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path like raphael-kit/python
. After modifying the code, you can run it directly to see the effect.
import LCD1602
import time
def setup():
LCD1602.init(0x27, 1) # init(slave address, background light)
LCD1602.write(0, 0, 'Greetings!')
LCD1602.write(1, 1, 'From SunFounder')
time.sleep(2)
def destroy():
LCD1602.clear()
if __name__ == "__main__":
try:
setup()
except KeyboardInterrupt:
destroy()
Code Explanation
import LCD1602
This file is an open source file for controlling I2C LCD1602. It allows us to easily use I2C LCD1602.
LCD1602.init(0x27, 1)
The function initializes the I2C system with the designated device symbol. The first parameter is the address of the I2C device, which can be detected through the i2cdetect command (see Appendix for details). The address of I2C LCD1602 is generally 0x27.
LCD1602.write(0, 0, 'Greetings!')
Within this function, ‘Greetings!! ‘ is the character to be printed on the Row 0+1, column 0+1 on LCD. Now you can see “Greetings!! From SunFounder” displayed on the LCD.
Phenomenon Picture¶
