element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Essential Raspberry Pi Peripherals #3: The kivy framework for small display and touch screens
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: balearicdynamics
  • Date Created: 1 Oct 2015 10:35 PM Date Created
  • Views 2937 views
  • Likes 1 like
  • Comments 10 comments
Related
Recommended
  • kivi
  • lcd_display
  • raspberry_pi
  • raspberry-pi
  • 7_inches_touch_screen_display
  • essential_raspberry
  • user_interaction

Essential Raspberry Pi Peripherals #3: The kivy framework for small display and touch screens

balearicdynamics
balearicdynamics
1 Oct 2015

Introduction

Available for the Raspberry PI at the actual date the market offers a number of touch screen displays; the recent launched Raspberry PI 7" LCD touch screen display and the 2.4" HAT display are the top accessories in their range. These devices can be used as primary display including the touch screen they can replace the standard HDMI display, USB keyboard and mouse.

 

It is almost obvious that the 2.4 inches screens are less useful than larger screen (i.e. 15 inches or more): but represent a great solution for a large number of projects and applications.

A common UI design is difficult to manage and more difficult to interact with when the user should manage a 2.4 inches (or less) small screen or trying to use complex interactive interfaces also on a 7 inches screen.

 

Take a look to the following video.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

If you like this kind of interface you are in the right place. Full colour graphics, multi-touch management, easy and visible interaction widgets also on small screen sizes, reasonably fast and responsive interfaces and more. The features shown in the video above are only some of what can be achieved with the Kivy python framework.


Note: the frame assembly of the Raspberry PI LCD Touch Screen display shown in the images of this post is available on the Drobott site. Don't forget to apply the Element14 discount code W0E49MYQ (10% off) reserved to the community users!

 

The framework

The adoption of this framework for the User Interface with the Raspberry PI is the better solution when the touch screen is the main tool to interact with the application. For the developers this framework is simple to manage, entirely developed in Python and very well documented with plenty of examples.

 

Wikipedia reports the definition of the Kivy framework as

Kivy is an open source Python library for developing mobile apps and other multitouch application software with a natural user interface (NUI). It can run on Android, iOS, Linux, OS X, and Windows. Distributed under the terms of the MIT license, Kivy is free and open source software.

              

but the term library is reductive; kivy is a set of libraries integrating features of many different environments. The recent porting available for the Raspberry PI Raspbian makes kivy one of the best solution for the UI design on touch screens and small displays.

 

The X desktop (the Raspbian desktop is an example) has never been though to be controlled by a touch-screen or an on-screen keyboard. In fact the kivy framework works perfectly just in these cases, so it's time to move on the Raspberry PI terminal and start the installation.

 

Installing Kivy on Raspberry PI

The main reference site is kivy.org On the site - not reported in the documentation index - there is a short page with a tutorial on Installing kivy on Raspberry PI. Unfortunately this is the only page I have found and is a bit outdated. The actual available version of the framework runs perfectly on all the Raspberry PI models including the PI 2, despite that the documentation report as untested.

 

Installation options

Two installation options are possible: the manual installation under Raspbian and the Kivy distribution image for the Raspberry PI.

I have tested both. The special PI distribution (derived by Raspbian) can be downloaded from the site KivyPie - Kivy on RaspberryPI but seems not well working so we will exclude this option and take in consideration just the manual installation.

 

Manual installation

The first thing to do is adding the repository http://vontaene.de/raspbian-updates/ to the list. From the terminal launch the editor

 

$>sudo nano /etc/apt/sources.list
          

 

and add the following line: deb http://vontaene.de/raspbian-updates/ . main

The resulting file will show like in the image below.

image

Save the file then launch the next commands:

 

$>sudo apt-get update
$>sudo apt-get upgrade
          

 

Before installing the framework you should install the dependencies of the packages:

 

sudo apt-get update
sudo apt-get 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
          

 

Note: you will receive a warning for some uncertified packages. Ignore this message and confirm when required to proceed.

 

The next step needs to install pip from the sources. Pip, aka Pipi is the Python Package Index; It is a specific python packages repository working in a similar way of the apt-get (the aptitude Debian package manager). A full detailed list of the available packages in pip is available on the pipi-python site.

 

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py
      

 

Installing and compiling the pip package manager on the Raspberry PI may require 10 minutes or more. Don't worry and wait ... During the installation you will get some error messages due the wheel command is not found; don't stop the process and ignore these messages. Wheel is a package image builder not intended for use in our case. The error message you get is shown in the image below.

image

Cythonhttp://cython.org/ is the c-extension for python and is used by some components of kivy. For a detailed description see the cython wiky.

At the end of the process described above cython should be installed in your system. We use the pip repository to acquire the last updated version, avoiding the eventually outdated version available in the Debian packages.

 

sudo pip install cython
    

 

At this point, we are are ready to clone kivy from GitHub and compile it locally

 

git clone https://github.com/kivy/kivy
cd kivy
    

 

Fine! We have completed the most boring part. The kivy sources now are in the user home directory, for example the user pi. It is also possible to install kivy only in the user folder but this way creates many issues when developing applications that will rung accessing other folders so we install the framework globally.

 

python setup.py build
sudo python setup.py install
   

 

The two commands above should be launched from inside the kivy directory in the user folders. You should already be there when the step ends. This operation requires 5-15 minutes or more, depending on the hardware model and processor speed of your Raspberry PI board.

A couple of other steps and our newly installed framework is ready for the first run.

 

Post-install settings

There are some features of the kivy framework requiring some external components to be installed afte the framework installation is complete.

 

sudo pip install pyglet docutils
sudo pip install pygments
 

 

The last operation is to edit the user kivy configuration file to set the raspberry PI touch screen replacing the mouse. Edit the kivy configuration file with the command

 

nano ~/.kivy/config.ini
 

 

and add the following lines in the [input] section (other similar lines should be replaced)

 

[input]
mouse = mouse
mtdev_%(name)s = probesysfs,provider=mtdev
hid_%(name)s = probesysfs,provider=hidinput
 

 

Save the file and reboot the system. Now you are ready to launch your application or run the examples in the folders you find in ~/kivy/examples

  • Sign in to reply

Top Comments

  • balearicdynamics
    balearicdynamics over 9 years ago in reply to mikethechap +1
    Hello Michael, don't worry for this. It's only a warning due the added repository has not (for some reason on their server I suppose) a valid GPG key. The only further issue you will get is that in the…
  • clem57
    clem57 over 8 years ago

    Ran across this just recently. Firstly, do you still use/develop with Kivy frameworks? What interest me was support to move to Android for future apps. I did notice this is for Wheezy. How would Jessie work. I have tried installs, but ran into various problems. Thanks for anything you can add.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to mikethechap

    Hello Michael,

     

    no, it is really the ./kivi/config.ini nothing to do with Python. It is the file that is checked by the kivy engine when it starts. This is one of the kiby sources I got inspiration (unfortunately I had to make this tutorial because all those I have found on the net are incomplete, buggy, outdated etc. with some issue) Installation on Raspberry Pi — Kivy 1.9.1-dev documentation

     

    As for as I know you should find the existing config.ini file in the .kivi folder under your user folder, that in ta bare installation is /home/pi/.kivi and is a hidden folder. It sounds strange to me: did you installed with a different user? Or making a sudo su so you have done all as root ? In this case your home folder is not where it is expected.

     

    As you can read here and there, there are two different posibilities to install kivi: in the user folder or as a global folder. I have preferred the user folder because after some tries I saw that it was more complex and risky to install kivy globally in the machine. And maybe that for some reason you don't need the installation, so it is sufficient to create a new user and the installation has no more effect.

     

    Let me know some more detail, it is an interesting issue that should be solved if possible.

     

    Two questions again: what Raspbian version did you used? Ths installation, despite the config.ini file issue, does it works ?

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mikethechap
    mikethechap over 9 years ago in reply to balearicdynamics

    Thanks so much for your help, Enrico. I was able to get though everything but the command:

     

    nano ~/.kivy/config.ini 

    It opens it as a new, blank file. I figured that's not the way it should be: there should be existing lines already there, I think. So I started searching the kivy folder. It seems the kivy folder has the following contents::

    AUTHORS  CONTRIBUTING.md  examples  LICENSE   MANIFEST.in  setup.cfg

    build    doc              kivy      Makefile  README.md    setup.py

    I then looked in the /kivy/kivy sub-folder and saw the file, config.py. Should the command be

    nano ~/.kivy/config.py

    Versus?

    nano ~/.kivy/config.ini 

    I just didn't see any *.ini files...

     

    Thanks!

    Mike

     

    PS I can't wait to get my Custom Frame!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to mikethechap

    Hello Michael,

     

    don't worry for this. It's only a warning due the added repository has not (for some reason on their server I suppose) a valid GPG key. The only further issue you will get is that in the next steps you will be noticed during the installation that there will be a non-signed package for installation (or similar message). Accept and go ahead.

     

    Enrico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mikethechap
    mikethechap over 9 years ago

    I had this error when I tried to sudo apt-get update. Any idea what might be wrong? Thanks!

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube