Apr 042014
 

This is a quick introduction how to calibrate our touchscreen.

display-bausatz-einzelteile

I freely admit this is heavily based on Adafruit’s tutorial – I hope we will be able to return the favour for you guys one day!

I suggest for you to run the commands in the following tutorial in a separate SSH shell, opened from an additional computer (why not simply buy a second Raspberry Pi from you-know-whom?) .

Also, the commands in this tutorial are supposed to be run as root! –> “sudo su” gets you into the root user from the pi user.

Some background information:

Our touchscreen is based on the ADS7843 (compatible with ads7846 driver) chip, which you can see being activated (on our image) by calling lsmod:

sudo lsmod

Module                  Size  Used by
fuse                   76348  3
evdev                   9407  4
joydev                  9084  0
ads7846                 7849  0
ads7846_device          6049  0
spi_bcm2708             4728  0
snd_bcm2835            16165  0
snd_soc_bcm2708_i2s     5474  0
regmap_mmio             2806  1 snd_soc_bcm2708_i2s
snd_soc_core          131356  1 snd_soc_bcm2708_i2s
regmap_spi              1897  1 snd_soc_core
snd_pcm                81585  2 snd_bcm2835,snd_soc_core
snd_page_alloc          5156  1 snd_pcm
regmap_i2c              1645  1 snd_soc_core
snd_compress            8108  1 snd_soc_core
snd_seq                53769  0
snd_timer              20133  2 snd_pcm,snd_seq
snd_seq_device          6473  1 snd_seq
leds_gpio               2059  0
led_class               3688  1 leds_gpio
snd                    61299  7 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress

/dev/input/event0

This driver “delivers” the finished information to the device /dev/input/event0 – you can verify this by doing

sudo cat /dev/input/event0

and touching the touchscreen (preferably with our stylus!) – it will spew out a garble of binary information on each touch. Use Ctrl + C to terminate the command.

Note: If this command does not react to input from the touchscreen, try moving your mouse / typing on the keyboard you’ve attached to the Raspberry Pi –> it may be assigned differently on your system. Adjust the following commands accordingly … !

/dev/fb1

Our touchscreen is set up as framebuffer device 1 – you can test this like this:

cat /dev/zero > /dev/fb1

Will turn your little screen black (and give you an error message to go with it, free of charge, naturally).

libts

Tslib is a library which serves as common abstraction layer for events on touchscreens. It includes filters (for instance for smoothing the events and calibrating).

Calibration

Install the touchscreen utilities (Tslib):

aptitude install libts-bin

This will create a configuration file, /etc/ts.conf, which you might want to modify some day (have a look at the manpage first, maybe).

In order to use ts_calibrate and ts_test, you need to set environment variables.

export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_FBDEVICE=/dev/fb1

This will set them temporarily for the current user and current console you’re working on.

Then, start the calibration process:

ts_calibrate

This will show a screen with a crosshair. And instructions.

Touch the crosshair’s center with your stylus. Repeat the procedure, until the software exits.

The calibration data will be shown on your console. It will look something like this:

xres = 320, yres = 240
Took 16 samples…
Top left : X = 3110 Y =  934
Took 6 samples…
Top right : X =  696 Y =  979
Took 14 samples…
Bot right : X =  711 Y = 3163
Took 10 samples…
Bot left : X = 3161 Y = 3115
Took 8 samples…
Center : X = 1915 Y = 2070
330.695190 -0.090429 0.001365
-13.946960 0.001227 0.064123
Calibration constants: 21672440 -5926 89 -914028 80 4202 65536

 

This data will be written to the calibration file /etc/pointercal :

root@raspberrypi:/home/pi# cat /etc/pointercal
-5926 89 21672440 80 4202 -914028 65536536

Test

You can test the calibration using

ts_test

This will display a crosshair for you to move and drag around. You can also switch to drawing mode, and draw something.

Do not forget to set up the environment variables, if you run the command from another console.

 

X-Calibration and further knowledge

Please refer to Adafruit’s tutorial. The section on calibrating X is also applicable to our display.

The symlinking of the input device (/dev/input/event0 to /dev/input/touchscreen) mentioned in the tutorial will not work with our touchscreen and it’s current driver, the command has to be modified for that.

Troubleshooting

evtest

Evtest can help you to troubleshoot device input.

Install it using

aptitude install evtest

run it on the device you want to test, e.g. what the touchscreen should default to:

evtest /dev/input/event0

This will show you more information than the crude “cat” test suggested at the beginning of this article. It will also allow you to see keyboard events from your keyboard if you have one attached to the Pi (use /dev/input/event1 if you attached it as first USB device, before a different input device).

 

ts_test:

/dev/touchscreen/ucb1x00: No such file or directory

This error message will show, if you did not set the environment variables. Keep in mind, that you either have to set them manually from each (!) console / user (!) you open or operate as, or permanently in the appropriate location.

Check which environment variables are set by using:

set

you should see

TSLIB_FBDEVICE=/dev/fb1
TSLIB_TSDEVICE=/dev/input/event0

amongst the other output.

 

ts_calibrate:

ts_open: No such file or directory

This error message will show, if you did not set the environment variables. Keep in mind, that you either have to set them manually from each (!) console / user (!) you open or operate as, or permanently in the appropriate location.

Check which environment variables are set by using:

set

you should see

TSLIB_FBDEVICE=/dev/fb1
TSLIB_TSDEVICE=/dev/input/event0

amongst the other output.

 Posted by at 10:37 pm
  • Emmery Rugge

    tried this, what a mess

Optimization WordPress Plugins & Solutions by W3 EDGE