Raspberry Pi, Xbian & eGalax touchscreen

Xbian: Touchscreen calibration & extra features

UPDATE: See tutorial end for easy install script…

The following tutorial describes additional steps, after installation of Xbian1.0beta1, to enable calibration and extra functionality for the eGalax touchscreen in XBMC. By using a modified version of ts_calibrate for touchscreen calibration and python utility uinput-mapper, it’s possible to generate a user-input device even which handles the calibration transformations and gives additional BTN_LEFT/RIGHT functionality within XBMC on the Raspberry Pi.

The procedure requires to install the following:

ts_calibrate

uinput-mapper & Upstart script – uimapper.conf

The Upstart script uimapper.conf starts/stops the python script uinput-mapper whenever the input-device is added/removed allowing hot-plugging and grabbing of the device within XBMC.

I have 512pi too…but when I start or stop xmbc i have to type “sudo SERVICE xbmc start/stop/restart”..not only “xbmc start/stop/restart”…this is the difference between /etc/init.d and /etc/init I think..

for me the touchpad doesn´t work like it should. in the middle of the screen it´s ok, but up, down, left and right side the arrow goes “away”, means its in front of my finger . is it possible that the resolution is the issue? my tp has 1024×768, but calibrate says 1280.

I’m using a 7′ 800×480 screen(Model at070tn94) with eGalax touch screen.I’ve done with your guide,but how to calibrate the screen?
When I run the ts_calibrate,it prompts:
root@xbian:/home/xbian# ts_calibrate
ts_calibrate: error while loading shared libraries: libts-1.0.so.0: cannot open shared object file: No such file or directory

I have seen this error before, I thought i had fixed it for a fresh install of xbian beta1 and raspbmc….is this an upgrade? or have you previously installed ts_calibrate, tslib_dev etc. Maybe removing the package tslib first might help. It looks like the paths set in the config file are incorrect and the library can’t be found.

Ok, the pointercal file is generated automatically when execute ts_calib and select 5 points. The information looks ok to me, you can see top left and bottom right values will give you an inverted Y axis. The problem , I think is that uimapper is not running for some reason. It is uimapper that uses the pointercal file.

Using SSH, login in and type…

stop xbmc
start uimapper

apt-get install evtest
evtest

Did uimapper start?
Can you see, in the device list, a uimapper device entry?

We need to see this so xbmc can use the calib file, if not, xbmc wiull grab the egalax device and not uimapper, therefore xbmc will use the egalax directly and not add the scale and offset values from the pointercal file.

Hope this helps, if uimapper is not running then we can check the device values in the /etc/init/uimapper.conf file

Well finally calibrate the touch screen, ts_calib.sh generated data, only the X-axis and Y-bearing offset offset a little mistake, I manually calibrated Well, thank you very much! One to start the calibration data is not accurate because the touch screen ID set incorrectly. UIMAPPER not properly get to touch the device. Thanks again!

Ok good news, if you think you calibration is off, then maybe it’s worth checking to see if overscan is set when calibrating or the video overscan in xbmc, obviously the two should match. The other reason may be, the ts_lib calibration equation accounts for skew in the touchscreen too by adding compensation of x,y in the x & y equations; I didn’t include this at this stage into the calibration in uimapper.

Just to confirm and help others, in order to get it working you had to manually edit the ts_calib.sh script and uimapper.conf line and assign the correct /dev/input/event# as described in detail in the above tutorial?

In /etc/init/uimapper.conf When i insert more input devices, event? is not fixed, so do not run correctly uimapper,this is the reason why I can’t calibrate the correct device.I just changed the ts deviceid in ts_calib.sh but not in uimapper.conf

The only way I found to do it in upstart is by changing the uimapper.conf file, I will mail you a copy of the new one, it gets the correct event for eGalax automatically now. The only problem I can see is with RASPBMC, I have 2 eGalax events one for BTN_ events and one for touchscreen pos and BTN_TOUCH

great tutorial! I tried it the manual way (seen the automatic way too late).
The calibration is working: I had to choose event4, first try event3 (which is also my touchscreen) didn’t work.
The crosshairs disappear, after touching them and I get an output from it.

But in my xbmc, which runs via raspbmc in framebuffer, doesn’t mind the touchscreen calibration, still working but no change, pointer is fart away from my fingertip.

Does the visual resolution have any effect?

How do I get the calibration data into a screen running in framebuffer (raspxbmc).

I have the same thing with raspbmc, ther are 2 events, one for BTN_ events and the other for touchscreen position and BTN_TOUCH, this is the one you need. If you install evtest, you can see the event that gives the position feedback.

sudo apt-get install evtest

you also need to change uimapper.conf file to the correct event number. To test it is working , use ssh..

stop xbmc
start uimapper

evtest

(you should see a uimapper – touchscreen event too)

start xbmc

Now, it should have correct position and BTN_RIGHT.

Make sure the calibration is done in the same resolution when in framebuffer and xbmc, also check for overscan.

Check /boot/config.txt

the file /etc/pointercal has the calibration values and the screen resolution at which they were calculated.

After booting the into Xbian, use your PC to SSH via ‘putty’ and perform the short install process, provided by Brantje, by typing the following.
sudo su
wget https://github.com/brantje/xbian-touch/raw/master/install.sh
sudo sh install.sh

Follow the instructions, the process take a few minutes. Any problems just let me know or you can use the info in the thread to diagnose.

thank you sir, it’s only working good if resolution is 1280x 720
but not working good if resolution is 720×520
i need it work for lower resolution i have 6.5 touch screen for car project
when it calibration it i got “xres = 1280, yres = 720 ”
even i change the xbian setting to other resolution
how to fix this

I am working on a solution, you have found an anomaly!
I will provide a work-a-round in uimapper, so only one calibration necessary and then it will scale correctly in any resolution.

The reason:
i recalibrated ts_calib in a lower resolution in config.txt. The values given out are as expected in evtest and correctly scaled. The situation arises in xbmc, irrespective of the resolution, the mouse position is always from 0,0 to 1280,720 (depending on overcscan). So this makes gives incorrect mosue position when using touch.

You can diagnose x,y co-ordinates in xbmc too. In the skin folder you can edit addon.xml file. Changing debugging=”false” to “true” displays the pointer position on the screen. Using this you can see how the overscan effects the pointer max/min values

I’ve just finished updating uimapper so the calibration should still be ok if you decide to change screen resolution. Now you can calibrate in default (720p) resolution and if you reduce resolution and replug device (or restart uimapper/xbmc) then calibration with change to suit screen mode.

Also, you can calibrate in lower resolution to by changing /boot/config.txt. If you then change config.txt back to default (720p) the calibration should still work ok too.

There seems to be a problem however above 720p (1080p), still need some work, but as this is mainly for touchscreens, then I think most situations will be ok.

Please give it a try, by doing the following fro SSH to pi:
stop xbmc
stop uimapper

Best advice I can give to you is to follow my original tutorial, don’t use the install script just yet.

1. Set the /boot/config.txt to the screen resolution you want. This will set the resolution in XBMC also.

2. Follow tutorial, and calibrate screen ( check resolution in ts_calib output).
You can run ‘sh ts_calib.sh’ as many times as you wish, until you are happy with the values, or accuracy. I recommend using a small fine tip to be accurate.

3. Install UIMAPPER as described in part 2 of tutorial. This is the new version ans should have better results for resolutions other than 720P.

4. If you are still not getting accurate behavior, you have two options.
option I:
Change manually the etc/pointercal file:
nano etc/pointercal

Hey Mark – this is a great walk-through. Thanks for maintaining it and supporting those of us trying this for the first time.

I have a Lilliput 869 monitor with an 8″ touchscreen. The resolution on this is 800×480, but ts_calibrate uses xres = 720, yres = 480.

I am seeing bad accuracy towards the edges of the screen. I am not sure, but I suspect it is related to the incorrect resolution at calibration time. I was looking to modify /boot/config.txt, but 800×480 doesn’t seem to be a supported setting.

If that doesn’t work, again in touchscreen.py, you can modify the x, y equations to slightly change the scale and offset value for each axis to fine tune the result, remembering to stop/start xbmc and uimapper to see the changes.

Hi Mark – here is the update. In short, I think it is fixed now. I ran evtest and it looked like the x/y matched the x/y min/max settings in touchscreen.py. Before I started playing with the formulas, I decided I would try to force the screen resolution correctly and re-run the calibration. This is what I did:

Add these lines to /boot/config.txt to set the resolution:

#set specific CVT mode
hdmi_cvt 800 480 60 6 0 0 0

#set CVT as default
hdmi_group=2
hdmi_mode=87

Then reboot (shutdown -r 0). After the system restarts, stop xbmc and uimapper and re-run calibration:

sudo stop xbmc
sudo stop uimapper
sudo sh ts_calib.sh

Then reboot (shutdown -r 0). Now in XBMC it seems that the pointer is tracking linearly instead of progressively getting worse towards the edges.

(N.B. Don’t think Brantje’s install.sh contains the latest updated uimapper.tar.gz files, made some changes for different screen resolution which weren’t working; the uimapper link in the tutorial is the latest as described here…http://markamc.cybaman.net/?p=50#comment-87)

Hi. I would like to thank you guys a lot. I tried the manual installation and it wouldn’t work at all. Not a bit. Now I put on a new imagie and tried out the install.sh. This took just 2 minutes and tadaah …. it works. Thank you heaps!

There must be a solution above that will work for you. If ‘uimapper’ is running then maybe try editing the scale and offset values directly in /etc/pointercal file, or the /scripts/uinput-mapper/configs/touchscreen.py file.
If you stop uimapper and xbmc, make changes and then start both again you can see if it changes the result; basically the offset values move the origin +/- back towards top left and the scale values reduce/increase the move size.

It might help to display the x,y coordiates on xbmc, and compare with the values form evtest. (top left, bottom right)

Regarding jumping, you can change the ‘nice’ value to ‘-20′ for higher priority, this may improve lag (large number of transformations); it is for a touchscreen so no real need for mouse-dragging.

Calibration should work though, check /boot/config.txt for screen res. and overscan. Post the output from evtest and ts_calib and I can see. Also info on your TS.

Got it to working fine in the end. the solution turned out to be actually very simple.

First I (re-)started to tweak the pointercal values, but that didn’t change anything. even with values of 0 (zero) for both xoffset and yoffset I had exactly the same behavior (which is abnormal in my opinion). the scales values did have some “effect” but no solution as I was changing them…

Then I was going over all the replies in this blog and saw a few entries about the hdmi resolution – I though to give it a try. Debugging the XBMC skin confirmed that the resolution is 1280×720 so I forced the hdmi output to be the same by adding this in the /boot/config.txt

hdmi_cvt=1280 720 60 4
hdmi_group=2
hdmi_mode=87

rebooted.. and guess what? problem solved! In the end the solution turns out to be as simple as logical
I have no idea if, when using a small touch (< 10inch), the resolution of the hdmi plays a lesser important role but I can confirm that the default resolution was causing my issue.

If you run ts_clib and generate the file /etc/pointercal, then the axis directions and swap, if necessary, are automatically handled, but only if uimapper is running. Please ‘stop xbmc’ and use evtest to check if the entry ‘uimapper – touchscreen’ event is created in the event list.

Great news the uimapper now shows up in evtest
and the axes are correct just the calibration is way off
I am currently using RCA video (HDMI to VGA still on it’s way)
Is there a resolution I should be setting in config.txt for this ?
or anywhere else

good to hear it’s nearly working, I need to update the download tonight. I have not tried on composite output, with overscan so not sure how it will look. I will look into this. In the meantime there is info in thread above detailing how to tweak calib values (offset/scales) to refine the calibration within the /scritps/uinput-mapper/configs/touchscreen.py’ file.

Again, I’ll check the composite solution later,

cheers,

mark

——————————–

UPDATE:

Hi again John,

Not forgotten about the issue. Some of the touchscreen.py config were changed to suit the “egalax patch (andrei) applied to xbian.

It is important to make sure the config.txt screen res is the same one used by ts_calib. I read the current resolution set by xbmc, using ‘tvservice -s’, the mouse returns values between 0,0 & 1280,720. Using these values if I calibrate in 720p, change resolution in xbmc and then stop/start uimapper & xbmc, my calibration works for most resolutions from 480p upwards. I am working on a fix to restart uimapper if screen resolution is changed in xbmc, thus maintaining calibration, to avoid the restart.

For now, if you can get ts_calib res and config.txt res etc the same, the calib should work, if not try tweaking the equations in touchscreen.py using the scale factors and linear offsets in both x and y equations.

I/m wondering whether the interlaced resolution is causing the problem. Your config.txt res. and the ts_calib res. are ok, so calib should work. You should also be able the get this resolution in xbmc, albeit interlaced, i need to test this on my system.

I have used hdmi mode to set 720x480i in config.txt and then calibrated in 720x480i in ts_calib (tvservice giving the same res.) and it works ok….I can also select 720x480i in xbmc and the pointer scale and offsets work fine. I’m sorry if this doesn’t help you, maybe you can change some values manually in the touchscreen.py file or change the pointercal values until it gives a better result. The pointercal values are described in the thread or in the xbian forum.

Xbian beta 2 EGalaxy with 7″ Touchscreen.
For all the People they have problems with the right position of the mouse finger if you touch. —-> install all the things step by step by hand and you will not have any problems.

Hey Mark!
Your solution seems to work for many people so thumbs up for that, solid work. I do encounter some problems tho and hope that you can give me a hand.
I freshly installed RaspBMC and went through your solution, calibrated the eGalax screen, which seemed to work.
Then I installed uimapper and evtest and changed the uimapper event to the right one.
starting and stopping uimapper works and evtest shows uimapper as an extra event (I have 2 eGalax Touchscreen events and one uimapper) evtest also shows that it’s touched when I tap on the screen.
But when I start xbmc again it’s not at all calibrated.
Is it possible that I have to use an older version of RaspBMC?

I wonder if you could help me with that.
Thanks for your awesome work.

I used brantje’s script on Xbian and it worked like a charm. I’d like to use RaspBMC tho to get dac support.

I think you need to check whether the uimapper is working and grabbing the device, drop out of xbmc and use evtest to check. The pointercal is calculated automatically and from the values displayed in the ts-calib event it shows that the minimum x,y are top left, this is correct.

Hey there,
great guide.
Having a slight issue, I used BrBranjte’s script and that worked fine for me, but my x and y axis’ are both inverted despite recalibration and trying to calibrate with inversion in mind.
Any idea as to what might be causing this?

I have everything configured, but the touch only works on part of the screen. It was the bottom left corner, but I switched the touchscreen output cable around and now it is the upper left corner. I can use the cursor a little bit, but it is across the screen from my finger press. I have tried the suggestions with running evtest and it detects input on every part of the screen. I go through the calibration just fine and am able to touch all of the points. uimapper is running. I modified the config file so that it starts on start-up.

I’m sorry, I have no time left to work on this site despite the fact that it gets viewed daily , but i cannot support it anymore. There is enough info within for any “novice” (like i was/am) to get into linux/python/coding an enjoy!! good luck!

Hey I’m a complete noob at Linux and really need some help with the calibration I noticed that free fish was having similar problems with his the only difference in mine is that the x axis is inverted and the y axis is above where I touch and if I go for the bottom of the screen to the top the pointer gets farther away from my finger but I’m running the latest version of xbian and I have the egalax at070tn92 touch screen which is 720 bye 576 or at least as far as tscalib think any help you can give me would be very much appreciated I’m literally out of ideas and have tried apt get evtest and it says “not found in library” so yeah I can use any help you could offer thanks