Raspberry Pi Pico 2/CircuitPython 9 display bmp on ST7789 LCD using adafruit_imageload/adafruit_slideshow

Previous post show how Raspberry Pi Pico 2/CircuitPython 9 display on 1.54" 240x240 ST7789 SPI IPS. This post show two exercises to display bmp using adafruit_imageload/adafruit_slideshow.


adafruit_imageload decodes an image file into new bitmap and palette objects of the provided type. It’s designed to load code needed during decoding as needed. This is meant to minimize the memory overhead of the decoding code.

adafruit_slideshow CircuitPython helper library for displaying a slideshow of images on a display.

Connection:

Keep using the same connection in previous exercise.

Test images:

All the test images shown in the above video were AI generated using "Image Creator in Bing", and resize and convert to 240x240 RGBB888/RGB565 bmp using Python/GIMP.

Exercise Code:

cpy_pico2_st7789_imageload.py, display bmp using adafruit_imageload
"""
Raspberry Pi Pico 2/CircuitPython 9
to display on 1.54" 240x240 ST7789 SPI IPS

Display bmp using adafruit_imageload

Connection:
-----------
GND   GND
VCC   3V3
SCL   GP18
SDA   GP19
RES   GP20
DC    GP21
CS    GP17
BLK   GP22

CircuitPython Libraries Bundle for Version 9.x needed:
(https://circuitpython.org/libraries)
- adafruit_st7789.mpy
- adafruit_imageload folder

Exercise to display bmp using adafruit_imageload
ref:
https://docs.circuitpython.org/projects/imageload/en/latest/
https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad
"""

import os, sys
import microcontroller
import board
import busio
import displayio
import adafruit_st7789
import adafruit_imageload

disp_sck  = board.GP18
disp_mosi = board.GP19
disp_res  = board.GP20
disp_dc   = board.GP21
disp_cs   = board.GP17
disp_blk  = board.GP22

# Release any resources currently in use for the displays
displayio.release_displays()

disp_spi = busio.SPI(clock=disp_sck, MOSI=disp_mosi)

display_bus = displayio.FourWire(spi_bus=disp_spi,
                                 command=disp_dc,
                                 chip_select=disp_cs,
                                 reset=disp_res)

display = adafruit_st7789.ST7789(display_bus,
                                 width=240,
                                 height=240,
                                 rowstart=80,
                                 rotation=180,
                                 backlight_pin=disp_blk)

sys_info_text = sys.implementation[0] + " " + os.uname()[3] +\
                "\nrun on " + os.uname()[4] +\
                "\n" + adafruit_st7789.__name__ + " " + adafruit_st7789.__version__ +\
                "\n" + adafruit_imageload.__name__ + " " + adafruit_imageload.__version__
print("====================================")
print(sys_info_text)
print("====================================")
print()

#loadImg = "/images/01_gimpConverted_240_rgb888.bmp"
#loadImg = "/images/02_gimpConverted_240_rgb565.bmp"
#loadImg = "/images/03_pythonConverted_240x240_rgb888.bmp"
loadImg = "/images/04_pythonConverted_240x240_rgb565.bmp"


# Make the display context
image, palette = adafruit_imageload.load(
    loadImg, bitmap=displayio.Bitmap, palette=displayio.Palette
)

print(loadImg)
print(image.width, "x", image.height)

tile_grid = displayio.TileGrid(image, pixel_shader=palette)

group = displayio.Group()
group.append(tile_grid)
display.root_group = group
while True:
    pass
   
print("~ bye ~")



cpy_pico2_st7789_slideshow.py, display images in SlideShow using adafruit_slideshow.
"""
Raspberry Pi Pico 2/CircuitPython 9
to display on 1.54" 240x240 ST7789 SPI IPS

Display images in SlideShow using adafruit_slideshow

Connection:
-----------
GND   GND
VCC   3V3
SCL   GP18
SDA   GP19
RES   GP20
DC    GP21
CS    GP17
BLK   GP22

CircuitPython Libraries Bundle for Version 9.x needed:
(https://circuitpython.org/libraries)
- adafruit_st7789.mpy
- adafruit_slideshow.mpy

Display images in SlideShow using adafruit_slideshow
ref:
https://learn.adafruit.com/creating-slideshows-in-circuitpython/
"""

import os, sys
import microcontroller
import board
import busio
import displayio
import adafruit_st7789
import adafruit_slideshow

disp_sck  = board.GP18
disp_mosi = board.GP19
disp_res  = board.GP20
disp_dc   = board.GP21
disp_cs   = board.GP17
disp_blk  = board.GP22

# Release any resources currently in use for the displays
displayio.release_displays()

disp_spi = busio.SPI(clock=disp_sck, MOSI=disp_mosi)

display_bus = displayio.FourWire(spi_bus=disp_spi,
                                 command=disp_dc,
                                 chip_select=disp_cs,
                                 reset=disp_res)

display = adafruit_st7789.ST7789(display_bus,
                                 width=240,
                                 height=240,
                                 rowstart=80,
                                 rotation=180,
                                 backlight_pin=disp_blk)

sys_info_text = sys.implementation[0] + " " + os.uname()[3] +\
                "\nrun on " + os.uname()[4] +\
                "\n" + adafruit_st7789.__name__ + " " + adafruit_st7789.__version__ +\
                "\n" + adafruit_slideshow.__name__ + " " + adafruit_slideshow.__version__
print("====================================")
print(sys_info_text)
print("====================================")
print()

# Create the slideshow object that plays through once alphabetically.
slideshow = adafruit_slideshow.SlideShow(display,
                                         folder="/images",
                                         loop=True,
                                         order=adafruit_slideshow.PlayBackOrder.ALPHABETICAL,
                                         dwell=5)

while slideshow.update():
    pass
   
print("~ bye ~")

Tested working on Pico 2 W also.


Next:
displayio.OnDiskBitmap on Pico 2 W/CircuitPython 9

Related:
Display bmp with XIAO ESP32S3 Sense/CircuitPython on GC9A01 Round LCD using OnDiskBitmap, adafruit_imageload and adafruit_slideshow


Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator