Need help with rpi-kivy-screen?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

222 Stars 50 Forks 26 Commits 11 Opened issues


Using Raspberry Pi's Official Touch Display with Kivy and GPIO

Services available


Need anything else?

Contributors list

# 169,719
22 commits

Using Kivy with the official Raspberry Pi Touch Display

Demo video

The guide below and example code will get you started setting up the Raspberry Pi touch display and getting Kivy working with it. Kivy is an "open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps."

This guide assumes you have a fresh install of Raspbian (the 2015-05-05 Wheezy release or the 2015-09-24 Jessie release), an Internet connection, and the display is connected and working. It also assumes that you're already familiar with Raspberry Pi enough to get yourself to the command line. You can run this code locally or via SSH.

Note: I don't recommend executing these steps with the desktop envioronment running. It may slow down the set up process and cause problems with running Kivy apps. If you're set up to boot to into the desktop enviroment on Raspbian Jessie, click the Raspberry Menu → Preferences → Raspberry Pi Configuration. Change the Boot setting from Desktop to CLI and then reboot.

The command line is where you'll start:

  1. Update your software. This is required with the 2015-05-05 Raspbian image in order to get touch working. This step will take a few minutes:

    [email protected] ~ $ sudo apt-get update && sudo apt-get -y upgrade
  2. Reboot (this is not required, but might be a good idea if you're working from an older version of Raspbian):

    [email protected] ~ $ sudo reboot
  3. Back on the command line, check that touch input works by trying it in X11:

    [email protected] ~ $ startx
  4. If touch works, exit out of X11 and go back to the command line.

  5. The next few steps will install Kivy. These instructions are based on the Kivy User’s Guide. Firstly, open the APT sources list:

    [email protected] ~ $ sudo nano /etc/apt/sources.list
  6. At the end of file, add the APT sources for Gstreamer:

    deb . main
  7. Type

    to exit nano. Then press
    to save the file. You'll be back on the command line.
  8. Download and add the GPG key for the Gstreamer sources:

    [email protected] ~ $ gpg --keyserver --recv-keys 0C667A3E
    [email protected] ~ $ gpg -a --export 0C667A3E | sudo apt-key add -
  9. Install the dependencies:

    [email protected] ~ $ sudo apt-get update
    [email protected] ~ $ sudo apt-get -y install pkg-config libgl1-mesa-dev libgles2-mesa-dev \
    python-pygame python-setuptools libgstreamer1.0-dev git-core \
    gstreamer1.0-plugins-{bad,base,good,ugly} \
    gstreamer1.0-{omx,alsa} python-dev
  10. Install pip from source, as the version that is in the Raspbian apt repository is too old. You can ignore any messages about

    [email protected] ~ $ wget
    [email protected] ~ $ sudo python
  11. Install Cython, Pygments, and docutils. The Pygments and docutils packages are not actually required for Kivy, but the example code you'll execute uses them. This step will take a few minutes:

    [email protected] ~ $ sudo pip install cython pygments docutils
  12. Download Kivy and install it globally (this step will take quite a few minutes):

    [email protected] ~ $ git clone
    [email protected] ~ $ cd kivy
    [email protected] ~/kivy $ python build
    [email protected] ~/kivy $ sudo python install
  13. To enable touch, you'll need to make a modification to the default Kivy configuration file. To create that file, first run an example:

    [email protected] ~/kivy $ python ~/kivy/examples/demo/pictures/
  14. Quit the example with

    and then open the newly-created
    file for editing:
    [email protected] ~/kivy $ nano ~/.kivy/config.ini
  15. Go into the

    section, remove the lines that are in there and put in:
    mouse = mouse
    mtdev_%(name)s = probesysfs,provider=mtdev
    hid_%(name)s = probesysfs,provider=hidinput
  16. Launch the multi touch pictures demo. Tap, drag, pinch, and rotate should all work like a dream:

    [email protected] ~/kivy $ python ~/kivy/examples/demo/pictures/
  17. Type

    to exit the pictures demo.
  18. Launch the UI showcase. This shows you all the different UI elements that Kivy makes available to you:

    [email protected] ~/kivy $ python ~/kivy/examples/demo/showcase/
  19. If you'd like, explore the other examples in

  20. To try Kivy and GPIO together, download this repo to your Raspberry Pi if you haven't already:

    [email protected] ~/kivy $ cd ~
    [email protected] ~ $ git clone
  21. The example uses BCM GPIO pins 17 as a piezo buzzer, 27 and 10 as LEDs, and 22 as a button (with internal pullups set HIGH, so connect one leg of the button to 22 and the other to ground.)

    Wiring Diagram

  22. First try to run the example as root (in versions of Raspbian before Jessie, root access is required for the GPIO library):

    [email protected] ~ $ cd rpi-kivy-screen/
    [email protected] ~/rpi-kivy-screen $ sudo python 
  23. As you'll see, touch doesn't work. To fix this, you need to make the same change to

    you made before, but to the root account's config file. Exit (
    ) and copy over your home directory's Kivy configuration file to overwrite the root account's:
    [email protected] ~/rpi-kivy-screen $ sudo cp ~/.kivy/config.ini /root/.kivy/config.ini
  24. Run the example again and you'll be able to control the LED and buzzer. You'll also be able to see the state of the physical button!

    [email protected] ~/rpi-kivy-screen $ sudo python 

Even though root access isn't required for Python GPIO starting with the Jessie version of Raspbian, it may be helpful to copy the

file anyway in case you decide to have the root user execute your project immediately after boot up.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.