Skip to content

Instantly share code, notes, and snippets.

@KurtJacobson
Last active February 27, 2024 22:06
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KurtJacobson/37288a0300a9c1b3e859c8dcff403300 to your computer and use it in GitHub Desktop.
Save KurtJacobson/37288a0300a9c1b3e859c8dcff403300 to your computer and use it in GitHub Desktop.
Touchscreen calibration procedue for Debian9 (stretch)

Touchscreen Calibration in Debian9

Unfortunately xinput-calibrator does not work at all for calibrating a touchscreen in Debian9. This is apparently because X server now uses libinput to handle input devices instead of evdev. I spent huge amount of trying to fiddling with xinput-calibrator and 99-calibration.conf files until I finely found this issue on GitHub that gave me some hints as how to proceed. This is mostly for my own reference, but I hope it might also help others in the same situation.

Install xinput

This not not seem to be installed by defaults on Debian9

$ sudo apt-get install xinput

Determine the screen size

You probably already know this, but if you have multiple screens they might be see as one big screen. So to determine the total size run

$ xrandr

This will print out a good bit of information, but what you are interested in is the current vales in the first line, which will look something like this:

Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192

Determine the name of the touch device

Next step it to find the touch device's name

$ xinput list

Look for the touch device in the Virtual core pointer section. In my case the device name is Elo TouchSystems 2700 IntelliTouch(r).

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Elo TouchSystems 2700 IntelliTouch(r)     id=12   [slave  pointer  (2)]
⎜   ↳ 2.4G Mouse                                id=10   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
...

Now run

$ xinput list-props <device name>

were <device-name> is the name you determined in the last step.

Confirm that the list of properties includes near the top a property called Coordinate Transformation Matrix. If it does not, you probably have the wrong device name.

Set the Coordinate Transformation Matrix

The screen is calibrated using a Coordinate Transformation Matrix, which defaults to the identity matrix.

[1 0 0]
[0 1 0]
[0 0 1]

for convenient entry, the matrix is flatted into a single line like this

1 0 0 0 1 0 0 0 1

were the valuse seem to map like this

[hscale] [vskew] [hoffset] [hskew] [vscale] [voffset] 0 0 1

Here is a very nice interactive tool for visualizing the effect of the various values: https://codepen.io/GottZ/full/d73f2f844b52b91b7457febce2d1b18c/

Apply the calibration matrix by saying

xinput set-prop '<device name>' 'Coordinate Transformation Matrix' 1.04 0 -0.02 0 1.04 -0.02 0 0 1

I just experimented with the values until I had the scree calibrated, it only took a few iterations to get so the pointer was exactly under were I touched.

References: https://wiki.archlinux.org/index.php/Calibrating_Touchscreen https://wiki.ubuntu.com/X/InputCoordinateTransformation

@Rowbotronics
Copy link

This was super helpful for me, thanks for posting it!

@0E800
Copy link

0E800 commented Apr 11, 2019

Thank you for leaving breadcrumbs. Excellent material.

@zhenisotarbay
Copy link

What if I have done rotation first, shall I do the same commands?

@pquiring
Copy link

Thanks for this post!
For my Elo 2218 the x=22 and y=38 and I use a for loop since the device id seems to change sometimes (if I have a keyboard plugged in).

for i in {4..15}
do
  xinput set-prop $i "libinput Calibration Matrix" 1.22 0.0 -0.11 0.0 1.38 -0.19 0.0 0.0 1.0
done

@cabassi
Copy link

cabassi commented Sep 18, 2019

Hi Kurt,
thanks for posting this! As it appears this is not a well know issue, and I did 2 days of researching and trying other solutions before finding this post.
You saved me! Thank you!

@KurtJacobson
Copy link
Author

KurtJacobson commented Sep 18, 2019 via email

@ostanki
Copy link

ostanki commented May 1, 2020

Thanks! (Also for the Calibrating_Touchscreen link in Your references that shows how to make it stick !)

@feer9
Copy link

feer9 commented Aug 30, 2020

Thanks, this helped a lot with an old Genius MousePen i608 Tablet, together with an xorg.conf file

@kreijack
Copy link

I created a project derived from xinput_calibrator called xlibinput_calibrator. It uses libinput , so it works with the new Xorg.

https://github.com/kreijack/xlibinput_calibrator

@lawrence-jeff
Copy link

Thank you very much for this - finally got my ELO touchscrren to work using @pquiring's values (I also have a 2218)
The exact cmd I used is
xinput set-prop "ELO Touch Solutions ELO Touch Solutions AccuTouch 2218 " 'Coordinate Transformation Matrix' 1.22 0.0 -0.11 0.0 1.38 -0.19 0.0 0.0 1.0

Note on my touchscreen the device has a trailing space after the 2218 - so you need to include that in the name

Any advice on how to get this to persist over reboots? Or to enable hold right click? In one of my attempts I think i had this working via edit of xorg.conf but i lost that web link

@markostamcar
Copy link

I created a project derived from xinput_calibrator called xlibinput_calibrator. It uses libinput , so it works with the new Xorg.

https://github.com/kreijack/xlibinput_calibrator

@kreijack, thank you very much for this! Worked great on latest Raspberry Pi OS Bullseye!! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment