User avatar
Posts: 237
Joined: Mon Mar 07, 2016 6:10 am

Solution for Pygame and Touchscreens on Raspbian Buster OS

Tue Aug 27, 2019 4:59 am

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 ... 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: ... _armhf.deb
and then install the package:

Code: Select all

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


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
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 <[email protected]>  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!

Posts: 1
Joined: Fri Sep 06, 2019 2:28 pm

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Fri Sep 06, 2019 2:52 pm

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?

Posts: 1
Joined: Mon Mar 16, 2015 1:11 pm

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Sun Sep 15, 2019 12:31 pm

What does "dpkg -s libsdl1.2debian" show?

Posts: 1
Joined: Thu Jan 02, 2020 10:52 pm

Re: Solution for Pygame and Touchscreens on Raspbian Buster OS

Fri Jan 03, 2020 12:04 am

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.

Return to “Python”