Skip to content

Add tft 3.5 inch featherwing helper #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions adafruit_featherwing/auto_writeable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2021 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_featherwing.auto_writeable`
====================================================

Superclass for the helpers pixelmatrix and matrix_featherwing

* Author(s): Tim Cocks
"""


class AutoWriteable:
"""Superclass for matrix_featherwing and pixelmatrix."""

def __init__(self):
self._auto_write = True

@property
def auto_write(self):
"""
Whether or not we are automatically updating
If set to false, be sure to call show() to update
"""
return self._auto_write

@auto_write.setter
def auto_write(self, write):
if isinstance(write, bool):
self._auto_write = write
37 changes: 9 additions & 28 deletions adafruit_featherwing/keyboard_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

import board
import digitalio
import displayio
import adafruit_ili9341
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
import sdcardio
import storage
from bbq10keyboard import BBQ10Keyboard
import neopixel


# pylint: disable-msg=too-few-public-methods
# pylint: disable-msg=too-many-arguments
class KeyboardFeatherwing:
from adafruit_featherwing.tft_featherwing import TFTFeatherWing


class KeyboardFeatherwing(TFTFeatherWing):
"""Class representing a `Keyboard Featherwing`
<https://www.tindie.com/products/arturo182/keyboard-featherwing-qwerty-keyboard-26-lcd/>`_.

Expand All @@ -48,32 +46,15 @@ def __init__(
sd_cs=None,
neopixel_pin=None,
):
displayio.release_displays()
if spi is None:
spi = board.SPI()
if cs is None:
cs = board.D9
if dc is None:
dc = board.D10
super().__init__(spi, cs, dc, ts_cs, sd_cs)

if i2c is None:
i2c = board.I2C()
if ts_cs is None:
ts_cs = board.D6
if sd_cs is None:
sd_cs = board.D5
if neopixel_pin is None:
neopixel_pin = board.D11

self.touchscreen = Adafruit_STMPE610_SPI(spi, digitalio.DigitalInOut(ts_cs))

display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
self.display = adafruit_ili9341.ILI9341(
self._display_bus, width=320, height=240
)
self.neopixel = neopixel.NeoPixel(neopixel_pin, 1)
self.keyboard = BBQ10Keyboard(i2c)
self._sdcard = None
try:
self._sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(self._sdcard)
storage.mount(vfs, "/sd")
except OSError as error:
print("No SD card found:", error)
20 changes: 5 additions & 15 deletions adafruit_featherwing/matrix_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@
import board
import adafruit_ht16k33.matrix as matrix

from adafruit_featherwing.auto_writeable import AutoWriteable

class MatrixFeatherWing:

class MatrixFeatherWing(AutoWriteable):
"""Class representing an `Adafruit 8x16 LED Matrix FeatherWing
<https://www.adafruit.com/product/3155>`_.

Automatically uses the feather's I2C bus."""

def __init__(self, address=0x70, i2c=None):

if i2c is None:
i2c = board.I2C()
self._matrix = matrix.Matrix16x8(i2c, address)
self._matrix.auto_write = False
self.columns = 16
self.rows = 8
self._auto_write = True
super().__init__()

def __getitem__(self, key):
"""
Expand Down Expand Up @@ -125,19 +128,6 @@ def shift_down(self, rotate=False):
self._matrix.shift_down(rotate)
self._update()

@property
def auto_write(self):
"""
Whether or not we are automatically updating
If set to false, be sure to call show() to update
"""
return self._auto_write

@auto_write.setter
def auto_write(self, write):
if isinstance(write, bool):
self._auto_write = write

@property
def blink_rate(self):
"""
Expand Down
18 changes: 3 additions & 15 deletions adafruit_featherwing/pixelmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

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


class PixelMatrix:
class PixelMatrix(AutoWriteable):
"""Base Class for DotStar and NeoPixel FeatherWings

The feather uses pins D13 and D11"""
Expand All @@ -27,7 +28,7 @@ def __init__(self):
self.rows = 0
self.columns = 0
self._matrix = None
self._auto_write = True
super().__init__()

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

@property
def auto_write(self):
"""
Whether or not we are automatically updating
If set to false, be sure to call show() to update
"""
return self._auto_write

@auto_write.setter
def auto_write(self, write):
if isinstance(write, bool):
self._auto_write = write

@property
def brightness(self):
"""
Expand Down
1 change: 1 addition & 0 deletions adafruit_featherwing/rtc_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def unixtime(self):
return time.mktime(self._rtc.datetime)
except (AttributeError, RuntimeError) as error:
print("Error attempting to run time.mktime() on this board\n", error)
return None

@unixtime.setter
def unixtime(self, unixtime):
Expand Down
67 changes: 67 additions & 0 deletions adafruit_featherwing/tft_featherwing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
# SPDX-FileCopyrightText: 2020 Foamyguy for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_featherwing.tft_featherwing`
====================================================

Super class for helpers for using the TFT FeatherWing devices
see tft_featherwng_24 and tft_featherwing_35

* Author(s): Melissa LeBlanc-Williams, Foamyguy

Requires:
* adafruit_stmpe610
"""
import time
import board
import digitalio
import displayio
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
import sdcardio
import storage


# pylint: disable-msg=too-few-public-methods, too-many-arguments
class TFTFeatherWing:
"""Class representing an `TFT FeatherWing 2.4
<https://www.adafruit.com/product/3315>`_.

"""

def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
displayio.release_displays()
if spi is None:
spi = board.SPI()
if cs is None:
cs = board.D9
if dc is None:
dc = board.D10

if ts_cs is None:
ts_cs = board.D6
if sd_cs is None:
sd_cs = board.D5

ts_cs = digitalio.DigitalInOut(ts_cs)

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

self._sdcard = None
try:
self._sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(self._sdcard)
storage.mount(vfs, "/sd")
except OSError as error:
print("No SD card found:", error)

try:
# the screen might not be ready from cold boot
time.sleep(0.8)
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
except RuntimeError:
# wait and try once more
time.sleep(1.0)
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
38 changes: 9 additions & 29 deletions adafruit_featherwing/tft_featherwing_24.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,21 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

import board
import digitalio
import displayio

import adafruit_ili9341
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
import sdcardio
import storage

# pylint: disable-msg=too-few-public-methods
class TFTFeatherWing24:
from adafruit_featherwing.tft_featherwing import TFTFeatherWing


class TFTFeatherWing24(TFTFeatherWing):
"""Class representing an `TFT FeatherWing 2.4
<https://www.adafruit.com/product/3315>`_.

"""

def __init__(self, spi=None, cs=None, dc=None):
displayio.release_displays()
if spi is None:
spi = board.SPI()
if cs is None:
cs = board.D9
if dc is None:
dc = board.D10

ts_cs = digitalio.DigitalInOut(board.D6)
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)

display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)

sd_cs = board.D5
self._sdcard = None
try:
self._sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(self._sdcard)
storage.mount(vfs, "/sd")
except OSError as error:
print("No SD card found:", error)
super().__init__(spi, cs, dc)
self.display = adafruit_ili9341.ILI9341(
self._display_bus, width=320, height=240
)
37 changes: 37 additions & 0 deletions adafruit_featherwing/tft_featherwing_35.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
# SPDX-FileCopyrightText: 2020 Foamyguy for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_featherwing.tft_featherwing_35`
====================================================

Helper for using the `TFT FeatherWing 3.5"`
<https://www.adafruit.com/product/3651>`_.

* Author(s): Melissa LeBlanc-Williams, Foamyguy

Requires:
* adafruit_hx8357
* adafruit_stmpe610
"""

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

from adafruit_hx8357 import HX8357

# pylint: disable-msg=too-few-public-methods
from adafruit_featherwing.tft_featherwing import TFTFeatherWing


class TFTFeatherWing35(TFTFeatherWing):
"""Class representing an `TFT FeatherWing 3.5
<https://www.adafruit.com/product/3651>`_.

"""

def __init__(self, spi=None, cs=None, dc=None):
super().__init__(spi, cs, dc)
self.display = HX8357(self._display_bus, width=480, height=320)
29 changes: 29 additions & 0 deletions examples/featherwing_tft35_simpletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
This example will display a CircuitPython console and
print the coordinates of touchscreen presses.

It will also try to write and then read a file on the
SD Card.
"""
from adafruit_featherwing import tft_featherwing_35

tft_featherwing = tft_featherwing_35.TFTFeatherWing35()

try:
f = open("/sd/tft_featherwing.txt", "w")
f.write("Blinka\nBlackberry Q10 Keyboard")
f.close()

f = open("/sd/tft_featherwing.txt", "r")
print(f.read())
f.close()
except OSError as error:
print("Unable to write to SD Card.")


while True:
if not tft_featherwing.touchscreen.buffer_empty:
print(tft_featherwing.touchscreen.read_data())