adafruit / Adafruit_CircuitPython_BitmapSaver

Save displayio bitmaps to BMP disk
MIT License
5 stars 9 forks source link

Simpletest fails on TFT Featherwing SD Card #24

Closed DJDevon3 closed 2 years ago

DJDevon3 commented 2 years ago

On 3.5" TFT Featherwing with on-board SD Card the screenshot simpletest fails due to save_pixels invalid 2nd argument. Bitmap or Display expected but no 2nd argument was given. Here's the code that works in Circuit Python 7.3.x. on NRF52840 Feather Sense + TFT Featherwing with SD Card

# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT

"""Screenshot on a 3.5" TFT Featherwing (integrated SD Card)"""

# pylint:disable=invalid-name
import board
import digitalio
import displayio
import adafruit_sdcard
from adafruit_bitmapsaver import save_pixels
import storage
from adafruit_hx8357 import HX8357

# Will also work on 2.5" TFT Featherwing just change the size.
DISPLAY_WIDTH = 480
DISPLAY_HEIGHT = 320

# Initialize Protocol Busses and SD Card
i2c = board.I2C()
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
displayio.release_displays()

# Setup Pinouts according to your feather board
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)

# Mount Virtual File System
virtual_root = "/sd"
storage.mount(vfs, virtual_root)

print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp", display)
print("Screenshot taken")
dhalbert commented 2 years ago

This doesn't appear to be the entire program: HX8357 is not imported.

DJDevon3 commented 2 years ago

Yeah it's part of a long script, tried my best to pull everything out. Missed 1. :P from adafruit_hx8357 import HX8357

Can see the pretty screenshot it took here

BitmapSaver works great!

FoamyGuy commented 2 years ago

The simpletest (and default behavior of the library) is written to assume it's taking a screenshot of a built-in display. The featherwing counts as an external display for this purpose and therefore this library cannot find it automatically, it must be passed as the 2nd argument as you noted.

I think we would want to keep the simpletest as-is showing the most basic case. But we could add a new example script for external display screenshots. In the example we can note which specific display it initializes but also can mention that people can substitute in the proper initialization for the display they are using.

Are you interested in making a new PR with the script you've shared added to the examples/ directory @DJDevon3 ?

DJDevon3 commented 2 years ago

Sure but I've never made a PR. No idea how. :/

DJDevon3 commented 2 years ago

OK got github for windows installed. Think I submitted a PR adding a tft featherwing example? It's showing up as a pull request to me. Pretty sure that worked.

tekktrik commented 2 years ago

@DJDevon3 are you still working on this? If you want, I can add the "First Good Issue" label to this and open it up for Hacktoberfest in a couple weeks!

DJDevon3 commented 2 years ago

@tekktrik Surprised this one is still open. The problem was that I was attempting to use code designed for built-in displays on an external display. At the time I didn't understand the difference. It wasn't a bug, more like inexperienced user error. It was just an issue of a missing example for external displays. I contributed a TFT featherwing example which can also be used for external displays. Still look back on this one fondly, my first ever PR. Closing.