Simple tests¶
Ensure your device works with these simple tests.
Mono¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for monochromatic character LCD"""
5import time
6import board
7import digitalio
8import adafruit_character_lcd.character_lcd as characterlcd
9
10# Modify this if you have a different sized character LCD
11lcd_columns = 16
12lcd_rows = 2
13
14# Metro M0/M4 Pin Config:
15lcd_rs = digitalio.DigitalInOut(board.D7)
16lcd_en = digitalio.DigitalInOut(board.D8)
17lcd_d7 = digitalio.DigitalInOut(board.D12)
18lcd_d6 = digitalio.DigitalInOut(board.D11)
19lcd_d5 = digitalio.DigitalInOut(board.D10)
20lcd_d4 = digitalio.DigitalInOut(board.D9)
21lcd_backlight = digitalio.DigitalInOut(board.D13)
22
23# Initialise the LCD class
24lcd = characterlcd.Character_LCD_Mono(
25 lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
26)
27
28# Turn backlight on
29lcd.backlight = True
30# Print a two line message
31lcd.message = "Hello\nCircuitPython"
32# Wait 5s
33time.sleep(5)
34lcd.clear()
35# Print two line message right to left
36lcd.text_direction = lcd.RIGHT_TO_LEFT
37lcd.message = "Hello\nCircuitPython"
38# Wait 5s
39time.sleep(5)
40# Return text direction to left to right
41lcd.text_direction = lcd.LEFT_TO_RIGHT
42# Display cursor
43lcd.clear()
44lcd.cursor = True
45lcd.message = "Cursor! "
46# Wait 5s
47time.sleep(5)
48# Display blinking cursor
49lcd.clear()
50lcd.blink = True
51lcd.message = "Blinky Cursor!"
52# Wait 5s
53time.sleep(5)
54lcd.blink = False
55lcd.clear()
56# Create message to scroll
57scroll_msg = "<-- Scroll"
58lcd.message = scroll_msg
59# Scroll message to the left
60for i in range(len(scroll_msg)):
61 time.sleep(0.5)
62 lcd.move_left()
63lcd.clear()
64lcd.message = "Going to sleep\nCya later!"
65time.sleep(3)
66# Turn backlight off
67lcd.backlight = False
68time.sleep(2)
RGB¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for RGB character LCD"""
5import time
6import board
7import digitalio
8import pwmio
9import adafruit_character_lcd.character_lcd as characterlcd
10
11# Modify this if you have a different sized character LCD
12lcd_columns = 16
13lcd_rows = 2
14
15# Metro M0/M4 Pin Config:
16lcd_rs = digitalio.DigitalInOut(board.D7)
17lcd_en = digitalio.DigitalInOut(board.D8)
18lcd_d7 = digitalio.DigitalInOut(board.D12)
19lcd_d6 = digitalio.DigitalInOut(board.D11)
20lcd_d5 = digitalio.DigitalInOut(board.D10)
21lcd_d4 = digitalio.DigitalInOut(board.D9)
22red = pwmio.PWMOut(board.D3)
23green = pwmio.PWMOut(board.D5)
24blue = pwmio.PWMOut(board.D6)
25
26# Initialise the LCD class
27lcd = characterlcd.Character_LCD_RGB(
28 lcd_rs,
29 lcd_en,
30 lcd_d4,
31 lcd_d5,
32 lcd_d6,
33 lcd_d7,
34 lcd_columns,
35 lcd_rows,
36 red,
37 green,
38 blue,
39)
40
41lcd.clear()
42# Set LCD color to red
43lcd.color = [100, 0, 0]
44time.sleep(1)
45# Print two line message
46lcd.message = "Hello\nCircuitPython"
47# Wait 5s
48time.sleep(5)
49# Set LCD color to blue
50lcd.color = [0, 100, 0]
51time.sleep(1)
52# Set LCD color to green
53lcd.color = [0, 0, 100]
54time.sleep(1)
55# Set LCD color to purple
56lcd.color = [50, 0, 50]
57time.sleep(1)
58lcd.clear()
59# Print two line message right to left
60lcd.text_direction = lcd.RIGHT_TO_LEFT
61lcd.message = "Hello\nCircuitPython"
62# Wait 5s
63time.sleep(5)
64# Return text direction to left to right
65lcd.text_direction = lcd.LEFT_TO_RIGHT
66# Display cursor
67lcd.clear()
68lcd.cursor = True
69lcd.message = "Cursor! "
70# Wait 5s
71time.sleep(5)
72# Display blinking cursor
73lcd.clear()
74lcd.blink = True
75lcd.message = "Blinky Cursor!"
76# Wait 5s
77time.sleep(5)
78lcd.blink = False
79lcd.clear()
80# Create message to scroll
81scroll_msg = "<-- Scroll"
82lcd.message = scroll_msg
83# Scroll to the left
84for i in range(len(scroll_msg)):
85 time.sleep(0.5)
86 lcd.move_left()
87lcd.clear()
88time.sleep(1)
89lcd.message = "Going to sleep\nCya later!"
90time.sleep(5)
91# Turn off LCD backlights and clear text
92lcd.color = [0, 0, 0]
93lcd.clear()
I2C Mono¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for 16x2 character lcd connected to an MCP23008 I2C LCD backpack."""
5import time
6import board
7import adafruit_character_lcd.character_lcd_i2c as character_lcd
8
9# Modify this if you have a different sized Character LCD
10lcd_columns = 16
11lcd_rows = 2
12
13# Initialise I2C bus.
14i2c = board.I2C() # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
16
17# Initialise the lcd class
18lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
19
20# Turn backlight on
21lcd.backlight = True
22# Print a two line message
23lcd.message = "Hello\nCircuitPython"
24# Wait 5s
25time.sleep(5)
26lcd.clear()
27# Print two line message right to left
28lcd.text_direction = lcd.RIGHT_TO_LEFT
29lcd.message = "Hello\nCircuitPython"
30# Wait 5s
31time.sleep(5)
32# Return text direction to left to right
33lcd.text_direction = lcd.LEFT_TO_RIGHT
34# Display cursor
35lcd.clear()
36lcd.cursor = True
37lcd.message = "Cursor! "
38# Wait 5s
39time.sleep(5)
40# Display blinking cursor
41lcd.clear()
42lcd.blink = True
43lcd.message = "Blinky Cursor!"
44# Wait 5s
45time.sleep(5)
46lcd.blink = False
47lcd.clear()
48# Create message to scroll
49scroll_msg = "<-- Scroll"
50lcd.message = scroll_msg
51# Scroll message to the left
52for i in range(len(scroll_msg)):
53 time.sleep(0.5)
54 lcd.move_left()
55lcd.clear()
56lcd.message = "Going to sleep\nCya later!"
57time.sleep(5)
58# Turn backlight off
59lcd.backlight = False
60time.sleep(2)
I2C RGB¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for I2C RGB character LCD shield kit"""
5import time
6import board
7import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
8
9# Modify this if you have a different sized Character LCD
10lcd_columns = 16
11lcd_rows = 2
12
13# Initialise I2C bus.
14i2c = board.I2C() # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
16
17# Initialise the LCD class
18lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
19
20lcd.clear()
21# Set LCD color to red
22lcd.color = [100, 0, 0]
23time.sleep(1)
24# Print two line message
25lcd.message = "Hello\nCircuitPython"
26# Wait 5s
27time.sleep(5)
28# Set LCD color to blue
29lcd.color = [0, 100, 0]
30time.sleep(1)
31# Set LCD color to green
32lcd.color = [0, 0, 100]
33time.sleep(1)
34# Set LCD color to purple
35lcd.color = [50, 0, 50]
36time.sleep(1)
37lcd.clear()
38# Print two line message right to left
39lcd.text_direction = lcd.RIGHT_TO_LEFT
40lcd.message = "Hello\nCircuitPython"
41# Wait 5s
42time.sleep(5)
43# Return text direction to left to right
44lcd.text_direction = lcd.LEFT_TO_RIGHT
45# Display cursor
46lcd.clear()
47lcd.cursor = True
48lcd.message = "Cursor! "
49# Wait 5s
50time.sleep(5)
51# Display blinking cursor
52lcd.clear()
53lcd.blink = True
54lcd.message = "Blinky Cursor!"
55# Wait 5s
56time.sleep(5)
57lcd.blink = False
58lcd.clear()
59# Create message to scroll
60scroll_msg = "<-- Scroll"
61lcd.message = scroll_msg
62# Scroll to the left
63for i in range(len(scroll_msg)):
64 time.sleep(0.5)
65 lcd.move_left()
66lcd.clear()
67time.sleep(1)
68lcd.message = "Going to sleep\nCya later!"
69time.sleep(5)
70# Turn off LCD backlights and clear text
71lcd.color = [0, 0, 0]
72lcd.clear()
SPI Mono¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for 16x2 character LCD connected to 74HC595 SPI LCD backpack."""
5import time
6import board
7import busio
8import digitalio
9import adafruit_character_lcd.character_lcd_spi as character_lcd
10
11# Modify this if you have a different sized character LCD
12lcd_columns = 16
13lcd_rows = 2
14
15# Backpack connection configuration:
16clk = board.SCK # Pin connected to backpack CLK.
17data = board.MOSI # Pin connected to backpack DAT/data.
18latch = board.D5 # Pin connected to backpack LAT/latch.
19
20# Initialise SPI bus.
21spi = busio.SPI(clk, MOSI=data)
22
23# Initialise the LCD class
24latch = digitalio.DigitalInOut(latch)
25lcd = character_lcd.Character_LCD_SPI(spi, latch, lcd_columns, lcd_rows)
26
27# Turn backlight on
28lcd.backlight = True
29# Print a two line message
30lcd.message = "Hello\nCircuitPython"
31# Wait 5s
32time.sleep(5)
33lcd.clear()
34# Print two line message right to left
35lcd.text_direction = lcd.RIGHT_TO_LEFT
36lcd.message = "Hello\nCircuitPython"
37# Wait 5s
38time.sleep(5)
39# Return text direction to left to right
40lcd.text_direction = lcd.LEFT_TO_RIGHT
41# Display cursor
42lcd.clear()
43lcd.cursor = True
44lcd.message = "Cursor! "
45# Wait 5s
46time.sleep(5)
47# Display blinking cursor
48lcd.clear()
49lcd.blink = True
50lcd.message = "Blinky Cursor!"
51# Wait 5s
52time.sleep(5)
53lcd.blink = False
54lcd.clear()
55# Create message to scroll
56scroll_msg = "<-- Scroll"
57lcd.message = scroll_msg
58# Scroll message to the left
59for i in range(len(scroll_msg)):
60 time.sleep(0.5)
61 lcd.move_left()
62lcd.clear()
63lcd.message = "Going to sleep\nCya later!"
64# Turn backlight off
65lcd.backlight = False
66time.sleep(2)
Keypad¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for keypad on I2C RGB character LCD Shield or Pi Plate kits"""
5import time
6import board
7import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
8
9# Modify this if you have a different sized Character LCD
10lcd_columns = 16
11lcd_rows = 2
12
13# Initialise I2C bus.
14i2c = board.I2C() # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
16
17# Initialise the LCD class
18lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
19
20lcd.clear()
21lcd.color = [100, 0, 0]
22while True:
23 if lcd.left_button:
24 print("Left!")
25 lcd.message = "Left!"
26
27 elif lcd.up_button:
28 print("Up!")
29 lcd.message = "Up!"
30
31 elif lcd.down_button:
32 print("Down!")
33 lcd.message = "Down!"
34
35 elif lcd.right_button:
36 print("Right!")
37 lcd.message = "Right!"
38
39 elif lcd.select_button:
40 print("Select!")
41 lcd.message = "Select!"
42
43 else:
44 time.sleep(0.1)
45 lcd.clear()
Raspberry Pi Mono¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for monochromatic character LCD on Raspberry Pi"""
5import time
6import board
7import digitalio
8import adafruit_character_lcd.character_lcd as characterlcd
9
10# Modify this if you have a different sized character LCD
11lcd_columns = 16
12lcd_rows = 2
13
14# Raspberry Pi Pin Config:
15lcd_rs = digitalio.DigitalInOut(board.D26)
16lcd_en = digitalio.DigitalInOut(board.D19)
17lcd_d7 = digitalio.DigitalInOut(board.D27)
18lcd_d6 = digitalio.DigitalInOut(board.D22)
19lcd_d5 = digitalio.DigitalInOut(board.D24)
20lcd_d4 = digitalio.DigitalInOut(board.D25)
21lcd_backlight = digitalio.DigitalInOut(board.D4)
22
23# Initialise the lcd class
24lcd = characterlcd.Character_LCD_Mono(
25 lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
26)
27
28# Turn backlight on
29lcd.backlight = True
30# Print a two line message
31lcd.message = "Hello\nCircuitPython"
32# Wait 5s
33time.sleep(5)
34lcd.clear()
35# Print two line message right to left
36lcd.text_direction = lcd.RIGHT_TO_LEFT
37lcd.message = "Hello\nCircuitPython"
38# Wait 5s
39time.sleep(5)
40# Return text direction to left to right
41lcd.text_direction = lcd.LEFT_TO_RIGHT
42# Display cursor
43lcd.clear()
44lcd.cursor = True
45lcd.message = "Cursor! "
46# Wait 5s
47time.sleep(5)
48# Display blinking cursor
49lcd.clear()
50lcd.blink = True
51lcd.message = "Blinky Cursor!"
52# Wait 5s
53time.sleep(5)
54lcd.blink = False
55lcd.clear()
56# Create message to scroll
57scroll_msg = "<-- Scroll"
58lcd.message = scroll_msg
59# Scroll message to the left
60for i in range(len(scroll_msg)):
61 time.sleep(0.5)
62 lcd.move_left()
63lcd.clear()
64lcd.message = "Going to sleep\nCya later!"
65# Turn backlight off
66lcd.backlight = False
67time.sleep(2)
Raspberry Pi RGB¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Simple test for RGB character LCD on Raspberry Pi"""
5import time
6import board
7import digitalio
8import pwmio
9import adafruit_character_lcd.character_lcd as characterlcd
10
11# Modify this if you have a different sized character LCD
12lcd_columns = 16
13lcd_rows = 2
14
15# Raspberry Pi Pin Config:
16lcd_rs = digitalio.DigitalInOut(board.D26) # LCD pin 4
17lcd_en = digitalio.DigitalInOut(board.D19) # LCD pin 6
18lcd_d7 = digitalio.DigitalInOut(board.D27) # LCD pin 14
19lcd_d6 = digitalio.DigitalInOut(board.D22) # LCD pin 13
20lcd_d5 = digitalio.DigitalInOut(board.D24) # LCD pin 12
21lcd_d4 = digitalio.DigitalInOut(board.D25) # LCD pin 11
22lcd_rw = digitalio.DigitalInOut(
23 board.D4
24) # LCD pin 5. Determines whether to read to or write from the display.
25# Not necessary if only writing to the display. Used on shield.
26
27red = pwmio.PWMOut(board.D21)
28green = pwmio.PWMOut(board.D12)
29blue = pwmio.PWMOut(board.D18)
30
31# Initialize the LCD class
32# The lcd_rw parameter is optional. You can omit the line below if you're only
33# writing to the display.
34lcd = characterlcd.Character_LCD_RGB(
35 lcd_rs,
36 lcd_en,
37 lcd_d4,
38 lcd_d5,
39 lcd_d6,
40 lcd_d7,
41 lcd_columns,
42 lcd_rows,
43 red,
44 green,
45 blue,
46 lcd_rw,
47)
48
49RED = [100, 0, 0]
50GREEN = [0, 100, 0]
51BLUE = [0, 0, 100]
52
53while True:
54 lcd.clear()
55 # Set LCD color to red
56 lcd.color = [100, 0, 0]
57 time.sleep(1)
58
59 # Print two line message
60 lcd.message = "Hello\nCircuitPython"
61
62 # Wait 5s
63 time.sleep(5)
64
65 # Set LCD color to blue
66 lcd.color = [0, 100, 0]
67 time.sleep(1)
68 # Set LCD color to green
69 lcd.color = [0, 0, 100]
70 time.sleep(1)
71 # Set LCD color to purple
72 lcd.color = [50, 0, 50]
73 time.sleep(1)
74 lcd.clear()
75
76 # Print two line message right to left
77 lcd.text_direction = lcd.RIGHT_TO_LEFT
78 lcd.message = "Hello\nCircuitPython"
79 # Wait 5s
80 time.sleep(5)
81
82 # Return text direction to left to right
83 lcd.text_direction = lcd.LEFT_TO_RIGHT
84
85 # Display cursor
86 lcd.clear()
87 lcd.cursor = True
88 lcd.message = "Cursor! "
89 # Wait 5s
90 time.sleep(5)
91
92 # Display blinking cursor
93 lcd.clear()
94 lcd.blink = True
95 lcd.message = "Blinky Cursor!"
96 # Wait 5s
97 time.sleep(5)
98 lcd.blink = False
99 lcd.clear()
100
101 # Create message to scroll
102 scroll_msg = "<-- Scroll"
103 lcd.message = scroll_msg
104 # Scroll to the left
105 for i in range(len(scroll_msg)):
106 time.sleep(0.5)
107 lcd.move_left()
108 lcd.clear()
109
110 # Turn off LCD backlights and clear text
111 lcd.color = [0, 0, 0]
112 lcd.clear()
113 time.sleep(1)
Other tests¶
Custom Character¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Display a custom character"""
5import board
6import digitalio
7import adafruit_character_lcd.character_lcd as characterlcd
8
9# Modify this if you have a different sized character LCD
10lcd_columns = 16
11lcd_rows = 2
12
13# Metro M0/M4 Pin Config:
14lcd_rs = digitalio.DigitalInOut(board.D7)
15lcd_en = digitalio.DigitalInOut(board.D8)
16lcd_d7 = digitalio.DigitalInOut(board.D12)
17lcd_d6 = digitalio.DigitalInOut(board.D11)
18lcd_d5 = digitalio.DigitalInOut(board.D10)
19lcd_d4 = digitalio.DigitalInOut(board.D9)
20lcd_backlight = digitalio.DigitalInOut(board.D13)
21
22# Initialise the LCD class
23lcd = characterlcd.Character_LCD_Mono(
24 lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
25)
26
27checkmark = bytes([0x0, 0x0, 0x1, 0x3, 0x16, 0x1C, 0x8, 0x0])
28
29# Store in LCD character memory 0
30lcd.create_char(0, checkmark)
31
32lcd.clear()
33lcd.message = "\x00 Success \x00"
Nyan Cat¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Use custom characters to display Nyan cat"""
5import time
6import board
7import digitalio
8import adafruit_character_lcd.character_lcd as characterlcd
9
10# Modify this if you have a different sized character LCD
11lcd_columns = 16
12lcd_rows = 2
13
14# Metro M0/M4 Pin Config:
15lcd_rs = digitalio.DigitalInOut(board.D7)
16lcd_en = digitalio.DigitalInOut(board.D8)
17lcd_d7 = digitalio.DigitalInOut(board.D12)
18lcd_d6 = digitalio.DigitalInOut(board.D11)
19lcd_d5 = digitalio.DigitalInOut(board.D10)
20lcd_d4 = digitalio.DigitalInOut(board.D9)
21lcd_backlight = digitalio.DigitalInOut(board.D13)
22
23# Initialise the LCD class
24lcd = characterlcd.Character_LCD_Mono(
25 lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
26)
27
28head = [31, 17, 27, 17, 17, 21, 17, 31]
29
30top_body = [31, 0, 31, 0, 18, 8, 2, 8]
31top_left_corner_body = [31, 16, 16, 17, 22, 20, 20, 20]
32top_right_corner_body = [31, 1, 1, 17, 13, 5, 5, 5]
33
34# these three chars will be the above three reversed with a few minor changes to
35# fit feet into the bottom
36bot_body = []
37bot_left_corner_body = []
38bot_right_corner_body = []
39
40tail_neutral = [0, 0, 0, 0, 31, 31, 0, 0]
41tail_up = [0, 8, 12, 6, 3, 1, 0, 0]
42
43for i in range(7, -1, -1):
44 bot_body.append(top_body[i])
45 bot_left_corner_body.append(top_left_corner_body[i])
46 bot_right_corner_body.append(top_right_corner_body[i])
47
48# adding feet and making space for them
49
50bot_body[6] = 31
51bot_body[5] = 0
52bot_body[4] = 31
53bot_body[7] = 24
54bot_left_corner_body[7] = 0
55bot_left_corner_body[6] = 31
56bot_left_corner_body[7] = 28
57bot_right_corner_body[7] = 0
58bot_right_corner_body[6] = 31
59
60# bottom body with feet forward
61bot_body2 = bot_body[:-1] + [3]
62
63
64rainbow = [0, 0, 6, 25, 11, 29, 27, 12]
65rainbow2 = [0, 0, 6, 31, 13, 5, 23, 12]
66
67lcd.create_char(0, top_body)
68lcd.create_char(1, top_left_corner_body)
69lcd.create_char(2, rainbow)
70lcd.create_char(3, bot_left_corner_body)
71lcd.create_char(4, bot_body)
72lcd.create_char(5, bot_right_corner_body)
73lcd.create_char(6, head)
74lcd.create_char(7, tail_neutral)
75
76lcd.clear()
77
78lcd.move_right()
79lcd.message = (
80 "\x02\x02\x02\x02\x01\x00\x00\x00\x06\n\x02\x02\x02\x07\x03\x04\x04\x04\x05"
81)
82
83lcd.backlight = True
84
85while True:
86 lcd.create_char(4, bot_body2)
87 lcd.create_char(7, tail_up)
88 lcd.create_char(2, rainbow2)
89 lcd.move_right()
90 time.sleep(0.4)
91 lcd.create_char(4, bot_body)
92 lcd.create_char(7, tail_neutral)
93 lcd.create_char(2, rainbow)
94 lcd.move_left()
95 time.sleep(0.4)