Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

2.8" PiTFT Capacitive Touch Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: 2.8" PiTFT Capacitive Touch Issue

by DannyBGoode on Thu Mar 26, 2020 1:59 pm

That project just refers to the same instructions I've tried (and mentioned that don't work). I'm on Stretch, and they don't work. I posted what messages I'm seeing a few posts ago.

I'm far from a Linux expert, so I don't know how to fix it...

I also looked at your recommendation for using circuit python, and I don't see that it has the ability to draw graphics, so it's not much use to me.

Danny

DannyBGoode
 
Posts: 25
Joined: Wed Nov 06, 2019 11:58 am

Re: 2.8" PiTFT Capacitive Touch Issue

by MakerMelissa on Thu Mar 26, 2020 2:05 pm

CircuitPython can draw graphics. You'll want to use the Adafruit_CircuitPython_RGB_Display library in conjunction with Pillow for doing the graphics drawing. More info https://learn.adafruit.com/adafruit-2-d ... thon-usage and https://pillow.readthedocs.io/en/stable/.

Melissa

MakerMelissa
 
Posts: 174
Joined: Wed Jun 05, 2013 2:10 am

Re: 2.8" PiTFT Capacitive Touch Issue

by DannyBGoode on Mon Aug 03, 2020 1:30 pm

I figured I'd update this. I do have the touch working with PyGame, kinda. I'm still using PyGame for the display portion so I didn't have to re-write all my code. But I was able to use the CircuitPython library to talk to the device to get the touch positions. For those interested, I did have touch and display all working just using CircuitPython (Pillow), so that's a viable option if you're just starting from scratch. I really didn't want to re-write my entire application, so I kept PyGame.

To make this work, once you install the adafruit drivers, you have to go in and blacklist one (the touch). To do this, edit '/etc/modprobe.d/raspi-blacklist.conf' and add this to the file:

Code: Select all | TOGGLE FULL SIZE
blacklist edt_ft5x06


Be sure to reboot after making the change to make it have an effect.

You can check using the command 'lsmod'. Before this, you will see the edt_ft5x06 in the list and won't afterwards. And if you do an 'i2cdetect -y 1' command before you'll see that address 38 has 'uu' denoting it's reserved/locked. Afterward, it shows the address meaning it's available.

Here's my entire test program that is working for me on the current Raspbian image (or whatever they're calling it now):

Code: Select all | TOGGLE FULL SIZE
import digitalio
import board
from time import sleep
import busio
import adafruit_focaltouch
import pygame
from pygame.locals import *
import os

#Colors
WHITE = (255,255,255)
GREY = (128,128,128)
BLACK = (0,0,0)
RED = (255,0,0)

# initialize the LCD
os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
testfont = pygame.font.SysFont('freesansbold.ttf', 35)

# set up the touch device
i2c=board.I2C()
ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False)

# initialize the touch position variable
pos = [0,0]

# set up a test 'button' in the middle of the screen
button10 = pygame.Rect(80,70,160,100)

# loop continuously - use ctrl-C to exit
while True:
   # get the touch position
   if ft.touched:
      # Clear the display - color it white
      print(ft.touches)
      ts = ft.touches
      point = ts[0]
      # perform transformation to make coordinates match
      pos[1] = 240 - point["x"]
      pos[0] = point["y"]
      print("x:" + str(pos[0]) + ", y:" + str(pos[1]))
      if (button10.collidepoint(pos)):
                   print ('Test button pressed!!')

   # clear the display
   lcd.fill(WHITE)

   # display the test button in the middle of the screen
   pygame.draw.rect(lcd, GREY, button10, 0)
   text = testfont.render('PRESS ME', True, BLACK)
   textRect = text.get_rect()
   textRect.center = (160,120)
   lcd.blit(text, textRect)

   # display the red dot - where last pressed or top left to start
   pygame.draw.circle(lcd, RED, pos, 10, 0)
   pygame.display.update()

   sleep(0.3)


A final note: The CircuitPython stuff requires Python3, so you'll have to install the Python3 versions of PyGame, etc. to make this work (at least that's what I did). Also, you'll have to run my test program with admin credentials (sudo python3 ...) or it won't work.

Hopefully this will help someone else in the future trying to use this touch screen...

Danny

DannyBGoode
 
Posts: 25
Joined: Wed Nov 06, 2019 11:58 am

Please be positive and constructive with your questions and comments.