Skip to content

Commit c9e46e5

Browse files
authored
Merge pull request #68 from FoamyGuy/add_tft_3_5_inch
Add tft 3.5 inch featherwing helper
2 parents 9355f2e + 12f24d1 commit c9e46e5

9 files changed

+192
-87
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2021 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_featherwing.auto_writeable`
7+
====================================================
8+
9+
Superclass for the helpers pixelmatrix and matrix_featherwing
10+
11+
* Author(s): Tim Cocks
12+
"""
13+
14+
15+
class AutoWriteable:
16+
"""Superclass for matrix_featherwing and pixelmatrix."""
17+
18+
def __init__(self):
19+
self._auto_write = True
20+
21+
@property
22+
def auto_write(self):
23+
"""
24+
Whether or not we are automatically updating
25+
If set to false, be sure to call show() to update
26+
"""
27+
return self._auto_write
28+
29+
@auto_write.setter
30+
def auto_write(self, write):
31+
if isinstance(write, bool):
32+
self._auto_write = write

adafruit_featherwing/keyboard_featherwing.py

+9-28
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
2020
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
2121

2222
import board
23-
import digitalio
24-
import displayio
2523
import adafruit_ili9341
26-
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
27-
import sdcardio
28-
import storage
2924
from bbq10keyboard import BBQ10Keyboard
3025
import neopixel
3126

3227

3328
# pylint: disable-msg=too-few-public-methods
3429
# pylint: disable-msg=too-many-arguments
35-
class KeyboardFeatherwing:
30+
from adafruit_featherwing.tft_featherwing import TFTFeatherWing
31+
32+
33+
class KeyboardFeatherwing(TFTFeatherWing):
3634
"""Class representing a `Keyboard Featherwing`
3735
<https://www.tindie.com/products/arturo182/keyboard-featherwing-qwerty-keyboard-26-lcd/>`_.
3836
@@ -48,32 +46,15 @@ def __init__(
4846
sd_cs=None,
4947
neopixel_pin=None,
5048
):
51-
displayio.release_displays()
52-
if spi is None:
53-
spi = board.SPI()
54-
if cs is None:
55-
cs = board.D9
56-
if dc is None:
57-
dc = board.D10
49+
super().__init__(spi, cs, dc, ts_cs, sd_cs)
50+
5851
if i2c is None:
5952
i2c = board.I2C()
60-
if ts_cs is None:
61-
ts_cs = board.D6
62-
if sd_cs is None:
63-
sd_cs = board.D5
6453
if neopixel_pin is None:
6554
neopixel_pin = board.D11
6655

67-
self.touchscreen = Adafruit_STMPE610_SPI(spi, digitalio.DigitalInOut(ts_cs))
68-
69-
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
70-
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
56+
self.display = adafruit_ili9341.ILI9341(
57+
self._display_bus, width=320, height=240
58+
)
7159
self.neopixel = neopixel.NeoPixel(neopixel_pin, 1)
7260
self.keyboard = BBQ10Keyboard(i2c)
73-
self._sdcard = None
74-
try:
75-
self._sdcard = sdcardio.SDCard(spi, sd_cs)
76-
vfs = storage.VfsFat(self._sdcard)
77-
storage.mount(vfs, "/sd")
78-
except OSError as error:
79-
print("No SD card found:", error)

adafruit_featherwing/matrix_featherwing.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@
1818
import board
1919
import adafruit_ht16k33.matrix as matrix
2020

21+
from adafruit_featherwing.auto_writeable import AutoWriteable
2122

22-
class MatrixFeatherWing:
23+
24+
class MatrixFeatherWing(AutoWriteable):
2325
"""Class representing an `Adafruit 8x16 LED Matrix FeatherWing
2426
<https://www.adafruit.com/product/3155>`_.
2527
2628
Automatically uses the feather's I2C bus."""
2729

2830
def __init__(self, address=0x70, i2c=None):
31+
2932
if i2c is None:
3033
i2c = board.I2C()
3134
self._matrix = matrix.Matrix16x8(i2c, address)
3235
self._matrix.auto_write = False
3336
self.columns = 16
3437
self.rows = 8
35-
self._auto_write = True
38+
super().__init__()
3639

3740
def __getitem__(self, key):
3841
"""
@@ -125,19 +128,6 @@ def shift_down(self, rotate=False):
125128
self._matrix.shift_down(rotate)
126129
self._update()
127130

128-
@property
129-
def auto_write(self):
130-
"""
131-
Whether or not we are automatically updating
132-
If set to false, be sure to call show() to update
133-
"""
134-
return self._auto_write
135-
136-
@auto_write.setter
137-
def auto_write(self, write):
138-
if isinstance(write, bool):
139-
self._auto_write = write
140-
141131
@property
142132
def blink_rate(self):
143133
"""

adafruit_featherwing/pixelmatrix.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
1717

1818
# pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
19+
from adafruit_featherwing.auto_writeable import AutoWriteable
1920

2021

21-
class PixelMatrix:
22+
class PixelMatrix(AutoWriteable):
2223
"""Base Class for DotStar and NeoPixel FeatherWings
2324
2425
The feather uses pins D13 and D11"""
@@ -27,7 +28,7 @@ def __init__(self):
2728
self.rows = 0
2829
self.columns = 0
2930
self._matrix = None
30-
self._auto_write = True
31+
super().__init__()
3132

3233
def __setitem__(self, indices, value):
3334
"""
@@ -158,19 +159,6 @@ def shift_down(self, rotate=False):
158159
self._matrix[(self.rows - 1) * self.columns + x] = last_pixel
159160
self._update()
160161

161-
@property
162-
def auto_write(self):
163-
"""
164-
Whether or not we are automatically updating
165-
If set to false, be sure to call show() to update
166-
"""
167-
return self._auto_write
168-
169-
@auto_write.setter
170-
def auto_write(self, write):
171-
if isinstance(write, bool):
172-
self._auto_write = write
173-
174162
@property
175163
def brightness(self):
176164
"""

adafruit_featherwing/rtc_featherwing.py

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def unixtime(self):
300300
return time.mktime(self._rtc.datetime)
301301
except (AttributeError, RuntimeError) as error:
302302
print("Error attempting to run time.mktime() on this board\n", error)
303+
return None
303304

304305
@unixtime.setter
305306
def unixtime(self, unixtime):
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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`
8+
====================================================
9+
10+
Super class for helpers for using the TFT FeatherWing devices
11+
see tft_featherwng_24 and tft_featherwing_35
12+
13+
* Author(s): Melissa LeBlanc-Williams, Foamyguy
14+
15+
Requires:
16+
* adafruit_stmpe610
17+
"""
18+
import time
19+
import board
20+
import digitalio
21+
import displayio
22+
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
23+
import sdcardio
24+
import storage
25+
26+
27+
# pylint: disable-msg=too-few-public-methods, too-many-arguments
28+
class TFTFeatherWing:
29+
"""Class representing an `TFT FeatherWing 2.4
30+
<https://www.adafruit.com/product/3315>`_.
31+
32+
"""
33+
34+
def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
35+
displayio.release_displays()
36+
if spi is None:
37+
spi = board.SPI()
38+
if cs is None:
39+
cs = board.D9
40+
if dc is None:
41+
dc = board.D10
42+
43+
if ts_cs is None:
44+
ts_cs = board.D6
45+
if sd_cs is None:
46+
sd_cs = board.D5
47+
48+
ts_cs = digitalio.DigitalInOut(ts_cs)
49+
50+
self._display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
51+
52+
self._sdcard = None
53+
try:
54+
self._sdcard = sdcardio.SDCard(spi, sd_cs)
55+
vfs = storage.VfsFat(self._sdcard)
56+
storage.mount(vfs, "/sd")
57+
except OSError as error:
58+
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)

adafruit_featherwing/tft_featherwing_24.py

+9-29
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,21 @@
2020
__version__ = "0.0.0-auto.0"
2121
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
2222

23-
import board
24-
import digitalio
25-
import displayio
23+
2624
import adafruit_ili9341
27-
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
28-
import sdcardio
29-
import storage
3025

3126
# pylint: disable-msg=too-few-public-methods
32-
class TFTFeatherWing24:
27+
from adafruit_featherwing.tft_featherwing import TFTFeatherWing
28+
29+
30+
class TFTFeatherWing24(TFTFeatherWing):
3331
"""Class representing an `TFT FeatherWing 2.4
3432
<https://www.adafruit.com/product/3315>`_.
3533
3634
"""
3735

3836
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 = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
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)
37+
super().__init__(spi, cs, dc)
38+
self.display = adafruit_ili9341.ILI9341(
39+
self._display_bus, width=320, height=240
40+
)
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
from adafruit_hx8357 import HX8357
24+
25+
# pylint: disable-msg=too-few-public-methods
26+
from adafruit_featherwing.tft_featherwing import TFTFeatherWing
27+
28+
29+
class TFTFeatherWing35(TFTFeatherWing):
30+
"""Class representing an `TFT FeatherWing 3.5
31+
<https://www.adafruit.com/product/3651>`_.
32+
33+
"""
34+
35+
def __init__(self, spi=None, cs=None, dc=None):
36+
super().__init__(spi, cs, dc)
37+
self.display = HX8357(self._display_bus, width=480, height=320)
+29
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)