pinkstond
Posts: 13
Joined: Mon Sep 17, 2012 9:59 pm

Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Fri Nov 08, 2019 10:03 pm

I have a cheap capacitive 4.3" screen from China that the touch panel is I2C. I have verified that the PI sees it via i2cdetect and it is outputting values as expected, which I have verified by running a script similar to one I've taken off of another post. Here is the script:

Code: Select all

import smbus, os
from time import sleep
bus = smbus.SMBus(1)
addr = 0x2e #Address of the TP on the I2C bus

while True:
    Y = str(bus.read_byte_data(addr,0x04)) #Y Axis
    if (Y == "255"):
      Y = ''
    X  = str(bus.read_byte_data(addr,0x06)) #X axis
    if (X == "255"):
      X = ''

    YZ = str(bus.read_byte_data(addr,0x03)) #Y Axis Zone. 128(top) - 129(bottom)
    if (YZ == '64'):
        YZ = 'None'
    elif (YZ == '128'):
        YZ = 'Top'
    elif (YZ == '129'):
        YZ = 'Bottom'

    XZ = str(bus.read_byte_data(addr,0x05)) #X Axis Zone. 0(left) - 1(right)
    if (XZ == '1'):
        XZ = 'Left'
    elif (XZ == '0'):
        XZ = 'Right'

    os.system('clear')
    print('YZ : '+ YZ)   #Y Zone
    print('Y  : '+ Y)  #Y value from 0-255
    print('XZ : '+ XZ)   #X Zone
    print('X  : '+ X)  #X value from 0-255
    print(' ')

    sleep(0.05)
When I run the script above, I see the expected values on the screen when I'm touching the appropriate parts of the screen. How, do I turn those values into movements and clicks (taps)? There are drivers out there for similar screens of different sizes, on different buses, but I've searched and searched for days and I cannot find anything that works for this TP. If you can help, I will buy you a beer!

pinkstond
Posts: 13
Joined: Mon Sep 17, 2012 9:59 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Fri Nov 08, 2019 10:10 pm

Or maybe there's an easy way to create a script or something that will mimic touch/mouse input based on the information I've already gathered? Any solution that gets the job done for now, I'm very ok with as this is just a proof of concept project I'm working on at the moment.

trejan
Posts: 740
Joined: Tue Jul 02, 2019 2:28 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Fri Nov 08, 2019 10:36 pm

Which touchscreen controller IC is being used?


trejan
Posts: 740
Joined: Tue Jul 02, 2019 2:28 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Sat Nov 09, 2019 9:20 pm

pinkstond wrote:
Sat Nov 09, 2019 2:46 pm
CHSC6440
Google, Baidu, Aliexpress and Taobao don't recognise that part number at all. Are there any other markings on the chip? Do you have a link to the display?

pinkstond
Posts: 13
Joined: Mon Sep 17, 2012 9:59 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Mon Nov 11, 2019 2:20 am

No link to the display as it's a custom designed display manufacturered in China. I'll see if I can get a photo of the IC for you tomorrow, but you'll likely not find any documentation on the IC. It's not well documented.

Is there anything that can be done without already made drivers? I mean, I'm getting the correct values in the scripted pasted above. So I should be able to create something that takes those values and turns them in mouse/input actions.

pinkstond
Posts: 13
Joined: Mon Sep 17, 2012 9:59 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Mon Nov 11, 2019 2:24 pm

Image

Here's the IC. If the img url isn't working, it can also be found here:
https://photos.app.goo.gl/bhrgkBLhiGE2jmeG8

pinkstond
Posts: 13
Joined: Mon Sep 17, 2012 9:59 pm

Re: Chinese I2C Touchscreen panel HELP please! I'll owe you a beer

Tue Nov 12, 2019 10:54 pm

Ok, I've used python and xdotool to pickup the touch panel values, convert it, and submit it to xdotools for the input I'm looking for. So this will get the job done for now. Here's the python for anyone interested:

Code: Select all

import smbus
import time
import subprocess

bus = smbus.SMBus(1)

# For knowing your screens memory address type on the terminal: i2cdetect -y 1
addr = 0x2e # Memory address of the peripheral.
clicked = False # A boolean variable for the click algorithm.

while True:
  tp = bus.read_byte_data(addr,0x02)   #Number of active touch points.
  YZ = bus.read_byte_data(addr,0x03)   #Vertical zone of point 1: 128-132
  Y = bus.read_byte_data(addr,0x04)    #Vertical value of point 1 in the previously measured horizontal zone: 0-255
  XZ = bus.read_byte_data(addr,0x05)   #Horizontal zone of point 1: 0-3
  X = bus.read_byte_data(addr,0x06)    #Horizontal value of point 1 in the previously measured vertical zone: 0-255

  if tp == 1 and YZ >= 128 and clicked == False:    #Entry only if 1 touch point is detected and if it is located into the digitizer active area.
    #On this partical touchpanel, the X axis was reveresed and has a maximum usable resolution of 479X272
    horiz1 = (XZ * 255) + X
    horiz = 479 - horiz1  #Get the final X axis value for xdotool
    vert = (YZ -128) * 255 + Y #Get the final Y axis value for xdotool

    subprocess.call(["xdotool","mousemove",str(horiz),str(vert)])   #Move mouse to the desired point.
    subprocess.call(["xdotool","click","1"])    #Perform a mouse click event where the mouse is placed.
    clicked = True

  elif tp == 0 and clicked == True:  #No touch points are detected.
    clicked = False
  time.sleep(0.01)    #Time waiting for repeat the main loop.

Return to “Interfacing (DSI, CSI, I2C, etc.)”