It's easy to use display breakouts with Python and the Adafruit CircuitPython RGB Display module. This module allows you to easily write Python code to control the display.
Since there's dozens of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
- Pi 3.3V to TFT V+ (red wire)
- Pi GND to TFT G (black wire)
- Pi SCK to TFT CL (yellow wire)
- Pi MOSI to TFT DA (blue wire)
- Pi CE0 to TFT CS (green wire)
- Pi GPIO25 to TFT DC (white wire)
Software Setup
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling SPI on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Python Installation of RGB Display Library
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-rgb-display
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!
If that complains about pip3 not being installed, then run this first to install it:
sudo apt-get install python3-pip
DejaVu TTF Font
Run the following command to install the DejaVu font:
sudo apt-get install fonts-dejavu
Pillow Library
We also need PIL, the Python Imaging Library, to allow graphics and using text with custom fonts. There are several system libraries that PIL relies on, so installing via a package manager is the easiest way to bring in everything:
sudo apt-get install python3-pil
If you installed the PIL through PIP, you may need to install some additional libraries:
sudo apt-get install libopenjp2-7 libtiff5 libatlas-base-dev
Adabot JPEG
Save the JPEG image of Adabot in the same directory as your code.py file. You can download the image from here or through the Project Bundle from GitHub.
Python Usage
Once you have all of the requirements installed on your Raspberry Pi, copy or download the following example, and run the following, replacing code.py with whatever you named the file:
python3 code.py
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries # SPDX-FileCopyrightText: Adapted from Melissa LeBlanc-Williams's Pi Demo Code # # SPDX-License-Identifier: MIT '''Raspberry Pi Graphics example for the Vertical Newxie TFT''' import time import digitalio import board from PIL import Image, ImageDraw, ImageFont from adafruit_rgb_display import st7789 BORDER = 20 FONTSIZE = 24 cs_pin = digitalio.DigitalInOut(board.CE0) dc_pin = digitalio.DigitalInOut(board.D25) reset_pin = digitalio.DigitalInOut(board.D24) BAUDRATE = 24000000 spi = board.SPI() disp = st7789.ST7789(spi, rotation=180, width=135, height=240, x_offset=53, y_offset=40, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE, ) width = disp.width height = disp.height # -------TEXT AND SHAPES--------- image1 = Image.new("RGB", (width, height)) draw1 = ImageDraw.Draw(image1) draw1.rectangle((0, 0, width, height), fill=(0, 255, 0)) # Green background draw1.rectangle( (BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136) ) font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FONTSIZE) text = "Hello\nWorld!" (font_width, font_height) = font.getsize(text) draw1.text( (30, height // 2 - font_height // 2-12), text, font=font, fill=(255, 255, 0), ) # ------ADABOT JPEG DISPLAY---------- image2 = Image.open("adabot.jpg") image_ratio = image2.width / image2.height screen_ratio = width / height scaled_width = width scaled_height = image2.height * width // image2.width image2 = image2.resize((scaled_width, scaled_height), Image.BICUBIC) x = scaled_width // 2 - width // 2 y = scaled_height // 2 - height // 2 image2 = image2.crop((x, y, x + width, y + height)) while True: disp.image(image1) # show text time.sleep(2) disp.image(image2) # show adabot time.sleep(2)
You'll see the graphics example show on the TFT. First, you'll see a purple rectangle on top of a green rectangle with the text "Hello World!" in the center. Then, you'll see the Adabot JPEG displayed. These two images will swap back and forth in the loop.
Text editor powered by tinymce.