User avatar
davidcoton
Posts: 5026
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Autorun Python code on TFT

Sat Dec 27, 2014 8:48 pm

I have a Model B with an Adafruit TFT attached. It's going to be a heating controller in a church (if I ever manage to jump all the hurdles).

I've got code that runs on the display, but I'm having trouble getting it to autorun. I added to /etc/rc.local:

Code: Select all

python3 /home/python/heating.py &
which seems to start the code, but it promptly aborts, leaving the x screen running and showing an error in the (hdmi) text terminal:

Code: Select all

_tkinter.TclError: No display name and no $DISPLAY environment variable
I've used Linux for some time, but still have no idea how to set the name and/or env var in an appropriate place -- or how to find what the correct value should be. Any hints?
Signature retired

broo0ose
Posts: 318
Joined: Wed Dec 14, 2011 3:59 pm
Location: Wirral, UK

Re: Autorun Python code on TFT

Sat Dec 27, 2014 10:57 pm

I'd add it to

Code: Select all

/etc/xdg/lxsession/LXDE/autostart
Back up the file, you can remove the other lines and add your command with an @ at the beginning. Have a look at the file and you'll understand what I mean

User avatar
davidcoton
Posts: 5026
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Autorun Python code on TFT

Sun Dec 28, 2014 12:01 am

Thanks for the reply, but it doesn't work that way either. It will wait for a login on the console -- despite autologin having been enabled (at least I think it was). I can't even get LXDE to start reliably now. If I try starting my program from the console, I get the same problem as in the first post.

I'm getting very discouraged -- autostart ought to be a minor part of the project, but I'm going to waste all my available time on it. It has been three months since I last had any programming time and it looks like I will never get enough time to make it all work. We may have to find another control system instead of building one on RPi.
Signature retired

broo0ose
Posts: 318
Joined: Wed Dec 14, 2011 3:59 pm
Location: Wirral, UK

Re: Autorun Python code on TFT

Sun Dec 28, 2014 7:01 pm

Have you used

Code: Select all

sudo raspi-config
to force gui mode rather than command line.
That should do the auto-login for you.

latki8
Posts: 31
Joined: Wed Aug 01, 2012 1:56 pm

Re: Autorun Python code on TFT

Sat Jan 03, 2015 12:08 am

If it is of any help, I was interested in trying this out myself (tkinter, not heating controller). I agree the tkinter error is probably because there is no x environment, ie the python code is running on the basic console function, but I have followed what has been suggested above and it all works fine as far as I can see and even with no HDMI screen connected, the python tkinter code is still running. The only problem I have is that my Noobs SD card still has all the other OS on it and the boot process won't continue until I press escape - annoying, but I want to keep my options open for now. In case it isn't clear, I don't have an Adafruit screen either.

Return to “Advanced users”