2-05-lcd1602: 1602 Display Screen
Here is the Python code to control an I2C LCD1602 display:
# -*- coding: UTF-8 -*-
# Experiment effect: I2C LCD1602 control
# Wiring: Connect an Arduino main control board to a Windows or Linux computer, and connect the LCD1602 display screen to the I2C port SCL and SDA
import time
from pinpong.board import Board
from pinpong.libs.lcd1602 import LCD1602_I2C # Import the lcd1602_i2c library from libs
Board("uno").begin() # Initialization, choose the board type (uno, leonardo, xugu) and port number. If the port number is not entered, automatic recognition will be performed
#Board("uno","COM36").begin() # Initialization with specified port on Windows
#Board("uno","/dev/ttyACM0").begin() # Initialization with specified port on Linux
#Board("uno","/dev/cu.usbmodem14101").begin() # Initialization with specified port on Mac
lcd = LCD1602_I2C(i2c_addr=0x20) # Initialize the I2C address of the LCD
print("I2C LCD1602 TEST...")
lcd.backlight(True) # Turn on the backlight
lcd.clear() # Clear the screen
lcd.set_cursor(0,0) # Set the cursor position
lcd.print("Hello World") # Display "Hello World". The 1602 screen has few pixels and cannot display Chinese characters
lcd.set_cursor(1,1) # Set the cursor position
lcd.print(1234) # Display the number 1234
while True:
time.sleep(1)
lcd.scroll_left() # Scroll display