Aligning Zynthian Touchscreens
So you have your zynthian and the display works . . .
But what if your pointer moves left and your cursor goes up...?
Well, hopefully this will act as a repository of knowledge for these sorts of problems.
The First thing you need to sort out is that you have a suitable zynthian display set up that works with the display you have installed on the Pi.
This is accessed by the webconf.
Now the screen we are playing with is a 3.5" screen with a touchscreen and not much else.
Well you are going to need to modify files within your zynthian's file system to adjust these things.
predominately files that look like this . . .
The following is a list of operations to be performed but the actual location of the script seems to vary between different installations.
For instance on my own machine, /usr/share/X11/xorg.conf.d/98-screen-calibration.conf is the location that worked. Othere people have located it successfully in /etc/X11/xorg.conf.d/99-calibration.conf. So a certain amount of adaption is required...
|1.||SSH into zynthian (root/raspberry)||Ok|
|2.||> cd /etc/X11/xorg.conf.d||Ok, files in there … 99-calibration.conf, 99-fbdev.conf|
|3.||> cp 99-calibration.conf 99-calibration.conf.backup||backup your current config|
|4.||> apt-get install xserver-xorg-input-evdev||This package provides the driver for input devices using evdev, the Linux kernel’s event delivery mechanism. This driver allows for multiple keyboards and mice to be treated as separate input devices.—I appear to already have this|
|5.||> apt-get install -y xinput-calibrator||A generic touchscreen calibration program for X.Org —I’ve already got it but I’ve played around a bit|
|6.||> > apt-get install -y bc GNU bc||3. copy and paste bash script from link above, create this as “calib” script (using vi [grrrr]… nano is a much easier windows like tool for people who have issues with vi . . . :-). Type nano calib, cut and paste the code into it. Cntrl O to write it Cntrl X to exit …)add this as first line on script:|
|7.||add export DISPLAY=:0.0 to script first line||Easy withing nano . . . :slight_smile:|
|8.||> chmod 755 calib||make it executable; I agree with @Baggypants|
|9.||> ./calib||6. calibration will popup on screen, follow instructions and Play tap the dot :smiley:|
|10.||> nano 99-calibration.conf||7. calibration script will end up with output which should go into /etc/X11/xorg.conf.d/99-calibration.conf [BEWARE! script recommends different file names, IDK if will work then] i already had details for this in the file so I overwrote them|
The location reveals a little it's within the directory.
with this sort of structure....
These are all the files that deal with the X Windows system which is how keyboard, mice, touchscreens, trackballs et al talk to Zynthians and how Zynthians talk back to screens be they great big hdmi one's or tiny touchscreens you need a pin to operate.
What's in these files is defined  in ALL it's gore...
But we just want to get a touchscreen the right way up.
Well we need something called a transform matrix, there is one in the screen above.. . .
Its a list of 9 numbers, more frequently laid out in a 3 * 3 grid
0 1 0 1 0 0 0 0 1
for the example above.
This is a way of laying out some numbers that is easily processed by the sort of worlds tht worry about rotating, transforming, scaling, shifting, skewing and goodness knows what other forms of distortion one can apply to a flat surface.
But on startup we really don't have too much in there ...
The threads for this built from THe x axis threads
Hal80 explained it in proper terms... on this thread. https://discourse.zynthian.org/t/cant-solve-wrong-touch-coordinates-on-a-3-5-screen/4111/18
Hi, well, it’s just my gut feeling that comes from being a physicist :wink: Let me just briefly explain. It’s about so called affine projections (you can google it) which are used to map a point or rather a vector (which defines that point by two coordinate numbers in space, i.e. in x-y-plane) to a new position. Now, these 9 numbers which are written in a single row in the config file, actually make up a matrix which connects the output vector (new point, the point where we want the touch point to be) with the input vector (original point, the point where touch is recorded now) by means of matrix multiplication which in turn is composed of matrices for offset (translation), rotation and scaling. We need scaling and offset here.
In our special case, and according to the nomenclature given here https://wiki.archlinux.org/index.php/Calibrating_Touchscreen we can actually assign a meaning to these numbers. We have the matrix
[ c0 0 c1 ] [ 0 c2 c3 ] [ 0 0 1 ] which is equivalent to c0 0 c1 0 c2 c3 0 0 1 in our config file
c0 defines scale factor along x (horizontal) axis, c2 defines scale factor along y (vertical) axis, c1 defines x offset c3 defines y offset. All these numbers are defined relative to total width and total height according to the above link and this is why the new numbers should be close to 1. For example, introducing an offset to the right by 10 % of the total width (and c1 = 1) would result in the new c1 being 1.1. The nice thing about these matrix operations is that they do not only affect a single point in the x-y plane but all points that are thrown at it. You have to imagine it like pushing a sheet of paper around on a table (i.e. offset, translation), or like pulling on a stretchy piece of cloth on one end while the other end is fixed (i.e. scaling).
Just one remark about the minus signs - they come from the matrix operations for flipping and rotating the axes. As they appear in steps of 90 degrees these numbers are 1 or -1 or 0. It comes from the sin or cos function of the angle of rotation which yields 1, 0, -1 at multiples of 90 degrees but could also give any number inbetween at other angles. Which we don’t want :wink:
Now the only thing I’m uncertain about is, where is actually the corner (0,0). Is it centered at (screen_witdh / 2, screen_height/2) or is it at screen pixel (0,0) (would that be upper left corner?) or does it have it’s own reference frame…