The Touchscreen


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.

 Go to post page

January 22nd, 2012 by sephiroth

Microtouch Serial Touchscreen Working with Ubuntu 11.10 (Oneiric Ocelot)

Touchscreen with Ubuntu & Gnome 3

Finally got the touchscreen working on the laptop. It worked fine on the desktop, though I think the pcmcia card I’m using in the laptop was giving me problems.

Not sure what got it working in the end (couldn’t get an xorg.conf file to work at all… kept crashing on boot) but among the things I did that may have got it working was install the default microtouch drivers :

sudo apt-get install xserver-xorg-input-mutouch (turns out this is not necessary.)

and set the serial port as the input with

sudo inputattach -mtouch /dev/ttyS4

ttyS4 will vary depending on your port.  I found mine by unplugging the pcmcia card then replugging it and entering dmesg in the terminal which showed the port number it was assigned among other things.

Didn’t work the first few times, then it just suddenly started working, so not sure if I did something different :/

Anyway, here is Ubuntu 11.10 running Gnome 3 (I love Gnome 3 so much… I want its babies) with a working 15″ touchscreen.


UPDATE :  Once I restarted the computer I found the touchscreen didn’t work automatically though when I entered

sudo inputattach -mtouch /dev/ttyS4

into the terminal it started up again.

It needs to start automatically since I won’t have a keyboard on this computer.

To get it working automatically the following should work.

You need to edit the rc.local file by entering this into the terminal :

gksudo gedit /etc/rc.local

and then add the following lines at the bottom :

inputattach -mtouch /dev/ttyS4 &

above exit 0 and save it.

Then in theory it should start automatically next time you reboot. Mine is a bit funny. For some reason it will only start if I am touching the screen during boot. Basically from the grub screen onwards I have to touch the screen or my pcmcia serial card won’t start… which is annoying, but put-up-with-able.

 Go to post page

January 1st, 2012 by sephiroth

New Touchscreen Works! But…..

Good news… the new Microtouch touchscreen seems to work just fine on Ubuntu 11.10. I tested it on the desktop and got it working by creating and xorg.conf file by running the code below through the terminal. (This technique should work for most serial touchscreens, don’t try this for USB touchscreens)

sudo pico /etc/X11/xorg.conf

In modern versions of Ubuntu, this should bring up a blank xorg.conf file in your terminal (unless you’ve already created one of course). Then copy and paste the following into it.

Section "InputDevice"
Identifier "TouchScreen"
Driver "mutouch"
Option "Type" "finger"
Option "Device" "/dev/ttyS0"
Option "ScreenNo" "0"
Option "MinX" "0"
Option "MaxX" "16383"
Option "MinY" "0"
Option "MaxY" "16383"
Option "SendCoreEvents" "yes"
EndSection

Section “ServerLayout”
Identifier “X.org Configured”
InputDevice “touchscreen”
EndSection

The press Ctrl+O and hit enter to save it. You can then press CTRL+X to exit.

The part I’ve highlighted in red may vary depending on your system. ttyS0 refers to the serial port on my computer that the touchscreen controller is attached to. Your’s may be different, perhaps ttyS01.

One way to easily find the port number you need is to run this through the terminal while the touchscreen is connected :

cat /dev/ttyS0

Then touch the touchscreen. If it is the correct port, the terminal should output a load of garbage every time you touch the screen. If nothing happens then you have the wrong port. Try ttyS1 next, then ttyS2 etc…

On my laptop, because of the pcmicia serial port, my port number is actually ttyWCH0. The only way I know that is from the instructions for the pcmcia card.

After I rebooted, the touchscreen worked straight away.

Only problem is the touchscreen is firmly attached to the LCD screen and it would be quite difficult to remove it. But I quite like the screen. It is slightly bigger than the screen on the laptop and has a better resolution, so I think I’ll try to use it instead of the laptop’s LCD for the 15″ tablet project.

Now, there IS a problem with the LCD screen. The backlight is dead! I’ve tested it and it is definitely the inverter and not the CCFL bulbs in the screen. This is a pain, since I don’t know where to find a replacement inverter, so it looks like I’m in for another hack!

New Hack : Convert LCD Screen from CFL Backlight to LED Backlight.

I’ve ordered 50 ultra bright LEDs which should hopefully be bright enough. They should arrive before the end of the week and I’ll let you guys know how it works out, and I’ll post a How To as well if it’s successful.

 

UPDATE

I’ve taken out the old CCFL bulbs for the Microtouch monitor’s backlight, but there is only about 5mm x 5mm space to work with.  Ideally I was hoping for a bit more since this tiny space is going to make it very difficult to install a powerful LED array.

I’ve managed to find another cheap inverter (£5.99) which should be able to replace the old busted one, but it’s going to take a while to get here.  In the mean time I thought I could probably steal the inverter and CCFL bulb from the laptop’s monitor and retrofit it to the Microtouch monitor.  This could actually be an ideal solution if it weren’t for the fact that the Microtouch monitor uses two CCFL bulbs and the laptop only uses one, so not sure how bright it is going to be.  Will give it a go this weekend.

 

 Go to post page

December 29th, 2011 by sephiroth

No luck with this touchscreen so ordered a new one

Pretty sure either the touchscreen or the controller are knackered. Got it working fine on the laptop on Windows XP but the cursor kept jumping all over the place. No joy getting it working on the laptop with Ubuntu though I’m certain that’s because I haven’t installed the drivers for the PCMCIA serial adapter properly.

Tried it with Ubuntu 11.10 on my desktop which has an on board serial port and it was behaving the same as it was on the laptop with XP and calibration wouldn’t help, so I’m going to have to give up on it.

Well that’s £25 down the drain. I’ve ordered another touchscreen. This time a complete unit with the LCD monitor.

15" Microtouch Touchscreen LCD Monitor

15" Microtouch Touchscreen LCD Monitor

This one also has a serial connection, so I’ll have to either get this serial adapter working, find one that does work, or use (*spit*) Windows.

Serial and VGA Ports

Serial and VGA Ports

The LCD monitor needs a 12v 5a power supply so if I wanted to used the monitor itself in the tablet I would have to add another power supply which will add to the bulk and the weight of the tablet, so hopefully I will be able to remove the touch panel and controller from the unit so I can still use the laptop’s much slimmer, lighter, and lower powered screen.

This is a Microtouch touchscreen by the way (another SAW type screen), which I’ve seen working on Ubuntu so fingers crossed it works since it is also untested!

Cost of the new screen = £26

This pretty much takes me up to the £100 mark in total costs, though if we write off the cost of the original touchscreen I still have £25 left to play with. ;) Cheating?

 Go to post page

December 28th, 2011 by sephiroth

Some Success with the 4001S Cable

Had some success this morning.  The manufacturers got back to me a wiring diagram of the 4001S cable so I could wire up the controller directly to the serial port on the laptop.

Couldn’t get any life out of the touchscreen at all with Ubuntu, but there is some response in Windows XP.  Think there might be something wrong with the way I have the serial port set up in Ubuntu so will have a look at that tonight.

So at least I know it is wired up right. :) Now to get it working!

EDIT : Just thought… these drivers may not be compatible with Ubuntu 11.10. The most up to date version they are designed for is 10.10 which could be a pain since Gnome 3 + Ubuntu 10.10 aren’t the best of friends, and I really want to use Gnome 3 on this build.

 Go to post page

December 27th, 2011 by sephiroth