Created
June 17, 2019 17:40
-
-
Save anecdata/771c7ad55e41fd1baa1b846d6994b0f9 to your computer and use it in GitHub Desktop.
3.5" FeatherWing (HX8357) [FeatherM4, 4.1.0-beta.0, Library Bundle 20190615]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This test will initialize the display using displayio | |
and draw a solid red background | |
""" | |
import board | |
import displayio | |
import time | |
print('Begin') | |
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) | |
try: | |
from adafruit_hx8357 import HX8357 | |
display = HX8357(display_bus, width=480, height=320) | |
time.sleep(5) # https://learn.adafruit.com/adafruit-3-5-tft-featherwing/troubleshooting | |
print('Display: HX8357') | |
except RuntimeError as e: | |
print('HX8357 Error:', e) | |
# SPI Frequency | |
while not spi.try_lock(): | |
pass | |
try: | |
print("SPI:", "{:>8}".format(spi.frequency), "Hz old") | |
attempt_baud = 3000000 | |
print("SPI:", "{:>8}".format(attempt_baud), "Hz try") | |
spi.configure(baudrate=attempt_baud) | |
except RuntimeError as e: | |
print('SPI Error:', e) | |
finally: | |
print("SPI:", "{:>8}".format(spi.frequency), "Hz new") | |
spi.unlock() | |
print("SPI:", "{:>8}".format(spi.frequency), "Hz unlocked") | |
# Make the display context | |
splash = displayio.Group(max_size=10) | |
display.show(splash) | |
color_bitmap = displayio.Bitmap(480, 320, 1) | |
color_palette = displayio.Palette(1) | |
color_palette[0] = 0xFF0000 | |
bg_sprite = displayio.TileGrid(color_bitmap, | |
pixel_shader=color_palette, | |
x=0, y=0) | |
splash.append(bg_sprite) | |
time.sleep(1) | |
display.show(None) | |
print("SPI:", "{:>8}".format(spi.frequency), "Hz pre-loop") | |
loop = 0 | |
while True: | |
time.sleep(.1) | |
print(loop, "SPI:", "{:>8}".format(spi.frequency), "Hz") | |
loop += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like baudrate shouldn't be changed once the SPI display is initialized, so "slow mode" can be avoided with a different code sequence by doing any SPI frequency changes before setting up SPI devices. It will then be static for the life of the program. It's not clear whether this is intentional. Without context manager, SPI frequency does seem to persist across reloads, hardware reset, and power loss.