Pico Inky Pack Image Display

Posted on March 15, 2023

This bit of code displays a random image pulled from the internet on the screen of a Pico Inky Pack.

import board
import busio
import digitalio
import adafruit_requests as requests
import adafruit_inky
from adafruit_imageload import load_image, dither

# Set up the Inky display and buttons
inky_display = adafruit_inky.AutoDisplay()
button = digitalio.DigitalInOut(board.BUTTON_A)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

# Set up the SPI bus and pins
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D22)
reset_pin = digitalio.DigitalInOut(board.D27)

# Initialize the Inky display
inky = adafruit_inky.InkyPHAT(spi, cs_pin, dc_pin, reset_pin, rotation=180)

# Get the image from picsum.photos
image_url = "https://picsum.photos/g/296/128"
response = requests.get(image_url)
image_file = response.content
image, palette = load_image(image_file)

# Dither the image
dither.dither_bitmask(image, bitmap=image)

# Display the dithered image on the Inky display
inky_display.display(inky, image)

# Wait for button press to exit
while button.value:

Comments are closed.