Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

pitft 3.5 resistive touch screen calibration
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

pitft 3.5 resistive touch screen calibration

by keithspg on Thu May 07, 2020 3:57 pm

I have the screen connected and have x displayed on it fine. Looking good! Now, though, I cannot for the life of me get X to calibrate the digitizer. I can see that it is working as I can cause things to happen on my display, they just do not happen where I think they should.
I am running the Matchbox Window Manager and Midori in full screen and it looks great! I can even get the OS Keyboard to show up when I randomly click.

What I have done is to follow these instructions:
https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi/touchscreen-install-and-calibrate
I built xtcal and when I run it, I get the red cross hairs and get a Transformation Matrix (I have teh screen upside down by using this config.txt line:
Code: Select all | TOGGLE FULL SIZE
 dtoverlay=pitft35-resistive,rotate=270,speed=32000000,fps=20

I run the xtcal and get this:
Code: Select all | TOGGLE FULL SIZE
# DISPLAY=:0.0 ./xtcal -geometry 320x480
fullscreen not supported
Calibrate by issuing the command below, substituting <device name> with the name found using `xinput list`.
xinput set-prop <device name> 'Coordinate Transformation Matrix' 0.041649 -2.048003 1.449165 0.429916 0.007468 -0.104660 0 0 1

I created the /etc/X11/xorg.conf.d/20-calibration.conf file and pasted these numbers in to get this:

Code: Select all | TOGGLE FULL SIZE
# cat /etc/X11/xorg.conf.d/20-calibration.conf
Section "InputClass"
    Identifier "STMPE Touchscreen Calibration"
    MatchProduct "stmpe"
    MatchDevicePath "/dev/input/event*"
    Driver "libinput"
    Option "TransformationMatrix" "0.041649 -2.048003 1.449165 0.429916 0.007468 -0.104660 0 0 1"
EndSection


I've even tried the xinput calibration and get a different calibration screen/target as well as numbers and still no joy.
I need this to work for X11. I do not need a console...

Thanks for any help.

Regards

keithspg
 
Posts: 6
Joined: Tue Jun 23, 2015 8:05 pm

Re: pitft 3.5 resistive touch screen calibration

by keithspg on Thu May 07, 2020 7:40 pm

Spent a bunch of time with this today and still no joy. What I can see is the cursor is reversed. Up goes left and down goes right, right goes up and left goes down. I have tried all the xinput configuration stuff and it just doe snot seem to do anything. If I try to change them in xinput, they change, but the cursor behavior never changes:
Code: Select all | TOGGLE FULL SIZE
~# DISPLAY=:0.0 xinput list-props stmpe-ts
Device 'stmpe-ts':
        Device Enabled (113):   1
        Coordinate Transformation Matrix (114): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix (245):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix Default (246):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (247):     1, 0
        libinput Send Events Mode Enabled (248):        0, 0
        libinput Send Events Mode Enabled Default (249):        0, 0
        Device Node (250):      "/dev/input/event2"
        Device Product ID (251):        0, 0
root@gretarune(rw):~# DISPLAY=:0.0 xinput set-prop stmpe-ts "libinput Calibration Matrix" -1 0 1 0 -1 1 0 0 1
root@gretarune(rw):~# DISPLAY=:0.0 xinput list-props stmpe-ts
Device 'stmpe-ts':
        Device Enabled (113):   1
        Coordinate Transformation Matrix (114): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix (245):      -1.000000, 0.000000, 1.000000, 0.000000, -1.000000, 1.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix Default (246):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (247):     1, 0
        libinput Send Events Mode Enabled (248):        0, 0
        libinput Send Events Mode Enabled Default (249):        0, 0
        Device Node (250):      "/dev/input/event2"
        Device Product ID (251):        0, 0
# DISPLAY=:0.0 xinput set-prop stmpe-ts "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
# DISPLAY=:0.0 xinput list-props stmpe-ts
Device 'stmpe-ts':
        Device Enabled (113):   1
        Coordinate Transformation Matrix (114): -1.000000, 0.000000, 1.000000, 0.000000, -1.000000, 1.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix (245):      -1.000000, 0.000000, 1.000000, 0.000000, -1.000000, 1.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix Default (246):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (247):     1, 0
        libinput Send Events Mode Enabled (248):        0, 0
        libinput Send Events Mode Enabled Default (249):        0, 0
        Device Node (250):      "/dev/input/event2"
        Device Product ID (251):        0, 0


Any ideas?

keithspg
 
Posts: 6
Joined: Tue Jun 23, 2015 8:05 pm

Re: pitft 3.5 resistive touch screen calibration

by keithspg on Thu May 07, 2020 11:36 pm

I finally got it. in case anyone searches and comes upon this thread.

The key is you need to reset the parameters before the calibration.

I used these 2 lines in /boot/config.txt to get the display loaded and working on /dev/fb1
Code: Select all | TOGGLE FULL SIZE
# TFT resistive Display
dtparam=spi=on
dtoverlay=pitft35-resistive,rotate=270,speed=32000000,fps=20

you need to tell tell Xorg that you are on fb1 with this in the 99-display.conf:
Code: Select all | TOGGLE FULL SIZE
Section "Device"
        Identifier "RpiFB"
        Driver "fbdev"
        [b]Option "fbdev" "/dev/fb1"[/b]
EndSection

To calibrate the touchscreen for X11 you need to install the packages required and build the xtcal program as shown in teh howto detailed installation. Once you have it, you need to reset the display:
Code: Select all | TOGGLE FULL SIZE
DISPLAY=:0.0 xinput set-prop "stmpe-ts" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1

then you can run the calibration routine. I have the binary in my root directory:
Code: Select all | TOGGLE FULL SIZE
DISPLAY=:0.0 ./xtcal -geometry 480x320

mine responded like this after I touched the 4 targets:
Code: Select all | TOGGLE FULL SIZE
# DISPLAY=:0.0 ./xtcal -geometry 480x320
fullscreen not supported
Calibrate by issuing the command below, substituting <device name> with the name found using `xinput list`.
xinput set-prop <device name> 'Coordinate Transformation Matrix' 0.020680 -1.101354 1.029753 1.052622 -0.043088 -0.018329 0 0 1

I then created the 20-calibration.conf file and set it up like this:
Code: Select all | TOGGLE FULL SIZE
Section "InputClass"
   Identifier "STMPE Touchscreen Calibration"
   MatchProduct "stmpe"
   MatchDevicePath "/dev/input/event*"
   Driver "libinput"
   Option "TransformationMatrix" "-0.003039 -1.098337 1.025817 1.094867 -0.003317 -0.050412 0 0 1"
EndSection

when I restarted X the touchscreen was calibrated. The key was I needed to reset the calibration each time I tried a new way to calibrate it. xorg-xinput does nothing, at least with this driver.

keithspg
 
Posts: 6
Joined: Tue Jun 23, 2015 8:05 pm

Re: pitft 3.5 resistive touch screen calibration

by keithspg on Fri May 08, 2020 11:48 am

In case anyone wants a PKGBUILD for the xtcal it is here:
https://github.com/gearhead/xtcal

keithspg
 
Posts: 6
Joined: Tue Jun 23, 2015 8:05 pm

Re: pitft 3.5 resistive touch screen calibration

by keithspg on Sun May 17, 2020 7:44 pm

Just another post on calibration of the touchscreen. xtcal does a nice job, but this perl script does as well:
http://support.fccps.cz/download/adv/fr ... brator.htm

The thing is I am running xorg 1.20.8 and the commas that the script puts in the matrix do not work. To get the script on this page to work to calibrate your touch screen, just reomve the commas.
Code: Select all | TOGGLE FULL SIZE
 # DISPLAY=:0.0 ./matrix.pl
Using 'xinput_calibrator --list' to find some pointer devices:
1.) stmpe-ts
Using device "stmpe-ts"
xrandr: Failed to get size of gamma for output default
Screen resolution: 480 x 320
We'd better cancel previous calibration, by inserting a unity matrix.
Launching the xinput_calibrator.
INFO: width=480, height=320
Click 0 : X=76, Y=263
Click 1 : X=80, Y=45
Click 2 : X=399, Y=264
Click 3 : X=400, Y=48
Will try to apply the matrix immediately. This is still just a runtime setting.
Matrix update cmd:
xinput set-prop "stmpe-ts" "Coordinate Transformation Matrix" 0.00849405180427814, -1.10592554491702, 1.03145777984362, 1.11965367546586, 0.0104477792422941, -0.0619717160235558, 0, 0, 1
By now, the input device might as well be calibrated.
To check, try:
xinput list-props "stmpe-ts"

To make the changes permanent, create or edit a file called
    /etc/X11/xorg.conf.d/99-calibration.conf
or in some distro's (debian based) called
    /usr/share/X11/xorg.conf.d/99-calibration.conf
and make it look like this (feel free to copy+paste):

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "stmpe-ts"
        Option          "TransformationMatrix" "0.00849405180427814, -1.10592554491702, 1.03145777984362, 1.11965367546586, 0.0104477792422941, -0.0619717160235558, 0, 0, 1"
EndSection


Just make change the one line to remove the commas and it works with xorg 1.20:
Code: Select all | TOGGLE FULL SIZE
 Option          "TransformationMatrix" "0.00849405180427814 -1.10592554491702 1.03145777984362 1.11965367546586 0.0104477792422941 -0.0619717160235558 0 0 1"


Gearhead

keithspg
 
Posts: 6
Joined: Tue Jun 23, 2015 8:05 pm

Please be positive and constructive with your questions and comments.