Skip to content

Instantly share code, notes, and snippets.

@arthurescriou
Last active May 8, 2023 17:30
Show Gist options
  • Select an option

  • Save arthurescriou/0df401bb0cc46aa8764e01433c2e938e to your computer and use it in GitHub Desktop.

Select an option

Save arthurescriou/0df401bb0cc46aa8764e01433c2e938e to your computer and use it in GitHub Desktop.
import board
import digitalio
import adafruit_rgb_display.ili9341 as ili9341
from PIL import Image, ImageDraw, ImageFont
# Initialize the display
spi = board.SPI()
tft_cs = digitalio.DigitalInOut(board.CE0)
tft_dc = digitalio.DigitalInOut(board.D24)
display = ili9341.ILI9341(spi, cs=tft_cs, dc=tft_dc)
# Create an image
image = Image.new("RGB", (display.width, display.height))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, display.width, display.height), fill=(255, 255, 255))
# Draw some text
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)
text = "Hello World!"
text_width, text_height = draw.textsize(text, font)
x = (display.width - text_width) // 2
y = (display.height - text_height) // 2
draw.text((x, y), text, font=font, fill=(0, 0, 0))
# Display the image
display.image(image)
display.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment