Skip to content

Commit 0c2c6db

Browse files
authored
Merge pull request #63 from FoamyGuy/tft24_featherwing
Adding class for TFT 2.4" FeatherWing
2 parents 10e9e68 + 0ee2885 commit 0c2c6db

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2020 Melissa LeBlanc-Williams, Foamyguy for Adafruit Industries LLC
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_featherwing.tft_featherwing_24`
24+
====================================================
25+
26+
Helper for using the `TFT FeatherWing 2.4"`
27+
<https://www.adafruit.com/product/3315>`_.
28+
29+
* Author(s): Melissa LeBlanc-Williams, Foamyguy
30+
31+
Requires:
32+
* adafruit_ili9341
33+
* adafruit_stmpe610
34+
"""
35+
36+
__version__ = "0.0.0-auto.0"
37+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
38+
39+
import board
40+
import digitalio
41+
import displayio
42+
import adafruit_ili9341
43+
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
44+
import sdcardio
45+
import storage
46+
47+
# pylint: disable-msg=too-few-public-methods
48+
class TFTFeatherWing24:
49+
"""Class representing an `TFT FeatherWing 2.4
50+
<https://www.adafruit.com/product/3315>`_.
51+
52+
"""
53+
54+
def __init__(self, spi=None, cs=None, dc=None):
55+
displayio.release_displays()
56+
if spi is None:
57+
spi = board.SPI()
58+
if cs is None:
59+
cs = board.D9
60+
if dc is None:
61+
dc = board.D10
62+
63+
ts_cs = digitalio.DigitalInOut(board.D6)
64+
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
65+
66+
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
67+
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
68+
69+
sd_cs = board.D5
70+
self._sdcard = None
71+
try:
72+
self._sdcard = sdcardio.SDCard(spi, sd_cs)
73+
vfs = storage.VfsFat(self._sdcard)
74+
storage.mount(vfs, "/sd")
75+
except OSError as error:
76+
print("No SD card found:", error)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This example will display a CircuitPython console and
3+
print the coordinates of touchscreen presses.
4+
5+
It will also try to write and then read a file on the
6+
SD Card.
7+
"""
8+
from adafruit_featherwing import tft_featherwing_24
9+
10+
tft_featherwing = tft_featherwing_24.TFTFeatherWing24()
11+
12+
try:
13+
f = open("/sd/tft_featherwing.txt", "w")
14+
f.write("Blinka\nBlackberry Q10 Keyboard")
15+
f.close()
16+
17+
f = open("/sd/tft_featherwing.txt", "r")
18+
print(f.read())
19+
f.close()
20+
except OSError as error:
21+
print("Unable to write to SD Card.")
22+
23+
24+
while True:
25+
if not tft_featherwing.touchscreen.buffer_empty:
26+
print(tft_featherwing.touchscreen.read_data())

0 commit comments

Comments
 (0)