6

I bought yesterday my first 3.5" Touchscreen for my Raspberry Pi. (Elegoo 3.5 inches TFT LCD Touch Screen Monitor) On my Raspberry runs an OctoPrint Image (Raspbian based).

The Display is working. My problem is the touch function; it's kind of inverted. If I touch the upper right. My cursor is at lower right. If I drag from left to right, my course goes just up and down.

I downloaded this driver/program.

I also tried a calibration test with

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test`
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate

And that works fine. After I used xinput_calibrator to read the new calibration data and inserted it at /etc/X11/xorg.conf.d/99-calibration.conf. After rebooting or restarting the "LCD-Show" driver, nothing changes.

Usually, the used program (LCD-show) overwrites every configuration. But I disabled it for debugging and to find my mistake.

For now, I don't know what to do. I changed different values (SwapAxes) but it's always inverted.

Edit - Steps I did with xinput-calibrator:

DISPLAY=:0.0 xinput_calibrator

Output is: enter image description here

I copied the Section to EndSection part into:

/etc/X11/xorg.conf.d/99-calibration.conf

After the restart, nothing changes. I also tried to change the "SwapXY" Value to 0. Again no changes.

  • Hi Kevin, is your issue solved by now? – Dmitry Grigoryev Jan 27 '17 at 10:42
  • Have you tried adding lcd_rotate=2 to config.txt? I realize that's flipping the display not the input, but if the rotated display aligns input properly it might be a quick fix until you can sort out the input layer. – Sandor Dosa Apr 28 '17 at 16:22
5

Download

First, download the file from this link waveshare-dtoverlays

Instalation

My touchscreen is Waveshare 3.5" LCD. I copied "waveshare35a-overlay.dtb" to "/boot/overlays"

sudo cp waveshare-dtoverlays/waveshare35a-overlay.dtb /boot/overlays/ 

then edit the boot configuration with root

sudo nano /boot/config.txt

then add :

dtoverlay=waveshare35a:rotate=270,swapxy=1

"rotate" can be 0,90,180 or 270. It depends on you, it will rotate your screen(output) but not your touchscreen(input).

Then reboot.

Calibration Touch Screen

In order to also rotate your touchscreen(input), we need to modify this file.

sudo nano /usr/share/X11/xorg.conf.d/99-callibration.conf 

or

sudo nano /usr/share/X11/xorg.conf.d/40-libinput.conf.

I used the second one. then set an option transformation setting by adding

Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"

This transformation matrix is for 90degree right (counter-clockwise) because i have already rotated the screen to 270degree, you can also see the other Transformation Matrix settings in the given link. Don't forget, it has to be match with the rotate setting. Then insert the above line into the Section below in the file "40-libinput.conf"

Section "InputClass"
    Identifier "libinput touchscreen catchall"
    MatchIsTouchScreen "on"
    MacthDevicePath "/dev/input/event*"
    Driver "libinput"
    Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"
EndSection

Then save it, and reboot.

Finally, my touchscreen works properly.

For detail step, you can follow this link

2

Similar to Dmitry's answer here's what worked for me on a waveshare 4" touchscreen and xinput-calibrate, when none of my edits in 99-calibration.conf seemed to do anything.

   $ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ADS7846                                   id=6    [slave  pointer  (2)]
...

Should all work, but my xinput list-props 6 gave me three different properties:

  • Coordinate Transformation Matrix
  • libinput Calibration Matrix
  • libinput Calibration Matrix Default

Each of these comes with a 3x3 matrix laid out like so:

Coordination Transformation Matrix (115): 1 0 0 0 1 0 0 0 1

where each can be up to 6 decimal places.

Using a bit of google-fu I found this link which explains the transformations that you can use to edit the input of the screen using

xinput set-prop 6 "Coordinate Transformation Matrix" [your 3x3 matrix here]

On my particular screen I managed to fix both inversion and axes swapping by doing:

xinput set-prop 6 "Coordinate Transformation Matrix" 0 -1 1 -1 - 1 0 0 1

But yours might be different, using the wiki link above gives some helpful transformations. This unfortunately also reverts when you reboot.

  • This worked for me, xinput set-prop 6 "Coordinate Transformation Matrix" 0 -1 1 -1 - 1 0 0 1 – winner_joiner Jun 1 '18 at 4:57
1

tslib (the library you seem to use) should store its configuration in /etc/pointercal. This location can be changed via TSLIB_CALIBFILE environment variable, but there's rarely a legitimate reason to do so. So make sure you're using this file while calibrating, open a root console and type:

export TSLIB_FBDEVICE=/dev/fb1
export TSLIB_TSDEVICE=/dev/input/touchscreen
export TSLIB_CALIBFILE=/etc/pointercal
ts_calibrate

When you complete calibration, check that /etc/pointercal is updated.

Another important file you should be aware of is /etc/ts.conf.

PS. After the exchange we had in comments it became clear that you should be using xinput_calibrator instead of ts_calibrate. I'll write a new answer, but keep this one for people who have to use specifically ts_calibrate for some reason (e.g. using the touchscreen in SDL games).

  • First - thanks for your help. I don´t want to use specifically "/etc/X11/xorg.conf.d/99-calibration.conf". I am very new in everything about display´s/touchscreens. The driver I downloaded uses this file for calibration. At least that's what I thought. If I use your suggested steps, the display works fine with ts_test. But if I switch back to my Desktop, it's still inverse. I think I have to search a way, to tell "LCD-show" to use the ts_calibration file. – Kevin Jan 23 '17 at 18:31
  • @Kevin Have you tried restarting? And please include the contents of 99-calibration.conf in your question, maybe we manage to get it working your way. – Dmitry Grigoryev Jan 23 '17 at 19:12
  • Yes, I restart my Pi after every change. So I tried to use xinput-calibrator. At the start, there is a line with "current calibration values: ... " and these values are not the values in my 99-calibration.conf file. Do xinput-calibrator and my Desktop environment use a different config file? – Kevin Jan 23 '17 at 19:40
  • @Kevin No, xinput-calibrator is supposed to output configuration that you then should put in 99-calibration.conf, so try running it again and replace your current config with the output. If that doesn't work, please please copy that config and paste it into your question. – Dmitry Grigoryev Jan 23 '17 at 20:13
  • Sorry, I thought it's clear. Of course, I copied the output from xinput-calibrator. I will update my Question, with the Steps I did. – Kevin Jan 24 '17 at 8:17
1

If you happen to have a file named /etc/X11/xorg.conf, you should know that this file takes precedence over /etc/X11/xorg.conf.d/99-calibration.conf, so you need to either remove /etc/X11/xorg.conf if you don't need it, or add the contents of /etc/X11/xorg.conf.d/99-calibration.conf at the end of /etc/X11/xorg.conf if you do.

One way to know if those options are really effective is to use xinput:

$ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ADS7846                                   id=6    [slave  pointer  (2)]
...

$ xinput list-props 6
...
    "Evdev Axis Calibration" <Min-X> <Max-X> <Min-Y> <Max-Y>
    "Evdev Axes Swap" 1 
...

If you did everything right, you should see your calibration values in the output.

Also check the /var/log/Xorg.0.log file: there may be messages about some configuration options being ignored due to various reasons.

Yet another way (if you can't get the config file working) is to set calibration data at runtime, using a shell script:

xinput set-prop 6 "Evdev Axis Calibration" <Min-X> <Max-X> <Min-Y> <Max-Y>
xinput set-prop 6 "Evdev Axes Swap" 1

(make sure you replace 6 with the ID you get in your system)

Note that SwapXY option does just that: swaps X and Y axes. If you also need to invert an axis, you should use:

    Option "InvertX" 1
    Option "InvertY" 1
0

The SwapXY function in 99-calibration.conf file works well only if the package xserver-xorg-input-evdev installed properly.

Just try to install it:

sudo apt-get update sudo apt-get install xserver-xorg-input-evdev

And restart the system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.