cheesebobdole
cheesebobdole

Reputation: 11

Using 2 Touchscreens on raspberry pi 4

I'm trying to do a project that would use 2 touchscreens on a raspberry pi 4 running buster, thanks to the dual HDMI output. I've got no issues with the displays and the pi recognizes the touch coming from both the screens, but it doesn't discern what touch is coming from which screen. The end result is erratic and unpredictable mouse movement.

I've thought about using python (pyagutogui) to control the mouse based off of where the touch is sensed on either screen. In theory, my code would work in 3 steps:

1) Receive x-y values of touch location from either /dev/input/mouse0 or /dev/input/mouse1 (or possibly other locations? Currently that's where I can see "mouse" movement from touch)
2) Apply correction factor to determine where on the display the mouse should be
3) Use pyautogui to move the mouse to that location and click

My main issue is that I don't know how to get the raw X-Y data from the touchscreen. Any ideas on how to accomplish this, or any other ideas on how to get to my end result would be much appreciated!

Upvotes: 1

Views: 3771

Answers (3)

Marcel0815a
Marcel0815a

Reputation: 21

@sheddenizen thank you, yes it´s working for me with 2 identical touch screens.

xinput --map-to-output 6 HDMI-1
xinput --map-to-output 7 HDMI-2

Upvotes: 2

sheddenizen
sheddenizen

Reputation: 516

Ancient question, but since I was having the same issue and struggling to find a concise answer, I'll add mine in the hope it's useful for the next person.

You can use xinput to map an absolute pointing device like a touchscreen to a specific display

xinput --map-to-output <device> <crtc>

Where device is the numeric id given by xinput --list and crtc is the display name as given by xrandr. So in my case, I run the following bash script from the autostart to map two touchscreens to their respective monitors on a Raspberry Pi 4:

#!/bin/bash
xinput --map-to-output $(xinput --list | sed -re '/G2Touch/ ! d ;  s/.*id=([0-9]*).*/\1/') HDMI-1
xinput --map-to-output $(xinput --list | sed -re '/wch\.cn/ ! d ;  s/.*id=([0-9]*).*/\1/') HDMI-2

Where G2Touch and wch.cn are the device names given in xinput --list for the two monitors, respectively.

I'm not sure how you would go with two identical touchscreens; I would expect they would enumerate in the same order in which case you should be able to use the numerical IDs directly, but perhaps some trickery might be needed with udev?

Upvotes: 0

Marcel0815a
Marcel0815a

Reputation: 21

did you got any solution? I installed sudo apt-get install xinput-calibrator after the calibration i got a window with this text:

Section "InputClass"
    Identifier      "calibration"
    MatchProduct    "TSTP MTouch"
    Option  "MinX"  "51"
    Option  "MaxX"  "65564"
    Option  "MinY"  "82"
    Option  "MaxY"  "65398"
    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

this should go to these files: /usr/share/X11/xorg.conf.d/40-libinput.conf or /etc/X11/xorg.conf.d/10-blanking.conf

so I got some coordinates and changed that a little but without any result. Sorry I don´t have a solution but maybe that helps a little bit.

Upvotes: 0

Related Questions