Calibrate Touchscreen

Started by Klaus, March 30, 2020, 03:28:15 PM

Previous topic - Next topic

Klaus

Hi folks,

I'm using a T2-OLinuXino-MICRO-e8Gs16M-IND with a LCD-OLINUXINO-4.3"TS rev.B Display and the Armbian_5.92.4_Olinuxino-a20_Debian_buster_next_5.2.21.7z image.

I also installed the Xorg X-server and some X Applications (e.g. xinput-calibrator).

Now I need to to calibrate the touchscreen of the LCD display and therefore start

    $ export DISPLAY=:0
    $ xinput-calibrator

At the end of the routine the application provides some information which should be placed into /etc/X11/xorg.conf.d/99-calibration.conf.

There is already a 98-screen-calibration.conf file in that directory, which is created during each system start by /usr/bin/olinuxino_ts.sh and targeting the same input device.

If I now replace the current content of 98-screen-calibration.conf
Section "InputClass"
 Identifier "calibration"
 MatchProduct "1c25000.rtp"
 Option "TransformationMatrix" "1.08 0.0 -0.04 0.0 1.14 -0.10 0.0 0.0 1.0"
EndSection
with the Information provided by xinput-calibrator
Section "InputClass"
 Identifier "calibration"
 MatchProduct "1c25000.rtp"
 Option "MinX" "65137"
 Option "MaxX" "57"
 Option "MinY" "-161"
 Option "MaxY" "63768"
 Option "SwapXY" "0" # unless it was already set to 1
 Option "InvertX" "0"  # unless it was already set
 Option "InvertY" "0"  # unless it was already set
EndSection
and restart the X-server, I can't see any difference in the calibration.  :(

If I read through the /var/log/Xorg.0.log I find the following entries for the touchscreen:

...
[ 00039.827] (II) config/udev: Adding input device 1c25000.rtp (/dev/input/event4)
[ 00039.827] (**) 1c25000.rtp: Applying InputClass "libinput touchscreen catchall"
[ 00039.827] (**) 1c25000.rtp: Applying InputClass "calibration"
[ 00039.827] (II) Using input driver 'libinput' for '1c25000.rtp'
[ 00039.827] (**) 1c25000.rtp: always reports core events
[ 00039.827] (**) Option "Device" "/dev/input/event4"
[ 00039.827] (**) Option "_source" "server/udev"
[ 00039.833] (II) event4  - 1c25000.rtp: is tagged by udev as: Touchscreen
[ 00039.835] (II) event4  - 1c25000.rtp: device is a touch device
[ 00039.835] (II) event4  - 1c25000.rtp: device removed
[ 00039.864] (**) Option "config_info" "udev:/sys/devices/platform/soc/1c25000.rtp/input/input4/event4"
[ 00039.864] (II) XINPUT: Adding extended input device "1c25000.rtp" (type: TOUCHSCREEN, id 9)
[ 00039.865] (**) Option "AccelerationScheme" "none"
[ 00039.865] (**) 1c25000.rtp: (accel) selected scheme none/0
[ 00039.865] (**) 1c25000.rtp: (accel) acceleration factor: 2.000
[ 00039.865] (**) 1c25000.rtp: (accel) acceleration threshold: 4
[ 00039.871] (II) event4  - 1c25000.rtp: is tagged by udev as: Touchscreen
[ 00039.872] (II) event4  - 1c25000.rtp: device is a touch device
...
which seems that the input device is
- added by/with config/udev
- the calibration is applied
- the device is removed
- the device is added by by/with/as XINPUT but no calibration is applied.  :o

Is there anything I'm missing out of, or how do I get the touchscreen calibrated?

BTW. Is there any information available on how to transform the output of xinput-calibrator into a TransformationMatrix used by the olinuxino_ts script?

kalata23

If the following packages are missing, please install them with:
sudo apt install xrandr xinput-calibrator xinput
Then:

export DISPLAY=:0
You must get LCD resolution:

xrandr | grep current:
The output will look like this:

Screen 0: minimum 320 x 200, current 480 x 272, maximum 8192 x 8192
Of course, the values will be different depending on the lcd type that you are using.

From the output above, you take the screen width and screen height, i.e:

screen_width = 480
screen_height = 272


and write them somewhere

Execute the following command:

xinput_calibrator -v
On the screen you will see some crosses, that you must press. Then you will see output like this:

DEBUG: XInputExtension version is 2.3
DEBUG: Skipping virtual master devices and devices without axis valuators.
DEBUG: Skipping device 'Virtual core XTEST pointer' id=4, does not report Absolute events.
DEBUG: Selected device: 1c25000.rtp
DEBUG: Not usbtouchscreen calibrator: Not a usbtouchscreen device
DEBUG: Not evdev calibrator: Evdev: invalid "Evdev Axis Calibration" property format
Calibrating standard Xorg driver "1c25000.rtp"
        current calibration values: min_x=0, max_x=65535 and min_y=0, max_y=65535
        If these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).
DEBUG: Found that '1c25000.rtp' is a sysfs name.
DEBUG: Adding click 0 (X=67, Y=48)
DEBUG: Adding click 1 (X=408, Y=46)
DEBUG: Adding click 2 (X=76, Y=227)
DEBUG: Adding click 3 (X=413, Y=227)
Теб те интересува това :
DEBUG: Adding click 0 (X=67, Y=48)
DEBUG: Adding click 1 (X=408, Y=46)
DEBUG: Adding click 2 (X=76, Y=227)
DEBUG: Adding click 3 (X=413, Y=227)

* Note: All the values in this post are just example, in your case they will be different.

Then you calculate the transformation matrix:
a = (screen_width * 6 / 8) / (click_3_X - click_0_X)
c = ((screen_width / 8) - (a * click_0_X)) / screen_width
e = (screen_height * 6 / 8) / (click_3_Y - click_0_Y)
f = ((screen_height / 8) - (e * click_0_Y)) / screen_height

Then enter:
xinputAnd find  out your TS device name, then copy it, you will need it in the next step.

Execute:
xinput set-prop "YOUR_DEVICE" "libinput Calibration Matrix" "libinput Calibration Matrix" a, 0.0, c, 0.0, e, f, 0.0, 0.0, 1.0

where:
a,c,e,f - you must replace them with values from the calculations above
"YOUR_DEVICE" - this is the name of the TS device that you got from xinput command.

If you are satisfied, you can save the values of the transformation matrix into that .conf file, so no need to execute the command above on each boot.

tropek

Quote from: kalata23 on April 01, 2020, 08:57:00 AMIf you are satisfied, you can save the values of the transformation matrix into that .conf file, so no need to execute the command above on each boot.
Hello

Which .conf file is it exactly ?
The values a, c, e and f written in /etc/X11/xorg.conf.d/98-screen-calibration.conf are taken into account after a reconnection to XFCE.
But on a reboot they are replaced by "default" values (I don't know where they come from).

Merci
DeepL translation

kalata23

#3
Quote from: tropek on March 23, 2021, 11:57:42 AM
Quote from: kalata23 on April 01, 2020, 08:57:00 AMIf you are satisfied, you can save the values of the transformation matrix into that .conf file, so no need to execute the command above on each boot.
Hello

Which .conf file is it exactly ?
The values a, c, e and f written in /etc/X11/xorg.conf.d/98-screen-calibration.conf are taken into account after a reconnection to XFCE.
But on a reboot they are replaced by "default" values (I don't know where they come from).

Merci
The calibration values are written in /etc/X11/xorg.conf.d/98-screen-calibration.conf However olinuxino-ts.service executes /usr/lib/olinuxino/olinuxino-ts on every boot. This overrides the .conf file after reboot, that's why I can suggest you to change default values in /usr/lib/olinuxino/olinuxino-ts

tropek

DeepL translation

tropek

DeepL translation

tropek

#6
Hello
I forgot to mention that I use an A10 with an updated buster, because I didn't get an answer on the A10 forum ...
In this configuration there is no olinuxino_ts.sh file, nor anything like it.

In which directory should something be found ?
DeepL translation

LubOlimex

The instructions kalata23 apply only for A10 Olimage images that are downloaded from here:

http://images.olimex.com/release/a10/

What image exactly are you using and where did you download it from (share link of place where you got it)?

Also if you use A10 board, please post in the A10 sub-forum, not in the A20 sub-forum, thanks.
Technical support and documentation manager at Olimex

tropek

My image comes from the page you indicate
A10-OLinuXino-buster-base-20210318-122357.img.7z
and the card A10 works.

I posted here -> https://www.olimex.com/forum/index.php?topic=8136.0
and Olimex advises me to continue here !

Thanks
DeepL translation

alex_u-94

I have done everything possible based on the official documents and instructions here... I have calculated the calibration matrix, and when I apply it under the Olimex user in the CLI using xinput set-prop, my touchscreen works perfectly. I made changes to /usr/lib/olinuxino/olinuxino-ts, I have the correct /etc/X11/xorg.conf.d/98-screen-calibration.conf after reboot. But these settings don't work. The touchscreen still have the wrong calibration. To be sure, I performed a new deployment with the OS on the SD card and made changes to /usr/lib/olinuxino/olinuxino-ts from the beginning. The results are exactly the same... correct data in /etc/X11/xorg.conf.d/98-screen-calibration.conf and incorrect calibration (((( To be honest, I do not know what to do.

Hardware: SODIMM 204 PIN EVALUATION BOARD WITH A20-SOM204-1GS16ME16G-MC
LCD: LCD-OLinuXino-7RTS
Software: A20-OLinuXino-bullseye-base-20220413-094751.img
jumper in correct position

LubOlimex

Technical support and documentation manager at Olimex

kalata23

#11
Quote from: alex_u-94 on June 30, 2022, 05:11:40 PMI have done everything possible based on the official documents and instructions here... I have calculated the calibration matrix, and when I apply it under the Olimex user in the CLI using xinput set-prop, my touchscreen works perfectly. I made changes to /usr/lib/olinuxino/olinuxino-ts, I have the correct /etc/X11/xorg.conf.d/98-screen-calibration.conf after reboot. But these settings don't work. The touchscreen still have the wrong calibration. To be sure, I performed a new deployment with the OS on the SD card and made changes to /usr/lib/olinuxino/olinuxino-ts from the beginning. The results are exactly the same... correct data in /etc/X11/xorg.conf.d/98-screen-calibration.conf and incorrect calibration (((( To be honest, I do not know what to do.

Hardware: SODIMM 204 PIN EVALUATION BOARD WITH A20-SOM204-1GS16ME16G-MC
LCD: LCD-OLinuXino-7RTS
Software: A20-OLinuXino-bullseye-base-20220413-094751.img
jumper in correct position

Please, copy the content of /usr/lib/olinuxino/olinuxino-ts here.

PS: Please also markup the line(s) that you have changed.

alex_u-94

All steps which I did.

Preparation
Fresh new deployment of OS on SD
$ sudo olinuxino-overlay
    1. Enabled: som204-lcd-olinuxino-7.dtbo        LCD-OLinuXino-7 800x480 panel without TS
    2. Enabled: som-i2c2-ar1021.dtbo              Microchip AR1021 RTS controller on I2C2 bus
    3. Disabled: som204-lcd-olinuxino.dtbo          LCD-OLinuXino PnP panel
$ sudo apt install xrandr (no longer available for installation, performed to demonstrate the result)
 Reading package lists... Done
 Building dependency tree... Done
 Reading state information... Done
 Package xrandr is not available, but is referred to by another package.
 This may mean that the package is missing, has been obsoleted, or
 is only available from another source
 However the following packages replace it:
  x11-xserver-utils

 E: Package 'xrandr' has no installation candidate
$ sudo apt install x11-xserver-utils (performed to demonstrate the result)
 Reading package lists... Done
 Reading state information... Done
 xinput-calibrator is already the newest version (0.7.5+git20140201-1+b2).
 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ sudo apt install xinput
 Reading package lists... Done
 Building dependency tree... Done
 Reading state information... Done
 The following NEW packages will be installed:
   xinput
 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
 Need to get 50.4 kB of archives.
 After this operation, 84.0 kB of additional disk space will be used.
 Get:1 http://httpredir.debian.org/debian bullseye/main armhf xinput armhf 1.6.3-1 [50.4 kB]
 Fetched 50.4 kB in 0s (117 kB/s)
 Selecting previously unselected package xinput.
 (Reading database ... 126380 files and directories currently installed.)
 Preparing to unpack .../xinput_1.6.3-1_armhf.deb ...
 Unpacking xinput (1.6.3-1) ...
 Setting up xinput (1.6.3-1) ...
 Processing triggers for man-db (2.9.4-2) ...
Сheckout
$ cat /etc/X11/xorg.conf.d/98-screen-calibration.conf
 Section "InputClass"
         Identifier      "calibration"
         MatchProduct    "1c25000.rtp"
         Option          "TransformationMatrix" "1.06 0.0 -0.03 0.0 1.11 -0.08 0.0 0.0 1.0"
 EndSection
Visual test (touch screen works, calibration has a significant deviation)


Calibration
$ export DISPLAY=:0
$ xinput_calibrator -v
DEBUG: XInputExtension version is 2.3
DEBUG: Skipping virtual master devices and devices without axis valuators.
DEBUG: Skipping device 'Virtual core XTEST pointer' id=4, does not report Absolute events.
DEBUG: Skipping device 'PixArt Microsoft USB Optical Mouse' id=6, does not report Absolute events.
DEBUG: Skipping device 'Microsoft Wired Keyboard 600 Consumer Control' id=8, does not report Absolute events.
DEBUG: Skipping device 'sunxi-ir' id=10, does not report Absolute events.
DEBUG: Selected device: ar1021 I2C Touchscreen
DEBUG: Not usbtouchscreen calibrator: Not a usbtouchscreen device
DEBUG: Not evdev calibrator: Evdev: invalid "Evdev Axis Calibration" property format
Calibrating standard Xorg driver "ar1021 I2C Touchscreen"
current calibration values: min_x=0, max_x=65535 and min_y=0, max_y=65535
If these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).
DEBUG: Found that 'ar1021 I2C Touchscreen' is a sysfs name.
DEBUG: Adding click 0 (X=106, Y=87)
DEBUG: Adding click 1 (X=685, Y=88)
DEBUG: Adding click 2 (X=106, Y=409)
DEBUG: Adding click 3 (X=687, Y=413)
--> Making the calibration permanent <--
DEBUG: Found that 'ar1021 I2C Touchscreen' is a sysfs name.
  copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)
Section "InputClass"
Identifier "calibration"
MatchProduct "ar1021 I2C Touchscreen"
Option "MinX" "765"
Option "MaxX" "64115"
Option "MinY" "4585"
Option "MaxY" "63476"
Option "SwapXY" "0" # unless it was already set to 1
Option "InvertX" "0"  # unless it was already set
Option "InvertY" "0"  # unless it was already set
EndSection

Preliminary verification of the calculations
$ xinput_calibratot --list
Device "ar1021 I2C Touchscreen" id=12
$ xinput set-prop 12 'Coordinate Transformation Matrix' 1.04 0.0 -0.02 0.0 1.12 -0.08 0.0 0.0 1.0

Visual test


Making changes to olinuxino-ts

$ sudo nano /usr/lib/olinuxino/olinuxino-ts

Old parameters for olimex lcd-olinuxino-7


New parameters for olimex lcd-olinuxino-7


Rebooting and checking the results

$ cat /etc/X11/xorg.conf.d/98-screen-calibration.conf (The content of the file corresponds to the specified parameters)
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "1c25000.rtp"
        Option          "TransformationMatrix" "1.04 0.0 -0.02 0.0 1.12 -0.08 0.0 0.0 1.0"
EndSection

Visual test (touch screen works, calibration has a significant deviation)

kalata23

Thank you for the detailed step list. However, I think you have edited the wrong line in  olinuxino-ts  script.

From the images, that you applied here, I see that you edit olimex,lcd-olinuxino-7 line in the following section:

else
    case $LCD in
        "olimex,lcd-olinuxino-4.3")
                MATRIX="1.08 0.0 -0.04 0.0 1.14 -0.10 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-7")
                MATRIX="1.06 0.0 -0.03 0.0 1.11 -0.08 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-10")
                MATRIX="1.04 0.0 -0.03 0.0 1.09 -0.07 0.0 0.0 1.0"
                ;;
        *)
                # The LCD is not supported by this script
                exit 0;
    esac
   
    PRODUCT="1c25000.rtp"   
   
fi
But this sections is related to CTS displays, not RTS. The correct sections, where you have to change the values for 7" LCD is this:

if [[ $overlays == *"micro-i2c2-ar1021"* ]];
then
    case $LCD in
        "olimex,lcd-olinuxino-4.3")
                MATRIX="1.09 0.0 -0.04 0.0 1.17 -0.09 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-7")
                MATRIX="1.05 0.0 -0.03 0.0 1.13 -0.08 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-10")
                MATRIX="1.04 0.0 -0.03 0.0 1.09 -0.07 0.0 0.0 1.0"
                ;;
        *)
                # The LCD is not supported by this script
                exit 0;
    esac   
   
    PRODUCT="ar1021 I2C Touchscreen"

Change the values in the correct section, and tell us if this solved your problem.

alex_u-94

#14
A few problems...
Firstly, I've already done this and it doesn't work at all because the olimex script to generate "98-screen-calibration.conf" uses the section I edited. If you check my post, I have inserted the contents from the source file "98-screen-calibration.conf", which was generated using an unmodified script. You can also check in the script that different sections for a 7-inch LCD display have different values.
The second problem is "98-screen-calibration.conf", which was generated using a modified script, contains the values that I inserted there....

Modified script
$ cat /usr/lib/olinuxino/olinuxino-ts
#!/bin/bash

# Check is LCD is enabled in the device tree
LCD=$(grep -r "lcd-olinuxino-[147]" /proc/device-tree -a -h | tr -d '\0')
[[ -z $LCD ]] && exit 0

overlays=$(cat /boot/uEnv.txt)

# Select transformation matrix
if [[ $overlays == *"micro-i2c2-ar1021"* ]];
then
    case $LCD in
        "olimex,lcd-olinuxino-4.3")
                MATRIX="1.09 0.0 -0.04 0.0 1.17 -0.09 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-7")
                MATRIX="1.05 0.0 -0.03 0.0 1.13 -0.08 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-10")
                MATRIX="1.04 0.0 -0.03 0.0 1.09 -0.07 0.0 0.0 1.0"
                ;;
        *)
                # The LCD is not supported by this script
                exit 0;
    esac

    PRODUCT="ar1021 I2C Touchscreen"

else
    case $LCD in
        "olimex,lcd-olinuxino-4.3")
                MATRIX="1.08 0.0 -0.04 0.0 1.14 -0.10 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-7")
                MATRIX="1.04 0.0 -0.02 0.0 1.12 -0.08 0.0 0.0 1.0"
                ;;
        "olimex,lcd-olinuxino-10")
                MATRIX="1.04 0.0 -0.03 0.0 1.09 -0.07 0.0 0.0 1.0"
                ;;
        *)
                # The LCD is not supported by this script
                exit 0;
    esac

    PRODUCT="1c25000.rtp"

fi

# Generate configuration file
mkdir -p /etc/X11/xorg.conf.d
tee > /etc/X11/xorg.conf.d/98-screen-calibration.conf << __EOF__
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "$PRODUCT"
        Option          "TransformationMatrix" "$MATRIX"
EndSection
__EOF__

# педалщина
LCD=$(grep -r "lcd-olinuxino-[147]" /proc/device-tree -a -h | tr -d '\0')
[[ -z $LCD ]] && exit 0

overlays=$(cat /boot/uEnv.txt)

# Select transformation matrix
if [[ $overlays == *"-gt911inv"* ]];
then
        /usr/bin/memtool mw -l 0x1C0C010  0x80000000 || :
        /usr/bin/memtool mw -l 0x1C0C044  0xF0000006 || :
fi

Generated "98-screen-calibration.conf"
$ cat /etc/X11/xorg.conf.d/98-screen-calibration.conf
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "1c25000.rtp"
        Option          "TransformationMatrix" "1.04 0.0 -0.02 0.0 1.12 -0.08 0.0 0.0 1.0"
EndSection

If you compare the script and the configuration file, you will find that the transformation matrix is the same.

Do I understand correctly that {MatchProduct "1c25000.rtp"} section should have a different value in the configuration file (98-screen-calibration.conf)?

Checks from the script
Display:

$ grep -r "lcd-olinuxino-[147]" /proc/device-tree -a -h | tr -d '\0'
olimex,lcd-olinuxino-7

Touch:
$ cat /boot/uEnv.txt
#
# Auto-generated on: 2022-04-13 10:12:41.610325
# Generated UUID: 30010994-cd0e-4557-be6d-fb22555be453
#
# Put u-boot environment variables here. Before boot, boot.scr will use these variables:
#
# boot_config - Explicitly specify the boot configuration
# fdtoverlays - List of overlay files
# load_legacy - Don't load FIT image,
# optargs - Optional arguments passed to the kernel

fdtoverlays=/usr/lib/olinuxino-overlays/sun7i-a20/som204-lcd-olinuxino-7.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/som-i2c2-ar1021.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/spi1-spidev.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/spi2-spidev.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-can.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-i2c2.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-spi1.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-spi2.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-uart3.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-uart4.dtbo /usr/lib/olinuxino-overlays/sun7i-a20/sun7i-a20-uart7.dtbo

The overlay does not include micro-i2c2-ar1021, so the script uses the second section....