WaveShare 5 inch Resistive Touch Screen LCD, HDMI interface, Designed for Raspberry Pi

based on AR1100 4 wires

I encountered problems to apply this driver derekhe/waveshare-7inch-touchscreen-driver to my 5" screen so I made a few modifications.


pi@raspberrypi ~ $ dmesg

[ 1248.788452] usb 1-1.5: USB disconnect, device number 5
[ 1251.838038] usb 1-1.5: new full-speed USB device number 6 using dwc_otg
[ 1251.941352] usb 1-1.5: New USB device found, idVendor=0eef, idProduct=0005
[ 1251.941382] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1251.941397] usb 1-1.5: Product: By ZH851
[ 1251.941412] usb 1-1.5: Manufacturer: RPI_TOUCH
[ 1251.941426] usb 1-1.5: SerialNumber: \xffffffc2\xffffffa7\xffffffa7\xffffffc2\xffffff88\xffffff88P601084166
[ 1251.948412] hid-generic 0003:0EEF:0005.0004: hiddev0,hidraw0: USB HID v1.10 Device [RPI_TOUCH By ZH851] on usb-bcm2708_usb-1.5/input0

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9514 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 046a:0023 Cherry GmbH CyMotion Master Linux Keyboard
Bus 001 Device 006: ID 0eef:0005 D-WAV Scientific Co., Ltd
pi@raspberrypi ~ $

First, obtain min and max values for calibration, the easiest way is to use touch.py script. To get min x and y press screen in left upper corner. To get max x and y press screen in right lower corner respectively.

pi@raspberrypi ~ $ sudo /usr/bin/touch.py
Waiting device
Device found /dev/hidraw0
Read buffer
True 149 220
Left click
True 139 209 <-- upper left min x,y
True 140 207
False 0 0
Release
True 171 296
...
...
Left click
True 3936 3934 <-- lower right max x,y
True 3940 3921
False 0 0
Release




See my modifications below /usr/bin/touch.py :

...
        while True:
            try:
                b = f.read(22)  # was 25
                (tag, btnLeft, x, y) = struct.unpack_from('>c?HH', b)
		x-=140 # x offset min(x)
		y-=210 # y offset min(y)
		# screen is 800x480 px 
		x=int(x/4.75) # x_scale=(max(x)-min(x))/800=(3940-140)/800=4.75
		y=int(y/7.73) # y_scale=(max(y)-min(y))/480=(3920-210)/480=7.73
                print(btnLeft, x, y)
            except:
                print('failed to read from deviceFound' + str(deviceFound))
                return
...
restart service

/etc/init.d/touch.sh restart

Now touch screen should correctly emulate mouse.
Czas generowania strony : 0.004 s