Ubuntu Touchscreen Problems and Their Solutions

As hard as it was to physically build “The Captain’s Writing Desk“, getting the software side of it working wasn’t a walk in the park either!  It took me a while to figure out how to get my screen working.  xorg.conf is no longer used in recent versions of ubuntu and the process of creating and editing your own xorg.conf file can be quite tedious.

I have only tried these methods with a Microtouch touchscreen so can not guarantee they will work with other brands.

Install a Serial Touchscreen in Ubuntu
Begin Touchscreen at Startup
Begin Touchscreen on Resume
Calibrate your Touchscreen
Right Click Solution for Single Touch Touchscreens

Installing a Serial Touchscreen in Ubuntu

 

The easy way to get a serial touchscreen working on Ubuntu is with Inputattach which comes installed on recent versions of Ubuntu.

Inputattach is run from the terminal and has several parts.

sudo inputattach -mtouch /dev/ttyS4

This is the terminal command I use to get my serial Microtouch touchscreen working.

“sudo” invokes user rights, “inputattach” summons input attach, “-mtouch” tells Ubuntu which driver to use, and “/dev/ttyS4″ refers to the serial port the touchscreen is plugged in to.

To find which port you need, plug in and turn on your touchscreen then enter the following command into the terminal.

sudo cat /dev/ttyS0

Enter your password then touch the screen.  If that is the right port, then the terminal should output a bunch of garbage when you touch the screen.  If that has no reaction, then try another port.

sudo cat /dev/ttyS1

and repeat for ttsS2, ttyS3, ttyS4, etc etc… My computer only has one port but for some reason it is listed as ttyS4.

Once you have found the port number, identify the driver you need to use.  The following drivers an be found on this page : http://manpages.ubuntu.com/manpages/natty/man1/inputattach.1.html

Mine is a Microtouch screen so I’m using -mtouch.

If everything has gone smoothly, then next time you enter

sudo inputattach -mtouch /dev/ttyS4

(with you adjustments) the cursor should begin responding to your touch.

Begin Touchscreen at Startup

 

To initiate the touchscreen automatically at startup, you need to add a line to the /etc/rc.local file in Ubuntu.

To edit this file enter

sudo gedit /etc/rc.local

into the terminal and enter you password.  This should bring up the rc.local file which will probably look like this :

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0″ on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

Now add a line to it above “exit 0″

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0″ on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sleep 10s && inputattach -mtouch /dev/ttyS4
exit 0

The part in red will be from the line you enter into the terminal to initiate the touchscreen (sudo isn’t needed in rc.local).  I added “sleep 10s &&” to the line because for some reason rc.local gets loaded too early and so doesn’t activate the touchscreen.  “sleep 10s &&” tells Ubuntu to wait 10s before trying to initiate the touchscreen.

Click save, then restart your computer.  Hopefully your touchscreen will now work automatically at startup.

Begin Touchscreen on Resume from Suspend

 

The next problem I found was that inputattach would stop working when I put the computer into suspend/hibernate.

To fix this, we need to rerun the command when the computer resumes from suspend.

To do this, enter the following into the terminal

sudo touch /etc/pm/sleep.d/99-touch-restart

sudo chmod +x /etc/pm/sleep.d/99-touch-restart

sudo gedit /etc/pm/sleep.d/99-touch-restart

This will bring up a blank text document.   Copy and paste the following into that document leaving no space at the top and substituting the part in red for the line you added to rc.local earlier.

 
#!/bin/bash

#suspend_inputattach() {
#    inputattach automatically stops on suspend, so no need
#    usr/sbin/inputattach
#}

resume_inputattach() {
# restart input attach program
sleep 10s && inputattach -mtouch /dev/ttyS4 &
}

case “$1″ in
thaw|resume)
resume_inputattach
;;
*)
;;
esac

exit $?

Now next time you resume from suspend, your touchscreen should be working.

Calibrating your touchscreen

 

This part is easy!  Enter the following into the terminal.

sudo apt-get install xinput-calibrator

This will install the touchscreen calibrator. You can find it in your applications, or you can run it from the terminal with the following line.

xinput-calibrator

A white screen will come up prompting you to press crosses in the corners of the screen. Once you’ve done that, the screen will close and the terminal will output the calibration settings.  Mine looks like this.

Section “InputClass”
Identifier “calibration”
MatchProduct “MicroTouch Serial TouchScreen”
Option “Calibration” “16522 -283 16685 -478″
EndSection

Enter the following into the terminal.

sudo gedit /usr/share/X11/xorg.conf.d/99-calibration.conf

and copy and paste the calibration data and save the file.  Your touchscreen should now be calibrated.

Right Click Touchscreen Solution

 

Unfortunately, since this is a single touch touchscreen,  there is no easy way to initiate a “right click” to bring up the context menu.

One solution which will please most is to use Ubuntu’s Universal Access setting “Simulated Secondary Click” which can be found in the Pointing and clicking section.  This will make it so that it will initiate a right click if you touch the screen in one spot for a few seconds.

This doesn’t work for me since my cursor tends to jitter/shake around a few pixels when I’m pressing against the screen so it doesn’t initiate the right click.

Another solution is to use Easystroke to initiate a right click by holding down a modifier key on the keyboard (ctrl,alt,shift, or super) and using a “gesture”.  this gesture can be a simple as a single click while holding down one of the modifier keys.

This doesn’t work for me, since my computer doesn’t use a keyboard.  I only have access to the “launch” keys that were originally used for things like launching internet explorer (*spit*).

In the end I came up with the following solution.

Ubuntu has a good solution

In terminal enter:

xinput list

This should bring up a list of devices like this :

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ USB Keyboard id=10 [slave pointer (2)]
⎜ ↳ PixArt USB Optical Mouse id=11 [slave pointer (2)]
⎜ ↳ Mouseemu virtual mouse id=14 [slave pointer (2)]
⎜ ↳ MicroTouch Serial TouchScreen id=15 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ USB Keyboard id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=12 [slave keyboard (3)]
↳ Mouseemu virtual keyboard id=13 [slave keyboard (3)]

(ignore Mouseemu that was something else I tried but didn’t work. Doesn’t appear to be compatible with touchscreens)

Look for the line referring to your touchscreen and make a note of its name. In this case, my touchscreen’s name is recognised as “MicroTouch Serial TouchScreen”.

Enter the following into the terminal.

sudo touch /swapmouse.sh

sudo chmod +x /swapmouse.sh

sudo gedit /swapmouse.sh

This will bring up another blank text document that you just created in your home directory.

Then copy and paste the code below into the empty text document, replacing “MicroTouch Serial TouchScreen” for your touchscreen’s name.


#!/bin/bash

xinput set-button-map “MicroTouch Serial TouchScreen” 3 2 1 4 5  && sleep 3s && xinput set-button-map “MicroTouch Serial TouchScreen” 1 2 3 4 5

 

Then using keyboard shortcuts (under “keyboard” in Ubuntu’s settings), create a custom shortcut and use “Swap Mouse” as the name (or any other name you want) and enter the path to the file you just created in the “command” box.

/swapmouse.sh

Then assign the key you want to execute the script with. I’m using what Ubuntu calls “launch2″ but you can use any key you like.

Now when you press that button it will temporarily swap the click function of the touchscreen to a right click.  This will last for 3 seconds which should give you enough time to click what ever it is you wanted to right click on. After that the touchscreen click behaviour returns back to normal.

 

You must be logged in to post a comment.