Created
December 20, 2021 22:13
-
-
Save alexras/4c27ac9b897fe646b15f5801d0a50ea0 to your computer and use it in GitHub Desktop.
Character LCD Hello World using RPLCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Tested on a Raspberry Pi 3b+ running Raspbian 11 with i2c enabled via raspi-config, Python 3.9.2 and RPLCD 1.3.0. | |
Display under test is an HD44780 character LCD from Adafruit (https://www.adafruit.com/product/198) | |
soldered to an i2c backpack (https://www.adafruit.com/product/292). Display's i2c address located with `i2cdetect -y 1`. | |
""" | |
from RPLCD import i2c | |
import string | |
from time import sleep | |
lcdmode = 'i2c' | |
cols = 20 | |
rows = 4 | |
charmap = 'A00' | |
i2c_expander = 'MCP23008' | |
address = 0x20 | |
port = 1 | |
lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows) | |
text = (string.ascii_letters + string.digits + string.punctuation)[:cols * rows] | |
i = 0 | |
lcd.backlight_enabled = True | |
while True: | |
lcd.write_string(f"Hello World (Iter {i})") | |
lcd.crlf() | |
lcd.write_string('No bricks here :-)') | |
sleep(2) | |
lcd.clear() | |
text_offset = 0 | |
for row in range(rows): | |
lcd.write_string(text[text_offset:text_offset + cols]) | |
lcd.crlf() | |
text_offset += cols | |
sleep(5) | |
lcd.clear() | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment