With this example, tailored to the PyGamer, you can have a portable picture frame.  Put the BMP files in the main folder of your SD card, put the code below in code.py, and make sure you've configured mount_sd.py!

This example can be adapted to a lot of CircuitPython boards with support for displayio

For more information on making bitmap files, check out this guide.

# SPDX-FileCopyrightText: 2020 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT

import os
import time

import board
import displayio

display = board.DISPLAY

# The bmp files on the sd card will be shown in alphabetical order
bmpfiles = sorted("/sd/" + fn for fn in os.listdir("/sd") if fn.lower().endswith("bmp"))

while True:
    if len(bmpfiles) == 0:
        print("No BMP files found")

    for filename in bmpfiles:
        print("showing", filename)

        # CircuitPython 6 & 7 compatible
        bitmap_file = open(filename, "rb")
        bitmap = displayio.OnDiskBitmap(bitmap_file)
        tile_grid = displayio.TileGrid(
            pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter())

        # # CircuitPython 7+ compatible
        # bitmap = displayio.OnDiskBitmap(filename)
        # tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)

        group = displayio.Group()

        # Show the image for 10 seconds
Adafruit PyGamer Starter Kit with PCB, enclosure, buttons, and storage bag
Please note: you may get a royal blue or purple case with your starter kit (they're both lovely colors)What fits in your pocket, is fully Open...
Out of Stock
Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.
What fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the Adafruit...
Out of Stock

This guide was first published on Jul 31, 2020. It was last updated on Jul 31, 2020.

This page (Showing BMPs from SD card) was last updated on Sep 20, 2023.

Text editor powered by tinymce.