kdbdallas
Posts: 5
Joined: Tue Dec 15, 2015 10:29 pm

Official Touchscreen and Pygame

Tue Feb 16, 2016 1:04 am

I know there have been some other posts about the problems with the touchscreen and pygame, but nothing has really come from those posts, and they were all a while ago...

So I thought I would check back in since I just got my touchscreen and the entire reason I got it was to use it with the pygame app I am writing (Its a front-end for Mopidy and/or Musicbox) and without proper touches its not very useful.

I did see the ft5406 project for multitouch, but I don't need multitouch.
Plus I tried to get it to work in my project for single touches and still wasn't able to get it to track correctly.

Really hoping that there is something that can be done here...
Thanks!

kiltjim
Posts: 9
Joined: Mon Jan 28, 2013 1:53 am

Re: Official Touchscreen and Pygame

Tue Feb 16, 2016 5:06 pm

I too am having issues with the touchscreen and accuracy under python, pygame, and the command line. I'm not running it with any windows manager (X, etc.), so that might be one problem. But then I didn't want to need to startx if I didn't have to.

It seems to me that with the following code, the x-scaling is off. The closer I get to the left side of the screen, the farther off the touch-to-screen alignment is. Also, the y-scaling is off slightly, but not nearly as much as the x-axis.

Code: Select all

#! /usr/bin/env python

import pygame

LEFT = 1

running = 1
screen = pygame.display.set_mode((800, 480))

while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running = 0
    elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
        print("You pressed the left mouse button at (%d, %d)" % event.pos)
    elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
        print("You released the left mouse button at (%d, %d)" % event.pos)

    #screen.fill((0, 0, 0))
    pygame.display.flip()
I did find a reference to:
/etc/pointercal

Code: Select all

/etc/pointercal

34263 -38443 -81462 3200 -3591 3959 65536^@
somewhere in my search, and might give editing that a go if I can't find a more elegant solution. This would all be plug and tweak in order to get it to work though.

I also tried:
ts_calibrate

But, returns "ts_open: No such file or directory" Even if I export the appropriate environment variables.

I don't need multi-touch either. I just want my cursor to click where I do!

DirkS
Posts: 10096
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Official Touchscreen and Pygame

Tue Feb 16, 2016 5:38 pm

kiltjim wrote:I also tried:
ts_calibrate

But, returns "ts_open: No such file or directory" Even if I export the appropriate environment variables.
Make sure all the programs are installed:

Code: Select all

 sudo apt-get install evtest tslib libts-bin
then try

Code: Select all

sudo evtest
Run ts_calibrate like this:

Code: Select all

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate
But you may have to change the environment variables. Not sure how the RPF display is set up.

kdbdallas
Posts: 5
Joined: Tue Dec 15, 2015 10:29 pm

Re: Official Touchscreen and Pygame

Wed Feb 17, 2016 3:50 am

DirkS wrote: Make sure all the programs are installed:

Code: Select all

 sudo apt-get install evtest tslib libts-bin
then try

Code: Select all

sudo evtest
I ran the above and already had everything installed, and the values from evtest look to be correct.
DirkS wrote: Run ts_calibrate like this:

Code: Select all

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate
But you may have to change the environment variables. Not sure how the RPF display is set up.
When I try and run ts_calibrate (with the env variables set correctly in front) I get a message that shows the correct width and height of the screen but then says that the display is not a touchscreen.
So when I then touch the screen nothing happens. (but the calibration screen is showing on the screen, it just is not interactive)

That said, it seems like since the values from evtest looked correct that it is not an issue with overall calibration but instead with pygame calibration or something else pygame specific, but not console specific.

bullwinkle
Posts: 117
Joined: Wed Jan 09, 2013 12:14 pm

Re: Official Touchscreen and Pygame

Wed Feb 17, 2016 4:52 am

Hello
I don't have the official touchscreen but I expect it is the general pygame problem under Jessie.

The following worked for me, but be careful with your own data.
viewtopic.php?f=32&t=131889&p=879999#p879999
more details here https://forums.adafruit.com/viewtopic.p ... 58#p435225

kdbdallas
Posts: 5
Joined: Tue Dec 15, 2015 10:29 pm

Re: Official Touchscreen and Pygame

Wed Feb 17, 2016 6:06 am

bullwinkle wrote:Hello
I don't have the official touchscreen but I expect it is the general pygame problem under Jessie.

The following worked for me, but be careful with your own data.
viewtopic.php?f=32&t=131889&p=879999#p879999
more details here https://forums.adafruit.com/viewtopic.p ... 58#p435225
This didn't do anything good for me.
In fact it made it so the touchscreen stopped working at all.

One idea I did have that I had a little bit of success with is I changed my sdl_mousedrv from TSLIB to FT5406.
This did NOT fix the problem but it "fixed" it about half way.
It's possible to actually click on buttons with one or two "clicks". (most of the time)

Closer but no cigar.

mattcamp
Posts: 2
Joined: Wed May 25, 2016 10:42 pm

Re: Official Touchscreen and Pygame

Wed May 25, 2016 10:45 pm

Did anyone ever get this screen working with pygame?

chickentech
Posts: 4
Joined: Mon Sep 19, 2016 12:33 am

Re: Official Touchscreen and Pygame

Mon Sep 19, 2016 12:36 am

I am running into this same problem - spurious clicks in pygame. Trying to use this all to run Octoprint on a Raspberry Pi 7" official touchscreen. If this has been resolved, I can't find it on the internet anywhere..

sl46
Posts: 4
Joined: Fri Oct 07, 2016 6:52 am

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 6:56 am

I think I have the exact same problem.
The clicks are fine when running under x (unusable as the frame rate slows to 3-6 FPS) but when running without X the clicks are either random or occasionally appear to be slightly up and left of where I actually click.
Interestingly I don't have a /dev/input/touchscreen folder and not sure how to go about getting one!

Has this been resolved yet?

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 7:27 am

DELETED COMMENT.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

sl46
Posts: 4
Joined: Fri Oct 07, 2016 6:52 am

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 12:59 pm

Hi,

Thanks for your reply - unfortunately none of the solutions here worked for me.
Noticing that the touchscreen was accurate in evtest I found the following library which allows the interface to be managed from directly within Python.

https://github.com/pimoroni/python-multitouch

Well worth a look if you are hitting these problems.

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 1:19 pm

sl46 wrote:Hi,

Thanks for your reply - unfortunately none of the solutions here worked for me.
Noticing that the touchscreen was accurate in evtest I found the following library which allows the interface to be managed from directly within Python.

https://github.com/pimoroni/python-multitouch

Well worth a look if you are hitting these problems.
Aaaah. I took a look at my code - it's been a while since I was involved with it, and you are right - that is how I overcame the issue.
However I still had a problem with the cursor. I also had to move over to python3 in order to use that method.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

sl46
Posts: 4
Joined: Fri Oct 07, 2016 6:52 am

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 1:21 pm

Yeah - I also removed the mouse pointer which makes a neat solution and reversed the code to run under Python 2.7.
Alls well that ends well.

Thanks again

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 1:46 pm

sl46 wrote:Yeah - I also removed the mouse pointer which makes a neat solution and reversed the code to run under Python 2.7.
Alls well that ends well.

Thanks again
Do you have any details on the code 'downgrade' ?
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

sl46
Posts: 4
Joined: Fri Oct 07, 2016 6:52 am

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 1:49 pm

Yes - amazingly simple ....

Line 10 of ft5406.py:
import queue (Python 3.x) to import Queue (Python 2.x)

Works a treat!

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Official Touchscreen and Pygame

Fri Oct 07, 2016 1:53 pm

sl46 wrote:Yes - amazingly simple ....

Line 10 of ft5406.py:
import queue (Python 3.x) to import Queue (Python 2.x)

Works a treat!
LOL. I remember seeing the error relating to queue before switching to python3. If only I knew.
Thanks,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Official Foundation Display”