Skip to content

Commit c8e76bb

Browse files
committed
adding tft 3.5 inch helper class
1 parent f4f89f6 commit c8e76bb

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2020 Foamyguy for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
"""
7+
`adafruit_featherwing.tft_featherwing_35`
8+
====================================================
9+
10+
Helper for using the `TFT FeatherWing 3.5"`
11+
<https://www.adafruit.com/product/3651>`_.
12+
13+
* Author(s): Melissa LeBlanc-Williams, Foamyguy
14+
15+
Requires:
16+
* adafruit_hx8357
17+
* adafruit_stmpe610
18+
"""
19+
20+
__version__ = "0.0.0-auto.0"
21+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
22+
23+
import board
24+
import digitalio
25+
import displayio
26+
from adafruit_hx8357 import HX8357
27+
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
28+
import sdcardio
29+
import storage
30+
31+
# pylint: disable-msg=too-few-public-methods
32+
class TFTFeatherWing35:
33+
"""Class representing an `TFT FeatherWing 3.5
34+
<https://www.adafruit.com/product/3651>`_.
35+
36+
"""
37+
38+
def __init__(self, spi=None, cs=None, dc=None):
39+
displayio.release_displays()
40+
if spi is None:
41+
spi = board.SPI()
42+
if cs is None:
43+
cs = board.D9
44+
if dc is None:
45+
dc = board.D10
46+
47+
ts_cs = digitalio.DigitalInOut(board.D6)
48+
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
49+
50+
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
51+
self.display = HX8357(display_bus, width=480, height=320)
52+
53+
sd_cs = board.D5
54+
self._sdcard = None
55+
try:
56+
self._sdcard = sdcardio.SDCard(spi, sd_cs)
57+
vfs = storage.VfsFat(self._sdcard)
58+
storage.mount(vfs, "/sd")
59+
except OSError as error:
60+
print("No SD card found:", error)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example will display a CircuitPython console and
6+
print the coordinates of touchscreen presses.
7+
8+
It will also try to write and then read a file on the
9+
SD Card.
10+
"""
11+
from adafruit_featherwing import tft_featherwing_35
12+
13+
tft_featherwing = tft_featherwing_35.TFTFeatherWing35()
14+
15+
try:
16+
f = open("/sd/tft_featherwing.txt", "w")
17+
f.write("Blinka\nBlackberry Q10 Keyboard")
18+
f.close()
19+
20+
f = open("/sd/tft_featherwing.txt", "r")
21+
print(f.read())
22+
f.close()
23+
except OSError as error:
24+
print("Unable to write to SD Card.")
25+
26+
27+
while True:
28+
if not tft_featherwing.touchscreen.buffer_empty:
29+
print(tft_featherwing.touchscreen.read_data())

0 commit comments

Comments
 (0)