Magimedia
Posts: 33
Joined: Sun Feb 22, 2015 8:31 pm

5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 4:55 pm

I have a SpotPear 5inch HDMI Touchscreen

Good news - It works - screen is lovely and crisp with good colour, and responding to touch events.
Bad news - Coordinates are miles off!

I'm using Python with Pygame from the console (no X server), and all the calibration tools I've found so far, including those supplied on the image, only work within X.

I found a post that suggested Pygame uses SDL, and that tslib can calibrate it... but tslib complains
"ts_open: no such file or directory"

My touchscreen appears on /dev/input/mouse1 or /dev/input/mouse0 depending on whether I have a USB mouse plugged in or not. There is no /dev/fb1 presumably because the screen just connects to the HDMI.

I thought initially I could read coordinates in python and just compensate myself, but this doesn't work, because the "rectangle" the coordinates are within shifts when you reach the edge of the screen. (I can explain this more if required)

Any ideas as to how I can calibrate?

User avatar
saper_2
Posts: 240
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: 5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 5:33 pm

Hi,

I have some 5" lcd, and I had to calibrate it too (and write (well, just copy-paste ;) ) driver in python that translates data from /dev/rawinput to /dev/modse or something like that). See my repo: https://github.com/saper-2/rpi-5inch-hd ... een-driver I hope it'll give you some hints :) .
For calibrating, see src code of tslib, there is in linear.c or something like that .c file with equations. You can get constants needed by equations from ts_calib .

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: 5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 5:41 pm

Have you set TSLIB_TSDEVICE?

Magimedia
Posts: 33
Joined: Sun Feb 22, 2015 8:31 pm

Re: 5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 6:24 pm

I have the following environment variables set:
TSLIB_CONFFILE=/etc/ts.conf
TSLIB_CALIBFILE=/etc/pointercal
TSLIB_FBDEVICE=/dev/fb0
TSLIB_TSDEVICE=/dev/input/event1

I can verify that event1 is the touchscreen.

@saper_2 - The only thing I can think to do is install python_dev and evdev, then attempt to read /dev/input/event1 to decode events... am I on the right lines?

Magimedia
Posts: 33
Joined: Sun Feb 22, 2015 8:31 pm

Re: 5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 7:34 pm

Well I can find it and read it now... that's a start!

Code: Select all


import evdev

TDev = False
print "Looking for touch screen..."

devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
	if device.name=="ADS7846 Touchscreen":
		TDev = device

if not TDev:
	print "No touchscreen found."
	quit()

print "Found " + TDev.name + " on "+TDev.fn

mx=-1
my=-1
mp=-1
for event in TDev.read_loop():
	if event.type == evdev.ecodes.EV_ABS:
		if event.code == 0:
			mx = event.value
		elif event.code == 1:
			my = event.value
		elif event.code == 24:
			mp = event.value
	print "X : " + str(mx) + "   Y : " + str(my) + "   Pressure : " + str(mp)


Magimedia
Posts: 33
Joined: Sun Feb 22, 2015 8:31 pm

Re: 5inch HDMI Touchscreen - SDL calibration?

Fri Jun 17, 2016 8:05 pm

Threaded version... in case anyone else finds it useful.
Time for food, coffee, and then maybe work out how to do calibration.

Code: Select all


import evdev
import thread
import sys

TDev = False
print "Looking for touch screen..."

devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
	if device.name=="ADS7846 Touchscreen":
		TDev = device

if not TDev:
	print "No touchscreen found."
	quit()

print "Found " + TDev.name + " on "+TDev.fn

TSx=-1
TSy=-1
TSp=False


def TouchReader( touchdevice ):
	global TSx,TSy,TSp
	mx=-1
	my=-1
	mp=-1
	for event in touchdevice.read_loop():
		if event.type == evdev.ecodes.EV_ABS:
			if event.code == 0:
				mx = event.value
			elif event.code == 1:
				my = event.value
			elif event.code == 24:
				mp = event.value
		TSx=mx
		TSy=my
		TSp=mp>0
	
try:
	thread.start_new_thread(TouchReader,( TDev, ) )
except:
	print "Error: unable to start touchscreen reader thread"
	quit()
	
while 1:
	print "X : " + str(TSx) + "   Y : " + str(TSy) + "   Pressure : " + str(TSp) + "              \r",
	sys.stdout.flush()


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