RP2040/CircuitPython 8.1.0 Beta 1, play animated GIF on 8 bit parallel bus ILI9341.
My previous post show
setup libraries, connection and exercises code on RP2040/CircuitPython
to display on ILI9341 (8bit parallel bus) display. The old post show exercise playing animated GIF in CircuitPython 8.1.0 Beta 0, run on ESP32-S3,
display on ST7789 SPI TFT. Here is exercise run on WeAct RP2040 (16MB Flash)/CircuitPython 8.1.0 Beta
1, play animated GIFs on 2.8 inch 320x240 8 bit parallel ILI9341
TFT.
gifio.OnDiskGif() is used to create an OnDiskGif object
to display animated GIF, it's supported since CircuitPython 8.1.0 Beta 0.
So, make sure it's flashed with CircuitPython 8.1.0 Beta 0 or higher.
cpyPico_ParallelBus_ili9341_aniGIF.py
"""
Run on WeAct RP2040 (16MB Flash)/CircuitPython 8.1.0-beta.1
display on 8 bit ILI9341,
play animated GIFs using gifio.OnDiskGif()
"""
import os, sys
import time
import board
import displayio
import adafruit_ili9341
import gifio
displayio.release_displays()
"""
For Raspberry Pi Pico/RP2040,
supports data0= only, not data_pins=, because it requires contiguous pins.
"""
TFT_DATA0 = board.GP10 #The first data pin. The rest are implied
#D0~D7 = GP10~17
TFT_RS = board.GP9 #command
TFT_CS = board.GP18 #chip Select
TFT_WR = board.GP19 #write
TFT_RD = board.GP8 #read
TFT_RST = board.GP20 #reset
TFT_WIDTH = 320
TFT_HEIGHT = 240
display_bus = displayio.ParallelBus(data0=TFT_DATA0,
command=TFT_RS,
chip_select=TFT_CS,
write=TFT_WR,
read=TFT_RD,
reset=TFT_RST,
frequency=60000000)
display = adafruit_ili9341.ILI9341(display_bus,
width=TFT_WIDTH,
height=TFT_HEIGHT)
display.rotation=0
print("========================================")
print(sys.implementation[0], os.uname()[3],
"\nrun on", os.uname()[4])
print("========================================")
print(adafruit_ili9341.__name__, adafruit_ili9341.__version__)
print(display_bus)
print()
print("display.rotation:", display.rotation)
print("display.width: ", display.width)
print("display.height: ", display.height)
print()
splash = displayio.Group()
display.root_group = splash
def showGIF(gif):
print("------------------")
print("GIF:", gif)
odg = gifio.OnDiskGif(gif) # Create an OnDiskGif object with the given file.
print("W x H:", odg.width, "x", odg.height)
print("frame_count:", odg.frame_count)
odg.next_frame() # Load the first frame
face = displayio.TileGrid(
odg.bitmap,
pixel_shader=displayio.ColorConverter(
input_colorspace=displayio.Colorspace.RGB565_SWAPPED
),
x = int((display.width-odg.width)/2),
y = int((display.height-odg.height)/2),
)
splash.append(face)
display.refresh()
for r in range(odg.frame_count-1):
odg.next_frame() #load next frame
splash.remove(face)
#320x180
gifFiles = ("/GIF2/GIF2_1_320.gif",
"/GIF2/GIF2_2_320.gif",
"/GIF2/GIF2_3_320.gif",
"/GIF2/GIF2_4_320.gif")
"""
#200x113
gifFiles = ("/GIF2/GIF2_1_200.gif",
"/GIF2/GIF2_2_200.gif",
"/GIF2/GIF2_3_200.gif",
"/GIF2/GIF2_4_200.gif")
"""
while True:
for f in gifFiles:
showGIF(f)
next:
~ Play animated GIF stored in SD Card
Remark:
At beginning, I tried to play animated GIFs with higher resolution, it fail with
ValueError: Invalid file
ValueError: Invalid file
Then I resize the GIFs to resolution lower than display resolution, it work fine.
Comments
Post a Comment