Skip to content

Commit 12f24d1

Browse files
committed
wait before initializing touch screen. Retry once
1 parent 73c0f74 commit 12f24d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

adafruit_featherwing/tft_featherwing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Requires:
1616
* adafruit_stmpe610
1717
"""
18+
import time
1819
import board
1920
import digitalio
2021
import displayio
@@ -45,7 +46,6 @@ def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
4546
sd_cs = board.D5
4647

4748
ts_cs = digitalio.DigitalInOut(ts_cs)
48-
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
4949

5050
self._display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
5151

@@ -56,3 +56,12 @@ def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
5656
storage.mount(vfs, "/sd")
5757
except OSError as error:
5858
print("No SD card found:", error)
59+
60+
try:
61+
# the screen might not be ready from cold boot
62+
time.sleep(0.8)
63+
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
64+
except RuntimeError:
65+
# wait and try once more
66+
time.sleep(1.0)
67+
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)

0 commit comments

Comments
 (0)