Skip to content
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

3.5" Cap Touch has extra touches #4

Open
tyeth opened this issue Mar 9, 2024 · 0 comments
Open

3.5" Cap Touch has extra touches #4

tyeth opened this issue Mar 9, 2024 · 0 comments

Comments

@tyeth
Copy link

tyeth commented Mar 9, 2024

Not reliably 100% of the time, but reliable enough if you hold your finger down.
I've got a Feather RP2040 (USB Host but any would do) connected to the 3.5" capacitive touch featherwing with an SD card in place. No USB device in the USB A port.

This code loads bmp files from SD and local flash. I've nicked a load of assets from learn repo for testing.

Tapping should change image, but it skips one or so randomly.

Hold your finger down instead of tapping and watch the serial, sometimes (often) it has both finger #0 and finger #1 (i've seen 0-2) but usually at very different coordinates. I've taken off the protective film and it's still happening, it's clean/new so hopefully easily reproduced. Running v9-rc0

image

code:

# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
This test will initialize the display using displayio and display
a bitmap image. The image advances when the touch screen is touched.

Pinouts are for the 3.5" TFT FeatherWing V2 ## Now adapted for capacitive version instead
"""
import os
import board
import displayio
import adafruit_hx8357
import adafruit_ft5336
import storage
import adafruit_sdcard
import digitalio

# import adafruit_tsc2007
# Release any resources currently in use for the displays
displayio.release_displays()

# Use Hardware SPI
spi = board.SPI()

sd_cs = board.D5
tft_cs = board.D9
tft_dc = board.D10

display_width = 480
display_height = 320

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs )#, baudrate=60_000_000)
display = adafruit_hx8357.HX8357(display_bus, width=display_width, height=display_height)

i2c = board.STEMMA_I2C()

irq_dio = None
# tsc = adafruit_tsc2007.TSC2007(i2c, irq=irq_dio)
touch = adafruit_ft5336.Adafruit_FT5336(i2c)

groups = []
images = []
def list_files(path='/'):
    for filename in os.listdir(path):
        if filename.lower().endswith('.bmp') and not filename.startswith('.'):
            images.append((path if path.endswith('/') else path+"/" )+filename)

def os_Exists(path):
    try: 
        return os.stat(path) != None; 
    except: 
        return False

#attempt to mount sd card

# try:
def mountsd():
    print("Attempting to mount SD card")
    sdcs = digitalio.DigitalInOut(sd_cs)
    sd = adafruit_sdcard.SDCard(spi, sdcs)
    vfs = storage.VfsFat(sd)
    storage.mount(vfs, "/sd")
# except:
#     print("SD Card not found")
mountsd()

if os_Exists('/sd'):
    print("SD Directory exists")
    list_files('/sd')

# mount usb

list_files('/')
print(images)

for i in range(len(images)):
    splash = displayio.Group()
    bitmap = displayio.OnDiskBitmap(images[i])
    tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
    splash.append(tile_grid)
    groups.append(splash)

index = 0
touch_state = False

display.root_group = groups[index]
print("displaying image %s" % images[index])

point={"x":0,"y":0,"finger":0}
while True:
    if touch.touched and not touch_state:
        try:
            for i,tpoint in enumerate(touch.points):
                print(tpoint)
                point["x"] = tpoint[0]
                point["y"] = tpoint[1]
                point["finger"] = tpoint[2]
                print("Touchpoint #%d: (%d, %d, %d)" % (i, point["x"], point["y"], point["finger"]))
                # left side of the screen
                if point["y"] < 2000:
                    index = (index - 1) % len(images)
                    display.root_group = groups[index]
                # right side of the screen
                else:
                    index = (index + 1) % len(images)
                    display.root_group = groups[index]
                print("displaying image %s" % images[index])
        except RuntimeError:
            pass
        touch_state = True
    if not touch.touched and touch_state:
        touch_state = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant