Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can display text on the second line of an LCD screen using Python by using the appropriate command from the LCD library that you are using. Here's an example code snippet using the Adafruit CircuitPython library:

import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd

# Tell the program which pins are connected to the LCD
lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d7 = digitalio.DigitalInOut(board.D12)

# Define the LCD size (16x2)
lcd_columns = 16
lcd_rows = 2

# Initialize the LCD object
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)

# Display text on the first line
lcd.message = "Hello, world!"

# Display text on the second line
lcd.set_cursor(0, 1) # Move cursor to second row, first column
lcd.message = "2nd line text"

In the last two lines of the code, we use the set_cursor() method to move the cursor to the second row and first column of the LCD screen, then display the desired text using the message attribute. Note that the cursor position is zero-indexed, so the first row is at index 0 and the second row is at index 1.