Skip to main content

Inkplate 5v2 MicroPython - Draw Image from microSD card

Inkplate 5v2 can load and render images directly from the onboard microSD card. This example initializes the SD card, lists its contents and displays a JPEG, PNG or BMP image on screen.


Displaying an image from the SD card

Before running this example, make sure your SD card is formatted as FAT16, FAT32 or exFAT and inserted into Inkplate 5v2. To learn how to format the microSD card, see preparing the microSD card before usage.

The example does not ship with an image, so copy any JPG, PNG or BMP file you like onto the card and set the path in draw_image() to match its filename. The full example script is available in the Inkplate MicroPython library.

from inkplate5v2 import Inkplate
import time
from os import listdir

inkplate = Inkplate(Inkplate.INKPLATE_2BIT)
inkplate.begin()
inkplate.init_sd_card(fast_boot=True)
print(listdir("/sd"))

# Draw image onto the buffer
drawLength = time.ticks_ms()
inkplate.draw_image(
"sd/image.png",
0, 0,
invert=False,
dither=True,
kernel_type=Inkplate.KERNEL_FLOYD_STEINBERG
)
drawLength = time.ticks_diff(time.ticks_ms(), drawLength)
print("Time it took to draw to buffer: {} ms".format(drawLength))
inkplate.display()

# Put SD card interface to sleep
inkplate.sd_card_sleep()
# To wake it again, use: inkplate.sd_card_wake()

inkplate.draw_image()

Draw an image from a file path or URL into the display buffer.

Function parameters:

TypeNameDescription
StringpathPath to image (e.g. "sd/image.png") or URL.
Numberx0X coordinate of the top-left corner.
Numbery0Y coordinate of the top-left corner.
BooleaninvertIf True, invert image colors.
BooleanditherIf True, apply dithering for better grayscale rendering.
Constantkernel_typeDithering algorithm. Options: Inkplate.KERNEL_FLOYD_STEINBERG, Inkplate.KERNEL_JJN, Inkplate.KERNEL_STUCKI, Inkplate.KERNEL_BURKES.
ℹ️

Available options for dithering algorithm:

AlgorithmValue
Inkplate.KERNEL_FLOYD_STEINBERG0
Inkplate.KERNEL_JJN1
Inkplate.KERNEL_STUCKI2
Inkplate.KERNEL_BURKES3

Performance notes

  • JPG: ~3 seconds (or ~7s with dithering)
  • PNG: ~10 seconds (or ~14s with dithering)
  • BMP: ~15 seconds (or ~20s with dithering)
  • Maximum image file size: ~800kB
Inkplate 5v2 running the example code
Displaying an image from SD card.