Posts: 7
Joined: Sat Jun 16, 2012 10:18 am

Kivy and touchscreen at startup

Wed Nov 04, 2015 7:23 pm

I've created a script using Kivy that displays a clock and four buttons. My buttons start and stop an mpc radio stream, and raise and lower the volume (using os.system within the script). When I SSH into my Pi, and run the script, it runs without issue, as it should, buttons working, clock updating. However, when I get the script to run on the Pi at startup, the buttons don't respond to presses. I'm using the Raspberry Pi touchscreen display, and I've tried each of the following methods of running the script at startup, all with the same lack of touch screen response - adding it to rc.local and using init.d to run it as a service. I've tried using 'sudo' when adding it to rc.local.

Can anyone tell me what I'm missing when I'm trying to get it to run at startup? My Kivy/Python coding is weak at best, and I'm stumped on this!
Love the classics. Land Rovers and Minis, that is.

User avatar
Posts: 50
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: Kivy and touchscreen at startup

Thu Feb 04, 2016 9:43 am


here is a solution if you still need it.

Create a script named start_app.sh with

Code: Select all

cd ~
sudo nano start_app.sh

Code: Select all

#! /bin/sh
cd /home/sysop/PATH_TO_APP
python main.py
Change permissions and move it into init.d:

Code: Select all

chmod +x start_app.sh
sudo mv start_app.sh /etc/init.d/
Have fun!
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

Posts: 3
Joined: Wed Jan 11, 2017 9:36 pm

Re: Kivy and touchscreen at startup

Wed Jan 11, 2017 9:38 pm

I've tried the init.d approach but still have no touch. It works fine running the script manually or from SSH console, but not automatic boot. I use kivy with framebuffer (fbcp). Anyone?

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

Re: Kivy and touchscreen at startup

Thu Jan 12, 2017 8:57 am

Use cron with the @reboot option to directly run the python app,


Code: Select all

@reboot /usr/bin/python /home/pi/thermo.py
In this case thermo.py is my kivy driven GUI and is displayed on my touchscreen on boot up.
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):

Posts: 3
Joined: Wed Jan 11, 2017 9:36 pm

Re: Kivy and touchscreen at startup

Thu Jan 12, 2017 7:08 pm

Thanks but that didn't work for me. I finally found a solution though. I followed this tutorial to run it as a service and then add the following under [Service]

That makes the service run as "pi" and not "root". Then my touch came back to life!
http://www.raspberrypi-spy.co.uk/2015/1 ... ent-202707

The service can be set to auto reboot as well if it crashes. Restart=on-failure

Posts: 2
Joined: Mon May 08, 2017 12:53 am

Re: Kivy and touchscreen at startup

Mon May 22, 2017 7:30 pm

Could you please provide your .service file that works? I added User=pi as suggested but I still get no response from the touch screen after following the instructions at the link you provided (i.e. http://www.raspberrypi-spy.co.uk/2015/1 ... ent-202707). Mine is as follows

Code: Select all

Description=Kivy App

ExecStart=/usr/bin/python /home/pi/myscript.py

Does the order of the Type,ExecStart,User under [Service] matter? Does it work when you ssh in and restart the Pi as well? After running the above and rebooting it started but not on subsequent reboots :|

Do you have any other suggests to get the touch response working again? I really want to run the app from startup. Thanks.
I worked out. Stupidly, I did not complete the Kivy setup instructions. You must also add

Code: Select all

mouse = mouse
mtdev_%(name)s = probesysfs,provider=mtdev
hid_%(name)s = probesysfs,provider=hidinput
to ~/.kivy/config.ini. It worked!

Posts: 1
Joined: Tue Aug 22, 2017 6:09 pm

Re: Kivy and touchscreen at startup

Tue Aug 22, 2017 6:18 pm

Please help! I'm in the same situation and I followed your steps. My touch works when I set user to pi, but my program doesn't work properly because I need to run it using su privileges for folders my script looks for.
I was thinking that maybe the root cause of the touch not working without specifying the user as pi in the service, is that kivy was installed in the pi user directory rather than /. I moved all the kivy files and folders to /etc.. Now my touch is gone again :roll:

I don't really want to uninstall kivy and reinstall it again. Any thoughts?

Posts: 15
Joined: Mon Dec 21, 2015 2:15 am

Re: Kivy and touchscreen at startup

Fri Apr 20, 2018 12:50 am

I have similar problem. I am using Rpi3, official Rpi touch display and Raspbien/Kivy. My application is operator panel to control electronic instrumentation. On the screen there is oscilloscope and select buttons. On front panel there is encoder knob to select the setting values. Program runs normal if started manually from command line like this: python main.py The oscilloscope works ok, buttons are responding to touch and Ctrl + c terminates program If the program is auto started on boot (by adding line python /home/pi/main.py to rc.local ) program runs normal but buttons do not respond to touch – but respond to mouse click (cursor is not visible) and Ctrl + c do nothing. Looks like the Kivy config.ini is not executing before my script runs. In the previous posts there are suggestions how to fix this problem. I don’t exactly understand how it is done. It would be very beneficial for users less advanced (like my self) if somebody explain exactly what to do: how to open and what file and do what?

Posts: 15
Joined: Mon Dec 21, 2015 2:15 am

Re: Kivy and touchscreen at startup

Mon Apr 23, 2018 4:30 pm

I have tried crone, Rc.local and systemd . The trogram is running correctly but no touch.
If I added User=pi to Service the touch works but is second touch program terminates.
Another detail: when I run it manually “python main.py” is runs correctly and touch works but if I add sudo like this “sudo python main.py” program runs but no touch.
Can anybody help please?

Posts: 15
Joined: Mon Dec 21, 2015 2:15 am

Re: Kivy and touchscreen at startup

Wed Apr 25, 2018 12:35 am

I have found very simple solution to this problem – use “profile”
Sudo nano /etc/profile
Scroll down to the end and add line:
“python /home/pi/main.py
Save it and reboot.
Application and touch works ok on Rasbian Jessie but NOT on Rasbian Stretch


Posts: 387
Joined: Tue Oct 14, 2014 5:21 pm

Re: Kivy and touchscreen at startup

Thu Apr 26, 2018 9:24 am

It appears to me that touch will not work with root user or any other user than pi for whatever reason, since "sudo" leads to it not working, a service file lacking "user=pi" also does not work and rc.local does not work (which you should not use anyway - but it is run as root also).

Yet another way to autostart an application would be to use the desktop session's autostart. The benefits here include 1) it is started so late in the boot process that all other needed processes are likely already running, 2) it will run under the session user (i.e pi in this case).

https://www.raspberrypi-spy.co.uk/2014/ ... e-desktop/

Posts: 1
Joined: Tue Jan 08, 2019 7:23 am

Re: Kivy and touchscreen at startup

Tue Jan 08, 2019 7:28 am

none of the above methods worked for me

below method worked for me 8-) 8-) 8-) 8-) 8-) 8-)

first go to file using below command

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

second : add below command at the end with your file name

@lxterminal -e python /home/pi/yourfilename.py

Return to “General discussion”