Skip to content

Instantly share code, notes, and snippets.

@anecdata
Last active June 3, 2019 16:48
Show Gist options
  • Save anecdata/52aeb6e1917822a9ed48a069d5976be2 to your computer and use it in GitHub Desktop.
Save anecdata/52aeb6e1917822a9ed48a069d5976be2 to your computer and use it in GitHub Desktop.
CP 4.0.1 Feather M4 + 2.4" TFT .bmp rough simpletest
import board
import os
import busio
import digitalio
import displayio
import storage
import adafruit_sdcard
import adafruit_ili9341
from adafruit_slideshow import PlayBackOrder, SlideShow, PlayBackDirection
# very rough demo composed from:
# https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/PyPortal_ViewMaster/code.py
# https://github.com/adafruit/Adafruit_CircuitPython_ILI9341/blob/master/examples/ili9341_simpletest.py
spi = board.SPI()
tft_cs = board.D9
tft_dc = board.D10
displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
# Default location to look is in internal memory
IMAGE_DIRECTORY = "/images"
switch = digitalio.DigitalInOut(board.D6)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP
cs = digitalio.DigitalInOut(board.D5)
try:
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
IMAGE_DIRECTORY = "/sd/images"
except OSError as error:
print("No SD card, will only look on internal memory")
def print_directory(path, tabs=0):
for file in os.listdir(path):
stats = os.stat(path + "/" + file)
filesize = stats[6]
isdir = stats[0] & 0x4000
if filesize < 1000:
sizestr = str(filesize) + " by"
elif filesize < 1000000:
sizestr = "%0.1f KB" % (filesize / 1000)
else:
sizestr = "%0.1f MB" % (filesize / 1000000)
prettyprintname = ""
for _ in range(tabs):
prettyprintname += " "
prettyprintname += file
if isdir:
prettyprintname += "/"
print('{0:<20} Size: {1:>6}'.format(prettyprintname, sizestr))
# recursively print directory contents
if isdir:
print_directory(path + "/" + file, tabs + 1)
try:
print_directory(IMAGE_DIRECTORY)
except OSError as error:
raise Exception("No images found on flash or SD Card")
# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(display, None, folder=IMAGE_DIRECTORY, loop=True,
order=PlayBackOrder.ALPHABETICAL, dwell=0)
while True:
if not switch.value:
print("Click!")
slideshow.direction = PlayBackDirection.FORWARD
slideshow.advance()
while not switch.value:
pass
@anecdata
Copy link
Author

anecdata commented Jun 3, 2019

I don't see anything in https://github.com/adafruit/Adafruit_CircuitPython_Slideshow/blob/master/adafruit_slideshow.py about image size. They'd probably get pinned to (0,0) or maybe centered, haven't dug that deep. They must be .bmp. Does the REPL list your files (the print_directory() function)? Maybe try it with one or two standard images from Adafruit demos first.

@evaherrada
Copy link

Yeah. It does. They are .bmp and it does list the files. I'll try that.

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