Python Installation of CharLCD Library
You’ll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This will also require enabling I2C on your Raspberry Pi and verifying you are running Python 3.
Once that’s done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-charlcd
If your default Python is version 3 you may need to run ‘pip’ instead. Just make sure you aren’t trying to use CircuitPython on Python 2.x, it isn’t supported!
Python Code
To demonstrate the usage of the character LCD we’ll initialize it and display text using CircuitPython code.
First, you’ll need to import necessary modules, initialize the I2C bus, and create an instance of the character LCD class. Paste the following code into your REPL:
Full Example Code
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """Simple test for I2C RGB character LCD shield kit""" import time import board import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd # Modify this if you have a different sized Character LCD lcd_columns = 16 lcd_rows = 2 # Initialise I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA # Initialise the LCD class lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows) lcd.clear() # Set LCD color to red lcd.color = [100, 0, 0] time.sleep(1) # Print two line message lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) # Set LCD color to blue lcd.color = [0, 100, 0] time.sleep(1) # Set LCD color to green lcd.color = [0, 0, 100] time.sleep(1) # Set LCD color to purple lcd.color = [50, 0, 50] time.sleep(1) lcd.clear() # Print two line message right to left lcd.text_direction = lcd.RIGHT_TO_LEFT lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) # Return text direction to left to right lcd.text_direction = lcd.LEFT_TO_RIGHT # Display cursor lcd.clear() lcd.cursor = True lcd.message = "Cursor! " # Wait 5s time.sleep(5) # Display blinking cursor lcd.clear() lcd.blink = True lcd.message = "Blinky Cursor!" # Wait 5s time.sleep(5) lcd.blink = False lcd.clear() # Create message to scroll scroll_msg = "<-- Scroll" lcd.message = scroll_msg # Scroll to the left for i in range(len(scroll_msg)): time.sleep(0.5) lcd.move_left() lcd.clear() time.sleep(1) lcd.message = "Going to sleep\nCya later!" time.sleep(5) # Turn off LCD backlights and clear text lcd.color = [0, 0, 0] lcd.clear()