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
16# Initialise the lcd class
17lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
18
19# Turn backlight on
20lcd.backlight = True
21# Print a two line message
22lcd.message = "Hello\nCircuitPython"
23# Wait 5s
24time.sleep(5)
25lcd.clear()
26# Print two line message right to left
27lcd.text_direction = lcd.RIGHT_TO_LEFT
28lcd.message = "Hello\nCircuitPython"
29# Wait 5s
30time.sleep(5)
31# Return text direction to left to right
32lcd.text_direction = lcd.LEFT_TO_RIGHT
33# Display cursor
34lcd.clear()
35lcd.cursor = True
36lcd.message = "Cursor! "
37# Wait 5s
38time.sleep(5)
39# Display blinking cursor
40lcd.clear()
41lcd.blink = True
42lcd.message = "Blinky Cursor!"
43# Wait 5s
44time.sleep(5)
45lcd.blink = False
46lcd.clear()
47# Create message to scroll
48scroll_msg = "<-- Scroll"
49lcd.message = scroll_msg
50# Scroll message to the left
51for i in range(len(scroll_msg)):
52 time.sleep(0.5)
53 lcd.move_left()
54lcd.clear()
55lcd.message = "Going to sleep\nCya later!"
56time.sleep(5)
57# Turn backlight off
58lcd.backlight = False
59time.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
16# Initialise the LCD class
17lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
18
19lcd.clear()
20# Set LCD color to red
21lcd.color = [100, 0, 0]
22time.sleep(1)
23# Print two line message
24lcd.message = "Hello\nCircuitPython"
25# Wait 5s
26time.sleep(5)
27# Set LCD color to blue
28lcd.color = [0, 100, 0]
29time.sleep(1)
30# Set LCD color to green
31lcd.color = [0, 0, 100]
32time.sleep(1)
33# Set LCD color to purple
34lcd.color = [50, 0, 50]
35time.sleep(1)
36lcd.clear()
37# Print two line message right to left
38lcd.text_direction = lcd.RIGHT_TO_LEFT
39lcd.message = "Hello\nCircuitPython"
40# Wait 5s
41time.sleep(5)
42# Return text direction to left to right
43lcd.text_direction = lcd.LEFT_TO_RIGHT
44# Display cursor
45lcd.clear()
46lcd.cursor = True
47lcd.message = "Cursor! "
48# Wait 5s
49time.sleep(5)
50# Display blinking cursor
51lcd.clear()
52lcd.blink = True
53lcd.message = "Blinky Cursor!"
54# Wait 5s
55time.sleep(5)
56lcd.blink = False
57lcd.clear()
58# Create message to scroll
59scroll_msg = "<-- Scroll"
60lcd.message = scroll_msg
61# Scroll to the left
62for i in range(len(scroll_msg)):
63 time.sleep(0.5)
64 lcd.move_left()
65lcd.clear()
66time.sleep(1)
67lcd.message = "Going to sleep\nCya later!"
68time.sleep(5)
69# Turn off LCD backlights and clear text
70lcd.color = [0, 0, 0]
71lcd.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
16# Initialise the LCD class
17lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
18
19lcd.clear()
20lcd.color = [100, 0, 0]
21while True:
22 if lcd.left_button:
23 print("Left!")
24 lcd.message = "Left!"
25
26 elif lcd.up_button:
27 print("Up!")
28 lcd.message = "Up!"
29
30 elif lcd.down_button:
31 print("Down!")
32 lcd.message = "Down!"
33
34 elif lcd.right_button:
35 print("Right!")
36 lcd.message = "Right!"
37
38 elif lcd.select_button:
39 print("Select!")
40 lcd.message = "Select!"
41
42 else:
43 time.sleep(0.1)
44 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)