Simple test

Ensure your device works with this simple test.

examples/serlcd_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Simple Test - serlcd_simpletest.py
15 Written by Gaston Williams, July 16, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Simple Test:
21 This program writes Hello, World! to the display.
22"""
23import board
24
25# Enable I2C (Qwiic) communication
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31# Enable SPI communication
32# import digitalio
33# from sparkfun_serlcd import Sparkfun_SerLCD_SPI
34# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
35
36# Set up chip select, CE0 or D8 is labeled CS on Sparkfun Pi Hat
37# cs = digitalio.DigitalInOut(board.CE0)
38# cs.direction = digitalio.Direction.OUTPUT
39#
40# serlcd = Sparkfun_SerLCD_SPI(spi, cs)
41
42# Enable UART Serial communication
43# SerLCD is connected to the RPi via a USB to TTL 3.3v Serial Cable:
44# https://www.sparkfun.com/products/12977
45# https://www.adafruit.com/product/954
46# import serial
47# from sparkfun_serlcd import Sparkfun_SerLCD_UART
48#
49# usb0 = serial.Serial(
50#        port='/dev/ttyUSB0',
51#        baudrate = 9600,
52#        parity=serial.PARITY_NONE,
53#        stopbits=serial.STOPBITS_ONE,
54#        bytesize=serial.EIGHTBITS,
55#        timeout=1)
56#
57# serlcd = Sparkfun_SerLCD_UART(usb0)
58
59print("SerLCD Simple Test")
60
61serlcd.write("Hello, world!")

Examples

  1. Hello World - Write a ‘Hello, World!’ message on the display.

examples/example1_hello_world.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 1 - example1_hello_world.py
15 Written by Gaston Williams, July 16, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 1 - Hello World:
21 This program writes Hello, World! to the display,
22 then displays a count on the next line.
23"""
24from time import sleep
25import board
26
27# Enable I2C communication
28from sparkfun_serlcd import Sparkfun_SerLCD_I2C
29
30i2c = board.I2C()
31serlcd = Sparkfun_SerLCD_I2C(i2c)
32
33# Enable SPI communication
34# import digitalio
35# from sparkfun_serlcd import Sparkfun_SerLCD_SPI
36# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
37#
38# Set up chip select, CE0 or D8 is labeled CS on Sparkfun Pi Hat
39# cs = digitalio.DigitalInOut(board.CE0)
40# cs.direction = digitalio.Direction.OUTPUT
41#
42# serlcd = Sparkfun_SerLCD_SPI(spi, cs)
43
44# Enable UART Serial communication
45# SerLCD is connected to the RPi via a USB to TTL 3.3v Serial Cable:
46# https://www.sparkfun.com/products/12977
47# https://www.adafruit.com/product/954
48
49# import serial
50# from sparkfun_serlcd import Sparkfun_SerLCD_UART
51# usb0 = serial.Serial(
52#        port='/dev/ttyUSB0',
53#        baudrate = 9600,
54#        parity=serial.PARITY_NONE,
55#        stopbits=serial.STOPBITS_ONE,
56#        bytesize=serial.EIGHTBITS,
57#        timeout=1)
58#
59# serlcd = Sparkfun_SerLCD_UART(usb0)
60
61print("Example 1: Hello World")
62print("Press Ctrl-C to end program.")
63
64serlcd.write("Hello, world!")
65
66i = 0
67try:
68    while True:
69        serlcd.set_cursor(0, 1)
70        serlcd.write(i)
71        i += 1
72        sleep(1)
73
74except KeyboardInterrupt:
75    pass
  1. Backlight - Change the backlight color on the display.

examples/example2_backlight.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 2 - example2_backlight.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 2 - Backlight:
21 This program changes the backlight of the display through a cycle
22 of colors by setting the red, green and blue values individually.
23 This example works with the original version of SerLCD. See
24 Example 13 FastBacklight for version 1.1 and later.
25"""
26from time import sleep
27import board
28from sparkfun_serlcd import Sparkfun_SerLCD_I2C
29
30i2c = board.I2C()
31serlcd = Sparkfun_SerLCD_I2C(i2c)
32
33print("Example 2: Backlight.")
34print("Press Ctrl-C to end program.")
35
36try:
37    while True:
38        serlcd.set_backlight_rgb(0, 0, 0)  # black is off
39        serlcd.clear()
40        serlcd.write("Black (off)")
41        sleep(3)
42
43        serlcd.set_backlight_rgb(255, 0, 0)  # bright red
44        serlcd.clear()
45        serlcd.write("Red")
46        sleep(3)
47
48        serlcd.set_backlight(0xFF8C00)  # orange
49        serlcd.clear()
50        serlcd.write("Orange")
51        sleep(3)
52
53        serlcd.set_backlight_rgb(255, 255, 0)  # bright yellow
54        serlcd.clear()
55        serlcd.write("Yellow")
56        sleep(3)
57
58        serlcd.set_backlight_rgb(0, 255, 0)  # bright green
59        serlcd.clear()
60        serlcd.write("Green")
61        sleep(3)
62
63        serlcd.set_backlight_rgb(0, 0, 255)  # bright blue
64        serlcd.clear()
65        serlcd.write("Blue")
66        sleep(3)
67
68        serlcd.set_backlight(0x4B0082)  # indigo, a kind of dark purplish blue
69        serlcd.clear()
70        serlcd.write("Indigo")
71        sleep(3)
72
73        serlcd.set_backlight(0xA020F0)  # violet
74        serlcd.clear()
75        serlcd.write("Violet")
76        sleep(3)
77
78        serlcd.set_backlight(0x808080)  # grey
79        serlcd.clear()
80        serlcd.write("Grey")
81        sleep(3)
82
83        serlcd.set_backlight_rgb(255, 255, 255)  # bright white
84        serlcd.clear()
85        serlcd.write("White")
86        sleep(3)
87
88except KeyboardInterrupt:
89    pass
  1. Cursor Position - Randomly change the cursor position and print a character.

examples/example3_cursor_position.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 3 - example3_cursor_position.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 3 - Cursor Position:
21 This program randomly picks a cursor position, goes to that
22 position using the set _cursor() method, and prints a character.
23"""
24import time
25import random
26import board
27from sparkfun_serlcd import Sparkfun_SerLCD_I2C
28
29i2c = board.I2C()
30serlcd = Sparkfun_SerLCD_I2C(i2c)
31
32# These constants match a 16x2 SerLCD display
33num_cols = 16
34num_rows = 2
35# For a 20 x 4 SerLCD display use these values instead
36# num_cols = 20
37# num_rows = 4
38
39# Starting character value
40letter = ord("a")
41
42print("Example 3: Cursor Position")
43print("Press Ctrl-C to end program.")
44
45# Clear the display before writing random letters
46serlcd.clear()
47
48try:
49    while True:
50        # pick a random column 0 to 15 (or 19)
51        col = random.randint(0, num_cols - 1)
52        # pick a random row 0 to 1 (or 3)
53        row = random.randint(0, num_rows - 1)
54
55        # Move to random location and write the next letter
56        serlcd.set_cursor(col, row)
57        serlcd.write(chr(letter))
58
59        # Get the next letter wrapping around after z
60        letter += 1
61        if letter > ord("z"):
62            letter = ord("a")
63
64        time.sleep(0.5)
65
66except KeyboardInterrupt:
67    pass
  1. Move Cursor - Move the cursor on the display.

examples/example4_move_cursor.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 4 - example4_move_cursor.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 4 - Move Cursor:
21 This program displays text and then moves the cursor back and forth.
22"""
23from time import sleep
24import board
25from sparkfun_serlcd import Sparkfun_SerLCD_I2C
26
27i2c = board.I2C()
28serlcd = Sparkfun_SerLCD_I2C(i2c)
29
30print("Example 4: Move Cursor")
31print("Press Ctrl-C to end program.")
32
33# Clear the display before writing random letters
34serlcd.clear()
35# Turn the cursor on
36serlcd.cursor(True)
37try:
38    while True:
39        serlcd.clear()
40        serlcd.write("Watch cursor!  ")
41        serlcd.move_cursor_left()
42        sleep(0.5)
43        serlcd.move_cursor_left()
44        sleep(0.5)
45        serlcd.move_cursor_left()
46        sleep(0.5)
47
48        # Move back in one step
49        serlcd.move_cursor_right(3)
50        sleep(0.5)
51
52        # Move cursor ahead 3 places in 1 step
53        serlcd.move_cursor_right(3)
54        sleep(0.5)
55
56        # Move back in 3 steps
57        serlcd.move_cursor_left()
58        sleep(0.5)
59        serlcd.move_cursor_left()
60        sleep(0.5)
61        serlcd.move_cursor_left()
62        sleep(0.5)
63
64except KeyboardInterrupt:
65    pass
  1. Enable Cursor - Enable and Disable the cursor on the display.

examples/example5_enable_cursor.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 5 - example4_enable_cursor.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 5 - Enable Cursor:
21 This program displays text and uses the cursor(True) and cursor(False)
22 methods to turn the cursor on and off.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 5: Enable Cursor")
32print("Press Ctrl-C to end program.")
33
34# Clear the display before writing text
35serlcd.clear()
36serlcd.write("Hello, World!")
37
38try:
39    while True:
40        # Turn the cursor on
41        serlcd.cursor(True)
42        sleep(0.5)
43
44        # Turn the cursor off
45        serlcd.cursor(False)
46        sleep(0.5)
47
48except KeyboardInterrupt:
49    pass
  1. Blink Cursor - Blink the cursor on the display.

examples/example6_blink_cursor.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 6 - example6_blink_cursor.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 6 - Blink Cursor:
21 This program displays text and makes the cursor block blink.
22"""
23from time import sleep
24import board
25from sparkfun_serlcd import Sparkfun_SerLCD_I2C
26
27i2c = board.I2C()
28serlcd = Sparkfun_SerLCD_I2C(i2c)
29
30print("Example 6: Blink Cursor")
31print("Press Ctrl-C to end program.")
32
33# Clear the display before writing text
34serlcd.clear()
35serlcd.write("Hello, World!")
36
37try:
38    while True:
39        # Turn the cursor on
40        serlcd.blink(True)
41        sleep(2)
42
43        # Turn the cursor off
44        serlcd.blink(False)
45        sleep(2)
46
47except KeyboardInterrupt:
48    pass
  1. Scroll Display - Scroll the text on the display.

examples/example7_scroll_display.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 7 - example6_scroll_display.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 7 - Scroll Display:
21 This program displays text and uses the scroll_display_left() and the
22 scroll_display_right() methods to scroll the text.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 7: Scroll Display")
32print("Press Ctrl-C to end program.")
33
34# Clear the display before writing text
35
36try:
37    while True:
38        serlcd.clear()
39        serlcd.write("Hello, World!")
40        sleep(1)
41
42        # Scroll 13 positions (string length) to the left to move offscreen
43        for i in range(13):
44            # Scroll one position left
45            serlcd.scroll_display_left()
46            # wait a bit
47            sleep(0.150)
48
49        # Scroll 29 positions (string length + display length) to the right
50        # to move text offscreen right.
51        for i in range(29):
52            # Scroll one position right:
53            serlcd.scroll_display_right()
54            # wait a bit:
55            sleep(0.150)
56
57        # Scroll 16 positions (display length + string length) to the left
58        # to move it back to center:
59        for i in range(16):
60            # Scroll one position left:
61            serlcd.scroll_display_left()
62            # wait a bit:
63            sleep(0.150)
64
65        # delay at the end of the full loop
66        sleep(1)
67
68except KeyboardInterrupt:
69    pass
  1. Autoscroll - Autoscroll the text as new text is entered on the display.

examples/example8_autoscroll_text.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 8 - example6_autoscroll_text.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 8 - Autoscroll Text:
21 This program use of the autoscroll(True) and autoscroll(False)
22 to make new text scroll or not.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 8: Autoscroll Text")
32print("Press Ctrl-C to end program.")
33
34# Clear the display before writing text
35
36try:
37    while True:
38        serlcd.clear()
39
40        # Print from 0 to 9:
41        for i in range(10):
42            serlcd.write(str(i))
43            sleep(0.5)
44
45        # Set display to automatically scroll:
46        serlcd.autoscroll(True)
47
48        # Print from 0 to 9:
49        for i in range(10):
50            # Set cursor to end of string as we add letters
51            serlcd.set_cursor(10 + i, 0)
52            serlcd.write(str(i))
53            sleep(0.5)
54
55        # Turn off automatic scrolling
56        serlcd.autoscroll(False)
57        sleep(1)
58
59except KeyboardInterrupt:
60    pass
  1. Custom Characters - Create and Write custom characters on the display.

examples/example9_custom_characters.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 9 - example9_custom_characters.py
15 Written by Gaston Williams, July 16, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 9 - Custom Characters:
21 This program prints "I <heart> SerLCD! <smiley>" with a little dancing
22 man to the LCD. Since the Serial OpenLCD display uses a serial command
23 to display a customer character, the writeChar() method was added for
24 this function.  Custom characters are recorded to SerLCD and they are
25 remembered even after power is lost. There is a maximum of 8 custom
26 characters that can be recorded.
27"""
28from time import sleep
29import board
30from sparkfun_serlcd import Sparkfun_SerLCD_I2C
31
32i2c = board.I2C()
33serlcd = Sparkfun_SerLCD_I2C(i2c)
34
35# Define some custom characters as 8 x 5 bitmap arrays
36heart = [0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000]
37
38smiley = [0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000]
39
40frownie = [0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b00000, 0b01110, 0b10001]
41
42arms_down = [0b00100, 0b01010, 0b00100, 0b00100, 0b01110, 0b10101, 0b00100, 0b01010]
43
44arms_up = [0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010]
45
46print("Example 9: Custom Character")
47print("Press Ctrl-C to end program.")
48
49# Clear the display
50serlcd.clear()
51
52# Send custom characters to display
53# These are recorded to SerLCD and are remembered even after power is lost
54# There is a maximum of 8 custom characters that can be recorded
55
56serlcd.create_character(0, heart)
57serlcd.create_character(1, smiley)
58serlcd.create_character(2, frownie)
59serlcd.create_character(3, arms_down)
60serlcd.create_character(4, arms_up)
61
62# Print a message to the LCD.
63serlcd.write("I ")
64# Write the heart character. We use write_character since it's a serial display.
65serlcd.write_character(0)
66serlcd.write(" SerLCD! ")
67# Write smiley
68serlcd.write_character(1)
69
70try:
71    while True:
72        serlcd.set_cursor(4, 1)  # column, row
73        serlcd.write_character(3)  # Print the little man, arms down
74        sleep(0.200)
75
76        serlcd.set_cursor(4, 1)  # column, row
77        serlcd.write_character(4)  # Print the little man, arms up
78        sleep(0.200)
79
80except KeyboardInterrupt:
81    pass
  1. Turn Off Display - Turn the display off and on.

examples/example10_turn_off_display.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 10 - example10_turn_off_display.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 10 - Turn Off Display:
21 This program writes a message to the display,
22 then uses the display(True) and display(False)
23 methods to turn the display on and off.
24"""
25from time import sleep
26import board
27from sparkfun_serlcd import Sparkfun_SerLCD_I2C
28
29i2c = board.I2C()
30serlcd = Sparkfun_SerLCD_I2C(i2c)
31
32print("Example 10: Turn Off Display")
33print("Press Ctrl-C to end program.")
34
35serlcd.clear()
36
37serlcd.write("Display on/off.")
38
39try:
40    while True:
41        serlcd.display(False)
42        sleep(0.5)
43
44        serlcd.display(True)
45        sleep(0.5)
46
47except KeyboardInterrupt:
48    pass
  1. Text Direction - Write text in left and right to the display..

examples/example11_text_direction.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 11 - example11_text_direction.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 11 - Text Direction:
21 This program uses left_to_right() and right_to_left()
22 to change where the next character will be written.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 11: Text Direction")
32print("Press Ctrl-C to end program.")
33
34serlcd.write("Hello, world!")
35
36letter_a = ord("a")
37letter_j = ord("j")
38letter_q = ord("q")
39letter_z = ord("z")
40
41# Start with letter 'a'
42letter = letter_a
43
44# Clear the display
45serlcd.clear()
46
47# Turn on the cursor
48serlcd.cursor(True)
49
50try:
51    while True:
52        # Reverse direction at 'j'
53        if letter == letter_j:
54            serlcd.right_to_left()
55
56        # Reverse again at 'q'
57        if letter == letter_q:
58            serlcd.left_to_right()
59
60        # Reset at 'z' and go to (0,0)
61        if letter > letter_z:
62            letter = letter_a
63            serlcd.clear()
64            sleep(0.5)
65
66        serlcd.write(chr(letter))
67        sleep(1)  # wait a second
68        letter += 1
69
70except KeyboardInterrupt:
71    pass
  1. Display Input Text - Write input text from program onto the display.

examples/example12_display_input_text.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 12 - example12_display_input_text.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 12 - Display Input Text:
21 This program takes text typed into the console and writes
22 it to the serial displays.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 12: Display Input Text")
32print("Press Ctrl-C to end program.")
33
34
35try:
36    while True:
37        text = input("Please type some text to display: ")
38        serlcd.clear()
39        serlcd.write(text)
40        sleep(2)
41
42except KeyboardInterrupt:
43    pass
  1. Fast Backlight - Change the backlight color on the display quickly.

examples/example13_fast_backlight.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 13 - example13_fast_backlight.py
15 Written by Gaston Williams, July 14th, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 13 - Fast Backlight:
21 This program changes the backlight of the display through a cycle
22 of colors by setting red, green and blue values together.
23"""
24from time import sleep
25import board
26from sparkfun_serlcd import Sparkfun_SerLCD_I2C
27
28i2c = board.I2C()
29serlcd = Sparkfun_SerLCD_I2C(i2c)
30
31print("Example 13: Fast Backlight")
32print("Press Ctrl-C to end program.")
33
34try:
35    while True:
36        serlcd.set_fast_backlight_rgb(0, 0, 0)  # black is off
37        serlcd.clear()
38        serlcd.write("Black (off)")
39        sleep(3)
40
41        serlcd.set_fast_backlight_rgb(255, 0, 0)  # bright red
42        serlcd.clear()
43        serlcd.write("Red")
44        sleep(3)
45
46        serlcd.set_fast_backlight(0xFF8C00)  # orange
47        serlcd.clear()
48        serlcd.write("Orange")
49        sleep(3)
50
51        serlcd.set_fast_backlight_rgb(255, 255, 0)  # bright yellow
52        serlcd.clear()
53        serlcd.write("Yellow")
54        sleep(3)
55
56        serlcd.set_fast_backlight_rgb(0, 255, 0)  # bright green
57        serlcd.clear()
58        serlcd.write("Green")
59        sleep(3)
60
61        serlcd.set_fast_backlight_rgb(0, 0, 255)  # bright blue
62        serlcd.clear()
63        serlcd.write("Blue")
64        sleep(3)
65
66        serlcd.set_fast_backlight(0x4B0082)  # indigo, a kind of dark purplish blue
67        serlcd.clear()
68        serlcd.write("Indigo")
69        sleep(3)
70
71        serlcd.set_fast_backlight(0xA020F0)  # violet
72        serlcd.clear()
73        serlcd.write("Violet")
74        sleep(3)
75
76        serlcd.set_fast_backlight(0x808080)  # grey
77        serlcd.clear()
78        serlcd.write("Grey")
79        sleep(3)
80
81        serlcd.set_fast_backlight_rgb(255, 255, 255)  # bright white
82        serlcd.clear()
83        serlcd.write("White")
84        sleep(3)
85
86except KeyboardInterrupt:
87    pass
  1. Show Firmware Version - Write firmware version on the display.

examples/example14_show_firmware_version.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 12 - example12_show_firmware_version.py
15 Written by Gaston Williams, July 16, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 12 - Show Firmware Version:
21 This program shows the current serial lcd firmware version on the display.
22"""
23from time import sleep
24import board
25from sparkfun_serlcd import Sparkfun_SerLCD_I2C
26
27i2c = board.I2C()
28serlcd = Sparkfun_SerLCD_I2C(i2c)
29
30print("Example 12: Show Firmware Version")
31print("Press Ctrl-C to end program.")
32
33serlcd.clear()
34
35try:
36    while True:
37        # Display the firmware version for 0.5 second
38        serlcd.show_version()
39        sleep(0.5)
40
41except KeyboardInterrupt:
42    pass
  1. System Messages - Show system messages on the display after commands.

examples/example15_system_messages.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 15 - example15_message_enable.py
15 Written by Gaston Williams, July 15, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 15 - Message Enable:
21 This program turns the system messages off and on. These messages are shown
22 when the user changes a setting. For instance 'Contrast: 5' or 'UART: 57600'
23 is no longer displayed when system messages are turned off.  This example
24 and the system_messages(True) and system_messages(False) methods are only
25 supported on SerLCD v1.2 and above.
26
27
28"""
29from time import sleep
30import board
31from sparkfun_serlcd import Sparkfun_SerLCD_I2C
32
33i2c = board.I2C()
34serlcd = Sparkfun_SerLCD_I2C(i2c)
35
36print("Press Ctrl-C to end program.")
37
38
39try:
40    while True:
41        serlcd.clear()
42        serlcd.system_messages(True)
43        serlcd.set_contrast(5)
44        # Send invidual R, G, B backlight commands to see more messages
45        serlcd.command(157)
46        serlcd.command(187)
47        serlcd.command(217)
48        serlcd.write("Messages on")
49        serlcd.set_cursor(0, 1)
50        serlcd.write("White")
51        sleep(3)
52
53        serlcd.clear()
54        serlcd.system_messages(False)
55        serlcd.set_contrast(0)
56        serlcd.command(144)
57        serlcd.command(162)
58        serlcd.command(202)
59        serlcd.write("Messages off")
60        serlcd.set_cursor(0, 1)
61        serlcd.write("Purple")
62        sleep(2)
63
64except KeyboardInterrupt:
65    pass
  1. Splash Screen - Change the splash screen shown when the display is powered on.

examples/example16_splash_screen.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Serial LCD displays.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/14072
10#  https://www.sparkfun.com/products/14073
11#  https://www.sparkfun.com/products/14074
12
13"""
14 Serial LCD Example 16 - example16_splash_screen.py
15 Written by Gaston Williams, July 15, 2019
16 Based on Arduino code written by Gaston Williams and
17 Nathan Seidle @ Sparkfun, August 22, 2018.
18
19
20 Example 16 - Splash Screen:
21 This program sets the power splash screen on the display. You can set
22 the text to anything you like. After changing the splash screen you will
23 need to power down and power up the display to see the change. To return
24 to the original default splash screen, display a single character 0xFF,
25 and save that as the splash screen.
26"""
27import board
28from sparkfun_serlcd import Sparkfun_SerLCD_I2C
29
30i2c = board.I2C()
31serlcd = Sparkfun_SerLCD_I2C(i2c)
32
33print("Example 16: Splash Screen")
34
35# Set backlight to bright white
36serlcd.set_backlight_rgb(255, 255, 255)
37# Set contrast. Lower to 0 for higher contrast.
38serlcd.set_contrast(5)
39
40# Clear the display - this moves the cursor to home position as well
41serlcd.clear()
42
43# Display whatever splash screen message you like here
44serlcd.write("Fozziwig's Chicken Factory!")
45
46# Save the current text as the splash screen at next power on
47serlcd.save_splash_screen()
48
49# Uncomment this line to set splash screen back to default
50# serlcd.default_splash_screen()
51
52# This will cause the splash to be displayed at power on
53serlcd.splash_screen(True)
54
55# Uncomment the next line to supress any splash display at power on
56# serlcd.splash_screen(False)
57
58print("Power off dislpay. Then Power back on to see Splash Screen changes.")