Calibrating touch in Linux

One of the primary problem seen when integrating touch controller in Linux is calibration. I would like to introduce two different methods of calibration. Please use the table below to choose the correct tools

Tool name Application name Requirements Remarks
tslib ts_calibrate The touch device need to be exposed as /dev/input/eventX input device and a video framebuffer support like /dev/fbY is mandatory Standard for touchscreens on embedded ARM systems
xinput_calibrator xinput_calibrator Needs no special driver Used on X based devices with no frame buffer support

Calibrating touch using tslib in Linux

Calibrating touch using xinput_calibrator in Linux


Calibrating touch using xinput calibrator in Linux

Xinput_calibrator needs no special driver and is ideal for X based graphical interfaces.

Installing the tool

The tool can be installed form the standard repository of Ubuntu, Debian, Suse and RedHat flavours. For Debian based system use the command:

sudo apt-get install xinput-calibrator

The tools can be compiled from the sources, follow the steps described:

1. Clone the repository using the command.

git clone

2. As mentioned in the readme file, configure the build for the GUI library used in the system using the command

./ –with-gui=x11

3. Run the make command. The program will be built in the src folder.

Calibrating with single display

For calibrating the touch using the tool follow the steps described:

1. Run the command xinput_calibarator in the command prompt.

2. Graphics with a cross hair will be shown


3. Touch the cross hair until it turns from red to white.

4. Once the calibration has been completed for the 4 cross hairs, tool will exit automatically and the calibration information will be shown in the terminal. As mentioned copy the section in the file specified. An example of the same is shown below


As explained in the log store the portion marked in brown in the configuration file. This will be picked by the X org automatically.

Calibrating with multiple display

The process of calibrating with multiple displays involves mapping the display and the touch controller. Follow additional steps other than described above is needed:

1. Run xinput in terminal to get the id of input device


2. Run xrand in terminal to get the id of display

test@test-box:~$ xrand
Screen 0: minimum 8 x 8, current 3840 x 1080, maximum 32767 x 32767
eDP1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 382mm x 215mm
   1920x1080      60.0*+   59.9     40.0
DMI1 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 600mm x 340mm
   1920x1080      60.0*+   50.0     59.9
   1680x1050      59.9

3. In this case the display is eDP1 and the touch id is 12. Map the display to input using the command

xinput map-to-output 12 eDP1

4. Follow the steps in the section Calibrating with single display to complete the calibration

Calibrating touch using tslib in Linux

Tslib is a user-space based tool, written in C, used for calibrating touch in ARM based Linux system. Tslib acts as a thin layer between the drivers and the GUI, provides standard filters and provisions for adding new filters as plugins. .


  • Tslib needs the touch to be exposed as a device in the dev folder.
  • Calibration can only be performed on devices with frame buffer support.
  • Framebuffer needs write access.

Installing the tool

The tool can be installed form the standard repository of Ubuntu and Debian flavours, using the command:

sudo apt-get install libts-bin

or the tool can be compiled form sources. The steps described:

1. Clone the repository using the command.

git clone

2. Change to the tslib directory where the code was cloned. And run the command


3. Since tslib is generally used for cross compiled platforms like ARM the step here is described for the same. Run the command

./configure --prefix=/home/test-box/Project/tslib/output --host=arm-linux-gnueabi

Where the prefix denote the folder location of the build output will me stored.

4. Run the make and make install. This will copy the executables and the libraries in the prefix folder mentioned above.

Calibrating the touch

To calibrate the touch, follow the steps below:
1. Set the display (frame buffer), input device and config file to be used with the commands

export TSLIB_FBDEVICE=/dev/fbX
export TSLIB_TSDEVICE=/dev/input/eventY
export TSLIB_CONFFILE=/etc/ts.conf

X should be the number of the framebuffer mapped.
Y should be the event number.

2. Run the command ts_calibrate. A dark screen with cross hairs as shown is displayed. Touch at the 5 cross hairs to complete the calibration process.


3. The calibration can be tested using the ts_test utiliy.


4. The calibration is stored in the configuration file. Filters and plugins can be enabled using the ts.conf file.

module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

5. The X – Window system can be configure to use the touchscreen driver by adding a InputDevice section to /etc/x11/xorg.conf

Section "InputDevice"
    Identifier "tslib"
    Driver "tslib"
    Option "ScreenNumber"   "0"
    Option "Width"      "800"
    Option "Height"     "480"
    Option "Rotate"     "NONE"
    Option "TslibDevice"    "/dev/input/event0"
    Option "CorePointer"

Add hardisk to Oracle VirtualBox

I keep forgetting these steps so I decided to document them. Steps to add a extra hard disk space in Oracel virtual box. This is for Ubuntu

1. Add a hardisk using the option from virtual machine settings as shown


2. Start the virtual machine. Once the machine is up run the command to get the mname of the driver

sudo fdisk -l

In my case it is /dev/sdc

3. Partition the disk using the command

sudo fdisk /dev/sdc

Then use the command “n” to add a partition and “p” for primary partition. Use the default values (if you have no idea of what they are) and finally use “w” to write the partition table to the disk.

"The partition table has been altered!" 

message indicates partition is successful

4. Format the disk into the filesystem of your choice. I am using ext4 so the coomand is

sudo mkfs -t ext4 /dev/sdc1

5. Creating a mount point. I mount the disk at the location /media/etc_drive_2/ so I create a drive using the command

sudo mkdir /media/etc_drive_2/

6. For auto mount at every startup edit fstab

gksu gedit /etc/fstab

And add the following line

/dev/sdc1    /media/etc_drive_2  ext4    defaults     0        2

The name of the driver and folder name changes based on your system

7. Access permission. I have set the access permission for my login. To do so first mount the drive using the command

sudo mount /dev/sdc1 /media/etc_drive_2

And set access permission using

sudo chown -R USERNAME:USERNAME /media/etc_drive_2

replace USERNAME with correct username

For detailed reading and much more fun visit

An easy kernel development environment

This article which sounds like anti-oracle virtual box, but it wasn’t and highlighted the use of virtual box made me write this blog.

I have been a big fan of Oracle virtual box and indeed it’s the best Type2 hypervisor (based on features for x86) I have used. I would say qemu as the lightest and the fastest. When I started poking around on Linux kernel running over virtual box, my modules crashed and caused file-system corruptions. This led me to use a desktop machine as a Linux test machine. But I could not carry my test machine with me. And so, I have changed my environment to two virtual machines (test and development) using virtual box.

I will describe here how to Setup two virtual machines for Linux development environment

Please refer these links which describe how to :

  1. Build and test a module using the environment refer here.
  2. Change the kernel of test machine refer here
  3. Removing the kernel of test machine refer here

Overview of the setup:

  • Host OS is windows
  • Virtual box from Oracle
  • Ubuntu as the test and development Linux distribution


1. Downloads and software packages:

  • Download Oracle Virtual Box  and don’t forget the corresponding extension pack.
  • Download the Ubuntu ISO. I use Ubuntu 12.10. You can use Ubuntu 12.04 as it is LTS.

2. Virtual machines: Create two virtual machines,

  • Development machine with at least 20GB hard disk
  • Test machine with 4.5GB hard disk.

Refer the virtual box user guide if any doubts.

3. New network interface: Create a new host only adapter in the virtual box from Oracle VM Virtual Box Manager > File > Preferences > Network.


Create new adapter with the credentials as shown.


So the network adapter appears as shown


4. Tuning the test machine: Boot the test machine and strip it to bare minimum by removing the unnecessary software like games, Firefox etc. Even strip its GUI and make it text only using the grub as described here.

5. Setting up the network: With both the virtual machines stopped configure the network interface as shown.



Leave the first network adapter unaltered in the development machine. This interface will be used for downloading additional softwares.
Now start both the machines and get the IP of both machines using “ifconfig”. In my case development machine IP is 192.10.100 and test machine IP is 192.10.101. Ping both the machines from each other and verify the network connection.

6. First login: To login to the test machine using SSH install openSSH-client in your development machine using the command at a terminal

sudo apt-get install openssh-client

Now type the command at a terminal

ssh test@

I have used test as it is my user name on test machine. You will get a warning for the RSA when you login the first time

The authenticity of host '' can't be established.
RSA key fingerprint is b1:2d:33:67:ce:35:4d:5f:f3:a8:cd:c0:c4:48:86:12.
Are you sure you want to continue connecting (yes/no)?

Type yes

7. Test: You can test the setup by shutting down the test machine using the command after logging on to the machine on ssh

$ sudo poweroff

The Linux development environment is configured.

Please feel free to send me queries or improvements for this writeup. If you find this useful or useless please post your reply