Friday, October 27, 2017

Raspberry Pi and touchscreens...Updated for latest Raspian (Stretch)



I have done a few other projects...that I might document in the future...

But this one seemed particular useful for me.

A very long time ago (mid 2000's) I bought a ~13" touchscreen panel with USB controller that I then stuffed into a Sharp display.   I fiddled around with making it some kind of keyboard/mouseless interface.   But at the time the winXP interface was flakey, and we were a long way from win10 tiles.

So I kind of parked it off to the side.

About 3 years ago we packed up and moved a few hours south...a year later I needed a VGA screen just to test some computer outputs...I looked for this monitor, but had no idea what box it ended up in or if I gave it to Goodwill.

When we moved, a lot of things were tucked away in the 1car garage shop...Two large boxes were stacked in the corner.  One was full of the wifes craft stuff...I assumed the bottom one was more of the same.

Nope.  The bottom one was full of pieces and parts, packed away on moving day 3 years ago.   On top was this touchscreen modified monitor.

I saw it and knew I wanted to mount a Raspberry Pi on the VESA mounts behind the monitor.   But the big question was would the Pi access the USB touchscreen.

I have a HDMI to VGA adapter that works perfectly so I hooked that up, and plugged the USB into the Pi, then fired it up.   The display still worked perfectly...and the touchscreen was read by the Pi...

(Note: read about the onscreen keyboard at the bottom of this post)

BUT...the calibration was way out to lunch and reversed.

A quick googling later and I found exactly what I needed, and my display interface (that shows up when you LSUSB) was even the same as the writeup.

This is the entire writeup.   But I only needed to do the following and now it is working perfectly!

------------------------------------------------------

The first test is if your touchpad reacts at all to your input...if it does (even if wrong) then skip to CALIBRATION section.

With later versions of Jessie, and the new Stretch, not all touchpad drivers (well at least the one I needed) are not installed.

So I had to do the following ,based on this forum entry

Install Evdev.

sudo apt-get install xserver-xorg-input-evdev

Then go to...

cd /usr/share/X11/xorg.conf.d

and list the files

ls

Mine looked like this...

10-quirks.conf     10-evdev.conf      40-libinput.conf     99-fbturbo.conf

The fix is to put the evdev.conf file after the libinput.conf file...the way to do that is...

sudo mv 10-evdev.conf 45-evdev.conf

then when you do an ls you get something like...

10-quirks.conf      40-libinput.conf   45-evdev.conf   99-fbturbo.conf

Finally reboot that, and the touchscreen should now be working...just out of calibration.

(In the calibration below one of the axis was reversed, when I did this on the Stretch install, they were not reversed)


---------------CALIBRATION-----------------------------

Calibration for the touchscreen(in Raspberry PI).
Note: The next steps are performed in the Raspberry PI's Debian Wheezy. This is a method for calibrating the touchscreen which will work just for Xserver and Xserver based applications.

Install xinput_calibrator.
Install some dependencies:

sudo apt-get install libx11-dev libxext-dev libxi-dev x11proto-input-dev

Download xinput_calibrator somewhere in the Raspberry PI's folder structure.

wget http://github.com/downloads/tias/xinput_calibrator/xinput_calibrator-0.7.5.tar.gz

Unpack it and then navigate to the unpacked folder and then install it using:

./configure
make
sudo make install

After this step you should run xinput_calibrator(from Xserver terminal console: first startx then open console and then run it).

xinput_calibrator

Follow the on screen instructions(touching some points on screen) and after calibration is complete you will receive a message like this:
Calibrating EVDEV driver for "eGalax Inc. USB TouchController" id=8
    current calibration values (from XInput): min_x=1938, max_x=114 and min_y=1745, max_y=341

Doing dynamic recalibration:
    Setting new calibration data: 121, 1917, 317, 1741


--> Making the calibration permanent <-- p="">  copy the snippet below into ...
<-- p="">
Section "InputClass"
    Identifier    "calibration"
    MatchProduct    "eGalax Inc. USB TouchController"
    Option    "Calibration"    "121 1917 317 1741"
    Option    "SwapAxes"    "1"    (only needed if the axis is incorrect...0 if correct)
EndSection


For Raspbian you have to create a file:

sudo nano /usr/share/X11/xorg.conf.d/01-input.conf

Add in this file the content above(starting with Section "InputClass" line) and then save it(ctrl+O).

Note:
Please make sure that you don't have sections like
MatchProduct    "eGalax Inc. USB TouchController"
in other files from /usr/share/X11/xorg.conf.d/ folder(highest number files are processed last, thanks to Jasmin).

Now touchscreen should be calibrated and after reboot it will keep the settings.
Once, I had to run xinput_calibration again in order to have the pointer to the desired points. You can update the numbers given by the xinput_calibration utility in the
usr/share/X11/xorg.conf.d/01-input.conf file in order to have the best calibration at boot.



------------------------------

Onscreen keyboard.

sudo apt-get install matchbox-keyboard

For some reason, sometimes the keyboard shows up in MENU > ACCESSORIES

This page describes how to display the icon using MENU > PREFERENCES. Main Menu Editor


In my case the Keyboard was already selected, I unselected it, re-selected it, and rebooted...then the icon showed up in the menu.