Replace the resistive against a capacitive touch?


#1

Hi,

is it possible to replace the resistive 2,8" touch against a capacitive 2,8" Adafruit PiTFT in software just by changing the display type in the webinterface?

I think about the replacement because my resistive TFT from the kit has a bit uneven backlight with blurry areas and bright an dark spots. I have a unused spare capacitive one mentioned above.
Would be great if the replacement would be as easy as expected… :sunglasses:

Regards, Thorsten


#2

It should work without problem, although probably you will need to “tweak” some file to get working the “touch” surface. I think Adafruit have some good tutorial about it. If you do it, please, send feedback and i will include your configuration in the webconf tool.

Regards!


#3

As far as i see there are three modifications/insertions needed for the Adafruit 2.8" capacitive touch TFT:

In config.txt (seems to be already in the webUI configuration):

dtoverlay=pitft28c,rotate=90,speed=32000000,fps=20

In /etc/modules:

ft6x06_ts

A new file /etc/udev/rules.d/95-ft6206.rules with the following content:

SUBSYSTEM=="input", ATTRS{name}=="ft6x06_ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"

A calibration procedure seem not nescessary.
I will try this and i will give you a feedback if it worked, so you maybe can integrate the touch driver…

Regards, Thorsten


#4

Hello,

For the capacitive screen you just have to put this two lines in the /boot/config.txt :

:slight_smile:
Regards


#5

Ah, already solved!
Thanks :smiley:


#6

Works perfect!
Just added the second line to the display config of the PiTFT-capacitive in the webUI and it works like a charm :smiley:


#7

Another question…

As i remember, my resistive display has gone black when the Zynthian was shut down.
That doens’t seem to work with the capacitive touch anymore.

Is the backlight of the resistive TFT controlled by the Zynthian Software?
If yes, by the STMPE GPIO?

The capacitive touch doesn’t have this extra GPIO (because there is no such controller).
But there is an alternative pin that can be used. On RPi 1 this is GPIO18. As far as i see on the RPi2/3 this is GPIO1 which seems to be not connected at the Zynthian wiring.

So would it be possible to change this automatically if the capacitive touch is selected in the webconf display configuration?

Thanks…


#8

Hi @dl9sec!

You can check at the init script “/zynthian/zynthian-ui/zynthian.sh”:

function backlight_on() {
	# Turn On Display Backlight
	echo 0 > /sys/class/backlight/soc:backlight/bl_power
}

function backlight_off() {
	# Turn Off Display Backlight
	echo 1 > /sys/class/backlight/soc:backlight/bl_power
} 

The same method is used in the systemd “backlight.service”.

As you can see, the resistive driver implements a software switch using the “sys” interface.

It would be nice if every display driver implements this “standard” mechanism, but if not, we can create a “backlight control script” with the different cases.

Perhaps you could do some research in this area?

Thanks!


#9

Hmmm, i don’t know exactly where the mapping from GPIO to “bl_power” is made.
Maybe in the device tree. I don’t know, how to find out…


#10

The /sys/class/backlight/soc:backlight/bl_power directory doesn’t exist when i am using the capacitive touch TFT.
What works is the following (if the #18 backlight solder bridge on the TFT is closed):

gpio -g mode 18 pwm
gpio -g pwm 18 0 -> Turns the BL off
gpio -g pwm 18 1023 -> Turns the BL on

or this:

gpio -g mode 18 out
gpio -g write 18 0 -> Turns the BL off
gpio -g write 18 1 -> Turns the BL on

(see https://learn.adafruit.com/adafruit-2-8-pitft-capacitive-touch/backlight-control)

So this could be used in case of the capacitive touch TFT.

Cheers, Thorsten


#11

Hi @dl9sec!

Can you try this?

echo 1 > /sys/class/backlight/*/bl_power
echo 0 > /sys/class/backlight/*/bl_power

For me it works with the 2 different screens that currently i have over my table:

  • PiTFT resistive
  • PiScreen 2

Both uses different drivers, so perhaps it may work with your PiTFT capacitive …

Regards!


#12

Done. As already said, the direcory doesn’t exist. The driver of the capacitive touch doesn’t map a GPIO to the sysfs backlight…


#13

I got it running with full light :slight_smile:

#!/usr/bin/env python3
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)


backlight_pin = 18
pause_time = 0.02

pir_trigger = True
inactive_status = False

delay_timer = 100

GPIO.setup(pir_pin, GPIO.IN)         # activate input
GPIO.setup(backlight_pin, GPIO.OUT)

backlight = GPIO.PWM(backlight_pin, 100)

backlight.start(100)

def fadeIn():
   for i in range(0,101):      # 101 because it stops when it finishes 100
      backlight.ChangeDutyCycle(i)
      sleep(pause_time)

def fadeOut():
   for i in range(100,-1,-1):      # from 100 to zero in steps of -1
      backlight.ChangeDutyCycle(i)
      sleep(pause_time)

fadeIn()

You have to install library before :

sudo apt-get -y install python3-rpi.gpio

And launch the script, tadaa full blacklight !! :slight_smile:

Source : https://forums.adafruit.com/viewtopic.php?f=47&t=57897


#14

Ahah less complicated :

gpio -g mode 18 pwm
gpio -g pwm 18 100
gpio -g pwm 18 1000
gpio -g pwm 18 0

#15

Hello All !

Where can I put this two lines to turn on the backlight ? I mean, in wich script can I put this two command lines to get full backlight at start ?

gpio -g mode 18 pwm
gpio -g pwm 18 1000

Thank You !


#16

Please, take a look to this:

You have a several of options:

  • You could add a customized /etc/rc.local file and add the command there.
  • You could customize the /zynthian/config/zynthian_custom_config.sh
  • Better: Put your lines in a separated script, and customize the /etc/systemd/backlight.service to call your script.
  • etc.

Regards,