Tuesday, March 26, 2013

Murphy's Touchscreen

It was pretty straightforward to connect the touchscreen of my display to the Raspberry Pi. After plugging in the USB cable, the touchscreen reports itself as eGalax TouchScreen:

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0eef:0001 D-WAV Scientific Co., Ltd eGalax TouchScreen

Fortunately, there is a matching driver in the Linux kernel. It only wants to be activated. There are very detailed information about kernel compilation on the web, so I will skip that. In the configuration search for eGalax and activate the option for the corresponding USB driver (TOUCHSCREEN_USB_EGALAX).

After booting the new kernel, there should be a new device in /dev/input/by-id/ named usb-0eef_0001-event-if00. You can test it's functionality with

sudo evtest /dev/input/by-id/usb-0eef_0001-event-if00

Touching the touchscreen should produce some weird output (maybe you have to install evtest first). No further configuration is necessary at this point, everything will be detected automatically. It's time for startx:

I can touch the screen and the cursor moves - not to the position where my finger is, but this is only a matter of calibration. But, before I could start with that, the cursor stopped moving... I tried to reboot the Raspberry Pi, tested it at my PC, but the cursor does no longer react. I gave up and tested it again some time later. Surprise, surprise: It works again, but not for a long time. Furthermore, the evtest does no longer produce any output. Only sometimes it reports

Event: time 1364289593.457921, -------- SYN_REPORT --------
expected 16 bytes, got -1 

This is the same result as unplugging the USB cable. It looks very much as a hardware defect. I also recognized, that the case gets quite hot. Therefore, I opened the case:

There are three cable bundles coming out of the thick cable. It seemed very likely that two of them are for the TFT and one is for the touchscreen. Typically enough, the one for the touchscreen has four wires just like USB and the touchscreen still works when I unplug the two other connectors. We can focus on the little extra board sitting on top of the main board.

At the bottom you can see the USB cable, at the top the connector to the touchscreen. It seems to be a 4-wire resistive touchscreen. As the name implies, you only have to measure the resistance between the wires and calculate the touch position from that. There is a nice application note from Atmel about that topic. I measured the resistance between two of the pins marked in the picture above using a multimeter. The resistance changes when I touch the screen. There is also a small LED that lights up when I touch the screen (while the touchscreen is connected to the computer), but this only happens when the cursor also moves.

I don't think that I can fix the controller itself, but maybe I can connect another controller to the touchscreen some day, but until then I still own Murphy's touchscreen.