adafruit_character_lcd.character_lcd

Module for interfacing with monochromatic character LCDs

  • Author(s): Kattni Rembor, Brent Rubell, Asher Lieber, Tony DiCola (original python charLCD library)

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_character_lcd.character_lcd.Character_LCD(rs, en, d4, d5, d6, d7, columns, lines)[source]

Base class for character LCD.

Parameters:

Blink the cursor. True to blink the cursor. False to stop blinking.

The following example shows a message followed by a blinking cursor for five seconds.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.blink = True
lcd.message = "Blinky cursor!"
time.sleep(5)
lcd.blink = False
clear()[source]

Clears everything displayed on the LCD.

The following example displays, “Hello, world!”, then clears the LCD.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.message = "Hello, world!"
time.sleep(5)
lcd.clear()
column_align

If True, message text after ‘n’ starts directly below start of first character in message. If False, text after ‘n’ starts at column zero.

create_char(location, pattern)[source]

Fill one of the first 8 CGRAM locations with custom characters. The location parameter should be between 0 and 7 and pattern should provide an array of 8 bytes containing the pattern. E.g. you can easily design your custom character at http://www.quinapalus.com/hd44780udg.html To show your custom character use, for example, lcd.message = ""

Parameters:
  • location – integer in range(8) to store the created character
  • pattern (~bytes) – len(8) describes created character
cursor

True if cursor is visible. False to stop displaying the cursor.

The following example shows the cursor after a displayed message:

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.cursor = True
lcd.message = "Cursor! "
time.sleep(5)
cursor_position(column, row)[source]

Move the cursor to position column, row for the next message only. Displaying a message resets the cursor position to (0, 0).

param column:column location
param row:row location
display

Enable or disable the display. True to enable the display. False to disable the display.

The following example displays, “Hello, world!” on the LCD and then turns the display off.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.message = "Hello, world!"
time.sleep(5)
lcd.display = False
home()[source]

Moves the cursor “home” to position (0, 0).

message

Display a string of text on the character LCD. Start position is (0,0) if cursor_position is not set. If cursor_position is set, message starts at the set position from the left for left to right text and from the right for right to left text. Resets cursor column and row to (0,0) after displaying the message.

The following example displays, “Hello, world!” on the LCD.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.message = "Hello, world!"
time.sleep(5)
move_left()[source]

Moves displayed text left one column.

The following example scrolls a message to the left off the screen.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

scroll_message = "<-- Scroll"
lcd.message = scroll_message
time.sleep(2)
for i in range(len(scroll_message)):
    lcd.move_left()
    time.sleep(0.5)
move_right()[source]

Moves displayed text right one column.

The following example scrolls a message to the right off the screen.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

scroll_message = "Scroll -->"
lcd.message = scroll_message
time.sleep(2)
for i in range(len(scroll_message) + 16):
    lcd.move_right()
    time.sleep(0.5)
text_direction

The direction the text is displayed. To display the text left to right beginning on the left side of the LCD, set text_direction = LEFT_TO_RIGHT. To display the text right to left beginning on the right size of the LCD, set text_direction = RIGHT_TO_LEFT. Text defaults to displaying from left to right.

The following example displays “Hello, world!” from right to left.

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello, world!"
time.sleep(5)
class adafruit_character_lcd.character_lcd.Character_LCD_Mono(rs, en, db4, db5, db6, db7, columns, lines, backlight_pin=None, backlight_inverted=False)[source]

Interfaces with monochromatic character LCDs.

Parameters:
  • rs (DigitalInOut) – The reset data line
  • en (DigitalInOut) – The enable data line
  • d4 (DigitalInOut) – The data line 4
  • d5 (DigitalInOut) – The data line 5
  • d6 (DigitalInOut) – The data line 6
  • d7 (DigitalInOut) – The data line 7
  • columns – The columns on the charLCD
  • lines – The lines on the charLCD
  • backlight_pin (DigitalInOut) – The backlight pin
  • backlight_inverted (bool) – False if LCD is not inverted, i.e. backlight pin is connected to common anode. True if LCD is inverted i.e. backlight pin is connected to common cathode.
backlight

Enable or disable backlight. True if backlight is on. False if backlight is off.

The following example turns the backlight off, then displays, “Hello, world?”, then turns the backlight on and displays, “Hello, world!”

import time
import board
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA

lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

lcd.backlight = False
lcd.message = "Hello, world?"
time.sleep(5)
lcd.backlight = True
lcd.message = "Hello, world!"
time.sleep(5)
class adafruit_character_lcd.character_lcd.Character_LCD_RGB(rs, en, db4, db5, db6, db7, columns, lines, red, green, blue, read_write=None)[source]

Interfaces with RGB character LCDs.

Parameters:
color

The color of the display. Provide a list of three integers ranging 0 - 100, [R, G, B]. 0 is no color, or “off”. 100 is maximum color. For example, the brightest red would be [100, 0, 0], and a half-bright purple would be, [50, 0, 50].

If PWM is unavailable, 0 is off, and non-zero is on. For example, [1, 0, 0] would be red.

The following example turns the LCD red and displays, “Hello, world!”.

import time
import board
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd

i2c = board.I2C()  # uses board.SCL and board.SDA

lcd = character_lcd.Character_LCD_RGB_I2C(i2c, 16, 2)

lcd.color = [100, 0, 0]
lcd.message = "Hello, world!"
time.sleep(5)

adafruit_character_lcd.character_lcd_i2c

Module for using I2C with I2C/SPI character LCD backpack

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_character_lcd.character_lcd_i2c.Character_LCD_I2C(i2c, columns, lines, address=None, backlight_inverted=False)[source]

Character LCD connected to I2C/SPI backpack using its I2C connection. This is a subclass of Character_LCD_Mono and implements all of the same functions and functionality.

To use, import and initialise as follows:

import board
from adafruit_character_lcd.character_lcd_i2c import Character_LCD_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_I2C(i2c, 16, 2)

adafruit_character_lcd.character_lcd_rgb_i2c

Module for using I2C with I2C RGB LCD Shield or I2C RGB LCD Pi Plate

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_character_lcd.character_lcd_rgb_i2c.Character_LCD_RGB_I2C(i2c, columns, lines, address=None)[source]

RGB Character LCD connected to I2C shield or Pi plate using I2C connection. This is a subclass of Character_LCD_RGB and implements all of the same functions and functionality.

To use, import and initialise as follows:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
down_button

The down button on the RGB Character LCD I2C Shield or Pi plate.

The following example prints “Down!” to the LCD when the down button is pressed:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

while True:
    if lcd.down_button:
        lcd.message = "Down!"
left_button

The left button on the RGB Character LCD I2C Shield or Pi plate.

The following example prints “Left!” to the LCD when the left button is pressed:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

while True:
    if lcd.left_button:
        lcd.message = "Left!"
right_button

The right button on the RGB Character LCD I2C Shield or Pi plate.

The following example prints “Right!” to the LCD when the right button is pressed:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

while True:
    if lcd.right_button:
        lcd.message = "Right!"
select_button

The select button on the RGB Character LCD I2C Shield or Pi plate.

The following example prints “Select!” to the LCD when the select button is pressed:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

while True:
    if lcd.select_button:
        lcd.message = "Select!"
up_button

The up button on the RGB Character LCD I2C Shield or Pi plate.

The following example prints “Up!” to the LCD when the up button is pressed:

import board
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

while True:
    if lcd.up_button:
        lcd.message = "Up!"

adafruit_character_lcd.character_lcd_spi

Module for using SPI with I2C/SPI character LCD backpack

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_character_lcd.character_lcd_spi.Character_LCD_SPI(spi, latch, columns, lines, backlight_inverted=False)[source]

Character LCD connected to I2C/SPI backpack using its SPI connection. This is a subclass of Character_LCD_Mono and implements all of the same functions and functionality.

To use, import and initialise as follows:

import board
import digitalio
import adafruit_character_lcd.character_lcd_mono as character_lcd

spi = board.SPI()
latch = digitalio.DigitalInOut(board.D5)
lcd = character_lcd.Character_LCD_SPI(spi, latch, 16, 2)