Image from microSD
What this example shows
Mount the microSD card, list its files in the shell, and draw image.jpg from the card with dithering. Copy a JPG to the root of the card as image.jpg before you run it, or change IMAGE_PATH. At the end the card's supply is switched off.
Example code
"""Initialize an SD card and render an image located on it."""
# Include needed libraries
from inkplate7spectra import Inkplate
from os import listdir, stat
# Create Inkplate object
inkplate = Inkplate()
# Initialize the display, needs to be called only once
inkplate.begin()
# Initializes the SD card.
#
# Parameters:
# - fastboot (bool, default=False):
# If True, performs a soft reboot immediately after SD card initialization
# (only on cold start or hard reset). This significantly improves SD card
# read speeds—typically doubling performance.
#
# Note:
# - This function must be called before accessing files on the SD card.
# - The fastboot option has no effect if the device is already running.
inkplate.init_sd_card(fast_boot=True)
# This prints all the files on card
print(listdir("/sd"))
# Draw an image on the screen.
#
# Parameters:
# - path: File path to the image. Supports local paths (e.g., from SD card) or URLs.
# Supported formats: JPG, PNG, BMP.
#
# - x0: X-coordinate of the top-left corner where the image will be displayed.
#
# - y0: Y-coordinate of the top-left corner where the image will be displayed.
#
# - invert (bool, default=False): If True, inverts the image colors.
#
# - dither (bool, default=False): If True, applies a dithering algorithm to
# the image for better grayscale rendering.
#
# - kernel_type (int): Specifies the dithering algorithm to use.
# Available options:
# Inkplate.KERNEL_FLOYD_STEINBERG = 0
# Inkplate.KERNEL_JJN = 1
# Inkplate.KERNEL_STUCKI = 2
# Inkplate.KERNEL_BURKES = 3
#
# Performance Notes:
# - JPG: ~52 seconds (or ~90s with dithering)
#
# Example usage:
IMAGE_PATH = "sd/image.jpg"
try:
stat(IMAGE_PATH)
except OSError:
print("Image not found on SD card: {}".format(IMAGE_PATH))
print("Copy an image to that path on the SD card, or change IMAGE_PATH above.")
else:
inkplate.draw_image(
IMAGE_PATH,
0,
0,
invert=False,
dither=True,
kernel_type=Inkplate.KERNEL_FLOYD_STEINBERG,
)
# Show the image from the buffer
inkplate.display()
inkplate.sd_card_sleep()
# To turn it back on, use:
# inkplate.sd_card_wake()
Functions used
Inkplate()returns InkplateCreates the display object from the inkplate7spectra module.
ReturnsThe display object.
inkplate.begin()returns boolSets up the board and a white frame buffer. Call it once.
ReturnsTrue.
inkplate.init_sd_card(fast_boot=False)returns NoneSwitches on the card's supply and mounts the card at /sd. With fast_boot=True it also does a soft reset after a power-on, hard or watchdog reset, which the example says roughly doubles read speed. If the card cannot be read it prints 'Sd card could not be read'.
ReturnsNothing.
inkplate.draw_image(path, x0=0, y0=0, invert=False, dither=False, kernel_type=0)returns NoneDraws a BMP, JPG or PNG image into the frame buffer. A path without http:// or https:// is read as a local file, here from the card. The format comes from the file extension.
ReturnsNothing. An unsupported extension raises ValueError.
inkplate.display(leave_on=False)returns NoneSends the frame buffer to the panel and refreshes it.
ReturnsNothing.
inkplate.sd_card_sleep()returns NoneSwitches off the card's supply.
ReturnsNothing.
inkplate.sd_card_wake()returns NoneSwitches the card's supply on again after sd_card_sleep(). The example only mentions it in a comment.
ReturnsNothing.
listdir() and stat() come from MicroPython's os module.
What to expect
The shell prints the list of files on the card. With image.jpg in place, the screen refreshes and shows the picture from the top-left corner. Without it, the shell prints Image not found on SD card: sd/image.jpg and the hint to copy an image, and the screen refreshes to white.
🔗Open the complete example
examples/inkplate7spectra/displayimagesd/display_image_sd.py