Page 1 of 1

Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Tue Aug 27, 2019 4:59 am
by peppy.player
The current version of the Pygame library leverages libsdl1.2. The version of the libsdl1.2 on Raspbian Buster OS has the issues with touchscreens. One of the solutions is to build that library with proper touchscreen support. This solution was suggested by Gerhard the author of NewtronRadio https://forum-raspberrypi.de/forum/thre ... tron-radio On his behalf I'm creating this post hoping that it will be also helpful for other developers.

You can either download the patched libsdl1.2 package from the Gerhard's Dropbox account:
https://www.dropbox.com/s/0tkdym8ojhcmb ... _armhf.deb
and then install the package:

Code: Select all

wget https://www.dropbox.com/s/0tkdym8ojhcmbu2/libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
sudo dpkg -i libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
sudo apt-get -f install
Or you can build that library yourself by following these steps:

1. Install libts-dev

Code: Select all

sudo apt install libts-dev

2. Get the required packages

Code: Select all

wget http://deb.debian.org/debian/pool/main/libs/libsdl1.2/libsdl1.2_1.2.15+dfsg2.orig.tar.gz
wget http://deb.debian.org/debian/pool/main/libs/libsdl1.2/libsdl1.2_1.2.15+dfsg2-4.debian.tar.xz

3. Extract the packages

Code: Select all

tar xvzf libsdl1.2_1.2.15+dfsg2.orig.tar.gz
cd SDL-1.2.15
tar xvfJ ../libsdl1.2_1.2.15+dfsg2-4.debian.tar.xz

4. Install libSDL dependencies (can be found in debian/control)

Code: Select all

sudo apt install libx11-dev libxext-dev libxt-dev libxv-dev x11proto-core-dev libpulse-dev libgl1-mesa-dev libasound2-dev libcaca-dev libglu1-mesa-dev

5. Install packages for building .deb-packages

Code: Select all

sudo apt install build-essential debhelper

6. Add libts-dev to the "Build-Depends:"-section and to the "Depends:"-section for "Package: libsdl1.2-dev" in /home/pi/SDL-1.2.15/debian/control

7. Remove the "opts="-line in /home/pi/SDL-1.2.15/debian/watch so that it looks like this:

Code: Select all

# run "uscan --report" to check or "gpb import-orig --uscan" to update
version=4
https://www.libsdl.org/release/SDL-([\d.]+)\.tar\.(?:gz|bz2|xz|lzma)
8. Edit /home/pi/SDL-1.2.15/debian/changelog (add to top)

Code: Select all

libsdl1.2 (1.2.15+veloci1-1) unstable; urgency=medium

  * re-add support for libts
  
 -- veloci <veloci@gmx.de>  Thu, 11 Jul 2019 11:12:13 +0200
 
9. Rename libsdl1.2_1.2.15+dfsg2.orig.tar.gz to libsdl1.2_1.2.15+veloci1.orig.tar.gz

Code: Select all

mv /home/pi/SDL-1.2.15/libsdl1.2_1.2.15+dfsg2.orig.tar.gz /home/pi/SDL-1.2.15/libsdl1.2_1.2.15+veloci1.orig.tar.gz

10. Build the whole thing (in folder /home/pi/SDL-1.2.15)

Code: Select all

debian/rules clean
dpkg-source -b .
debian/rules build

11. Create the packages (in folder /home/pi/SDL-1.2.15)

Code: Select all

fakeroot debian/rules binary
12. Install new package

Code: Select all

cd ..
sudo dpkg -i libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
Many thanks to Gerhard for the suggested solution!

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Fri Sep 06, 2019 2:52 pm
by JKOORNNEEF
I have serious problems with your solution on my configuration: Buster, RPi B+, Linux 4.19.58+, Python 2.7.16, Pygame 1.9.4.post1, Watterott 2.8".
The initial installation of your precompiled libsdl1.2debian_1.2.15+veloci1-1_armhf.deb package failed due to the absence of libts0. After installing libts0_1.19-1_armhf.deb a rerun of your .deb completed.
But now, my Python script exits from Python with the "Illegal instruction" message directly after "import pygame".
I have been struggling with getting the touch capability to work for weeks, and would like your solution to work. Can you help?

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Sun Sep 15, 2019 12:31 pm
by veloci
What does "dpkg -s libsdl1.2debian" show?

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Fri Jan 03, 2020 12:04 am
by eorange
Has anyone had success with getting this solution to work? I have a 3B+ with an Adafruit PiTFT 3.5" running Buster Lite. I'm using pygame with python 3. Everything about pygame works except for the erratic and random mouse positions provided by pygame.mouse.get_pos().

I tried the pre-built and build-your-own examples provided by the OP, both on a clean Buster lite install. Each procedure completely successfully, but...there's no improvement. The mouse positions are still random.

What am I missing here? Thanks in advance.

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Thu Jan 30, 2020 9:58 pm
by toddboyland
I ran into the same issue w/ pygame on a Raspberry Pi.
In the OS, the touchscreen works fine.
When the python/pygame script it run the touchsreen is extremely erratic.
I tried wheezy, jessie, stretch, and buster (lite, and full OS) on Raspberry Pi version 3's & Pi 4 hardware platforms.

My solution ended up being related to how the .py script was started.
When I manually executed the .py script from ssh (as sudo due to permission issue), the touchscreen was erratic.
Example: /usr/bin/python3 /home/pi/foldername/script.py

When I schedule the script using crontab -e (as pi user), the touchscreen was erratic.
Example entry in cron: @reboot /usr/bin/python3 /home/pi/foldername/script.py

When I configure autostart the touchscreen finally works well.
Configure autostart: (must be performed as pi user, as sudo causes changes in file permissions)
mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/script_name.desktop

[Desktop Entry]
Type=Application
Name=script_name
Exec=/usr/bin/python3 /home/pi/foldername/script.py

Hopefully this helps someone else, as it took a long time to narrow down.

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Fri Jan 31, 2020 12:56 am
by peppy.player
The patched library works fine for all Peppy player disk images:
https://github.com/project-owner/PeppyP ... isk-Images

I download it from the Dropbox account mentioned in the first post.

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Posted: Tue Jul 14, 2020 7:01 pm
by VinceTaglia
Thank you for this! I was able to get this old Pygame alarm panel working! Much simpler solution than the script Adafruit tells you to run that doesn't actually work anymore.

https://github.com/vincenttaglia/mqtt-control-panel