Search This Blog

Properly setting up a 5" HDMI touchscreen for Kodi on Raspbian

Wow. This was a royal pita. I wanted to build this wake-up-light-alarm-clock-media-thingy for my girlfriend. Well, I got my hands on a RPi Zero and needed an LCD display. I found this nice-looking "WaveShare 4" IPS display" on Ebay and spent days trying to get it to work properly. You want a hint? DONT DO IT! BUY A HDMI SCREEN! Refresh rate sucks, Kodi is not working with hardware-acceleration, Framebuffer copying never worked. Short: It sucked!

So. Next chapter: Bought a 5" HDMI screen here. It has an HDMI input and connects to the RPi GPIO pins for power and touch functionality... and works ALMOST out of the box on a fresh Raspbian install (from 5/2016). Nice!

Set up screen resolution and touchscreen

This gets the display and the touchscreen up and running. You can test if the touchscreen does anything using:

cat /dev/input/mouse0
orcat /dev/input/event0

Setting up the touchscreen for X

This should give you weird output whenever you touch the screen. Fine.
Now you want to calibrate it. To do that install the calibration utility:

sudo apt-get install xinput_calibrator

Then start the GUI. You should now have an entry "Calibrate touchscreen" in your menu. Start it and tap the points. When finished the screen should be calibrated.
Or, to do the calibration from the command line, run:

xinput-calibrator

You can also do this from SSH, if you don't have a keyboard attached:

DISPLAY=:0 xinput_calibrator

Tap the points and when finished, the tool will output some calibration information:

Paste the calibration info into "/usr/share/X11/xorg.conf.d/99-calibration.conf".

Setting up the touchscreen for Kodi

Now you have a calibrated X input device, so the Desktop works nicely, but Kodi still does not. When starting it from X, there is a cursor, but the calibration is way off. When starting it standalone, there is not even touch input...
Fix this by installing tslib and evtest:

sudo apt-get install evtest tslib libts-bin

Additionally you will need Then calibrate the touchscreen using:

TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate

Touch the 5 crosses and you're done. You can test the calibration using:

TSLIB_TSDEVICE=/dev/input/event0 ts_test

You might also need to add the user you are starting / running Kodi with to the input user group. The user might be "kodi" or "kodiuser", but this might vary depending on your installation:

sudo usermod -a -G input kodi

If you have Kodi version >= 17 ("Krypton") you can now set up scale factors for the display so the cursor is properly displayed.

Setting display scale factors in Kodi >= v17

Test if Kodi can use touch input now. Start Kodi and touch the upper
left corner of the screen. You will see a cursor and can move it, but
only in 1/5th of the screen. The problem is that the coordinates
/dev/input/event0 sends are touch device coordinates (in the range you
see in the calibration values above), but Kodi expects pixel screen
coordinates (0-800,0-480). Kodi starts to support touchscreen
calibration out-of-the-box as of v17 aka "Krypton".
Edit the file advancedsettings.xml in your users userdata folder, e.g. /home/kodi/.kodi/userdata or ~/.kodi/userdata. If it does not exist, create it and add the following entries:

Good start values can be calculated by dividing the screen resolution by the X11 calibration values above (e.g. for x: 800/3982=~0.2 and 480/3883=~0.124). Note that you have to restart Kodi after editing the values to see any changes.

Installing a touchscreen calibration fix

When you have an older Kodi version and can not use advancedsettings.xml, there are also ways to properly calibrate your screen. Read here about using a tslib fork and ts_uinput_touch for this.

Fixing the double-click issue

A remaining problem is that Kodi wants a double-click to activate a function. This is not good as we want to activate functions with a single click or tap. We can change this by editing the file /usr/share/kodi/system/keymaps/mouse.xml. Change the entries in the mouse section to:

Hello - very good description. I don't know what i'm doing wrong, but starting Kodi no matter if standalone or from X leads to not the slightest trace of a Cursor. The only thing that happens is that if i use a mouse the cursor appears - and on touching the cursor disappears. So the Touchscreen is at least doing something, but nothing of any value - do you have any clue what's wrong. Every hint is very appreciatedThanx

It probably depends on your OS, your Kodi version and what skin you are using, so I can't say what's wrong. Try turning on the debug log and see what you cant find in there. Btw. Kodi hides the mouse when you don't mode it, so that behaviour is normal...

Which Kodi version do you have? Is you X calibrated (the user interface of your regulöar desktop you start with "startx")? Try to find advancedsettings.xml using "sudo find / -name advancedsettings.xml". It should be in "~/.kodi/userdata/" Note that this file only works with Kodi >= v17.

Man, I don't understand a word you're saying... Sorry.That guide you're following seems to use an older version of OSMC or Kodi. It is a modified Raspbian Jessie. Try a recent version of OSMC, or try to install the Kodi 17 beta on OSMC: http://forum.kodi.tv/showthread.php?tid=265306

I use OSMC. I have to stop mediacenter withsudo systemctl stop mediacenterbefore calibration but it let me make the 5 dots and in SSH it shows me the calibration data. With the test it works fine. But after reboot there are no changes and it is like i never calibrated. What can i do?

Dear Bim , as tfw said , I also have the same situation. I have the updated Raspbian and kodi 17 , touchscreen works great at X but at kodi it is not working. I have 4.3 inch waveshare hdmi lcd. What is the reason causing this problem , can you help me please ? thanks...

Thanks for the fast reply. I have checked what you said and also I started whole process from the beginning again and this time it worked , i guess i did mistake before :) , and now i am facing with inverted X and Y axises problem. In a forum I saw a suggestion to fix this problem and I added lcd_rotate=2 instead of display_rotate=2 in /boot/config.txt . This time kodi is working correctly but X desktop is inverted. Do you have any idea about that ? Thank you again.

Unfortunately negative scale factor is not supported , I dont know that option to rotate display in X you talk about but when i search it , it is written to add lcd_rotate or display_rotate to the config.txt . is there another way ? can you explain it please ?

@Ulle => You must change event0 section... sometimes working event1 or event2 for me event3.. example;TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate to changeTSLIB_TSDEVICE=/dev/input/event3 ts_calibrate ; for this touch screen event...

And I have some problem... sudo usermod -a -G input kodi and usermod: user 'kodi' does not exist says in terminal(putty)... And I cant change any screen calibration... Touch work but calibration failed always. How can I do for this problem, "sudo usermod -a -G input kodi and usermod: user 'kodi' does not exist says" ??? I have raspbian on kodi and retropie ... What is problem ???

If you installed Raspbian and then Kodi on top, maybe the user name your start Kodi with is not "kodi" or "kodiuser". The important thing is to add the user you are starting / running Kodi with to the input group. See this to check: https://superuser.com/questions/336275/find-out-if-user-name-exists

Thank you so much Bim... I cant change my usermode kodi... But now working. My advancedsetting.xml file is different location. /usr/share/kodi/system. for now good working my touch screen on kodi. Thanks for all information...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.you can read here

Post a Comment

Popular Posts

Installing newer gcc/g++ versions is easy: sudo apt-get install gcc-4.7 g++-4.7
If your system does not provide the new versions, you might still be able to get them via a different repository. Add the toolchain repository to your system and update your sources:sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get update
Now you should be able to install gcc/g++. The real problem comes after that. How to make use of the newer versions?

Option #1 - Uninstall older versions
This is sometimes not an option, because lots of dependencies will be uninstalled which you might need, or you want to keep those versions around for compiling stuff that still uses them.

Option #2 - Use update-alternatives to switch versionsThis informative post describes it pretty well. I'll sum it up here. First remove all update-alternatives:sudo update-alternatives --remove-all gccsudo update-alternatives --remove-all g++
Now add update-alternatives for 4.6 and 4.7 and make the g++ configuration a s…

Sometimes you are in the need to read back the OpenGL backbuffer, or other framebuffers. In my case the question was how to read back a downsampled framebuffer resp. its texture to system memory. There are different methods for this and I wrote a small benchmark to test them on various systems.

UPDATE #1: A thing I've totally overlooked is that you can actually blit the backbuffer to the downsampled framebuffer directly, saving you the FBO overhead (memory, setup, rendering time). I've updated the page and the code reflecting that.UPDATE #2: The code now works on Windows and Linux (via GLX). Maybe I'll port it to GLES2 for the Raspberry Pi too... :)UPDATE #3: The code works on the Raspberry Pi now using OpenGL ES 2.0. Reading the framebuffer is quite slow though even with an overclocked device. It's not the actual reading that is slow, but that we have to render to another framebuffer first and back to the screen. Atm all buffers and textures use RGBA8888, which might s…