Skip to content

Instantly share code, notes, and snippets.

@todbot
Created May 5, 2022 18:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todbot/59bafc9db1936564e7c3a8d260d5a3ed to your computer and use it in GitHub Desktop.
Save todbot/59bafc9db1936564e7c3a8d260d5a3ed to your computer and use it in GitHub Desktop.
DeathStar animation on GC9A01 round LCD for CircuitPython
# revengeofthefifth_code.py -- deathstar animation for CircuitPython
# 5 May 2022 - @todbot / Tod Kurt
# uses one big tilegrid
#
# ImageMagick commands used to go from GIF to TileGrid BMP:
# convert -coalesce deathstar40.gif -resize 240x240 deathstar-%02d.bmp
# montage -mode concatenate -tile x1 deathstar-*bmp deathstar_tile_tmp.bmp
# convert deathstar_tile_tmp.bmp -colors 8 -type palette -compress none BMP3:deathstar_tile.bmp
# Copy resulting file to CIRCUITPY drive
import time
import board, busio
import displayio
import gc9a01
# set up the GC9A01 round TFT LCD, wiring is for QT Py RP2040
displayio.release_displays()
tft_clk = board.SCK
tft_mosi = board.MOSI
tft_rst = board.TX
tft_dc = board.RX
tft_cs = board.A3
spi = busio.SPI(clock=tft_clk, MOSI=tft_mosi)
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst)
display = gc9a01.GC9A01(display_bus, width=240, height=240, rotation=180)
maingroup = displayio.Group()
display.show(maingroup) # put main group on display, everything goes in maingroup
# load up the big bitmap containing all the tiles
bitmap = displayio.OnDiskBitmap(open("deathstar_tile.bmp", "rb"))
deathstar = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader, tile_width=240, tile_height=240 )
maingroup.append(deathstar)
i=0
i_inc = 1
while True:
print("deathstar ranging ", i)
deathstar[0] = i # animate it
i = i + i_inc
if i==39 or i==0 : i_inc = -i_inc # bounce animation back-n-forth
display.refresh(target_frames_per_second=24)
@todbot
Copy link
Author

todbot commented May 5, 2022

This is the GIF started with:
deathstar40

@todbot
Copy link
Author

todbot commented May 5, 2022

And what the result looks like in action:

revengeofthefifth_demo_nohdr.mp4

@IlaydaBayram
Copy link

This is amazing! Would you be so kind to publish a video to show the steps you took in getting this to work. For instance showing the connections of the display and the phyton process. Thanks in advance!

@todbot
Copy link
Author

todbot commented May 27, 2022

Hi, and thanks! You can check out some display wiring setups for Raspberry Pi Pico and QT Py and general installation tips here: https://github.com/todbot/CircuitPython_GC9A01_demos

Not sure what you mean by "the python process" but if you're asking about how to install CircuitPython, this Learn Guide is a great place to start: https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment