1

I need to run a Python script on boot with display support

I have tried using rc.local, cron and a couple of other methods. All of them start the program and it runs as it should but I have a blank screen. I would like to be able to view what the program is doing on the screen. The script uses PyGame and printText to display a status to a small window. It works fine when I run it from a terminal window. I am using Raspbian on a Raspberry Pi 3.

Aurora0001
6,3773 gold badges25 silver badges39 bronze badges
asked Dec 29, 2017 at 3:37
5
  • I forgot to mention that I am using an ampersand at the end of the line in both the cron and rc.local with still no luck Commented Dec 29, 2017 at 3:38
  • 1
    Hello and welcome, @ray. Please note that you should include all relevant information in the question itself not comments - you can edit to question to do so. Commented Dec 29, 2017 at 21:00
  • @Ray Is your program a GUI? Commented Sep 11, 2018 at 4:18
  • try posting your script so that we can see what you're doing. This question is as vague as vague gets. Commented Nov 17, 2018 at 18:31
  • What version of Raspbian do you use? Is it Stretch? Commented Dec 16, 2019 at 14:37

2 Answers 2

1

I'd output the script to a logfile and, if needed use tail -f on the file to check the output. But if you really want to direct the output directly, note that both cron and rc.local don't have a tty attached. This means that you need to redirect the output of the script to a tty. So in your crontab put something like:

*/10 * * * * /home/pi/bin/myscript.py &> /dev/tty1

This still won't work (unless when you run the script as root), as the tty by default is owned by root. You can fix this by adding your user (probably pi) to the group tty: sudo usermod -a -G tty pi

Note that you can switch between your terminals with the ctrl-alt-f[1-6] keys (and from a X screen with ctrl+alt+F[1-6])

answered Dec 29, 2017 at 11:01
6
  • steviethecat, Thanks for your timely reply. My script controls a large dual axis solar tracker so I can tell it is working properly and it also generates log files of what it is doing so I am 100% certain that it is executing properly. I added my user to the tty group and added the line Commented Dec 29, 2017 at 15:05
  • @reboot python /home/pi/Tracker1_6b.py &> /dev/tty1 to the crontab file but it does not execute the script. When I use the line: python /home/pi/bin/Tracker1_6b.py in the rc.local it runs the script but without screen support of course. Commented Dec 29, 2017 at 15:28
  • When I add the line */ * * * * python /home/pi/Tracker1_6b.py to the crontab file it does not run either. I can't say I have ever gotten it to execute from cron. I must have spent 6 hours by now trying to get this to work. Commented Dec 29, 2017 at 15:30
  • In rc.local you can put python /home/pi/Tracker1_6b.py &> /dev/tty1 & Commented Dec 29, 2017 at 17:02
  • I tried that and I still have a black screen with the program functioning normally other than the lack of display. I think my setup is pretty generic with a normal HDMI display. Commented Dec 29, 2017 at 18:54
1

2020 answer for those who finding this from google:
nowadays Raspbian is using systemd that can handle graphical output with its services. You can find a simple example running the internet browser on bootup. It should not be a big issue to replace ExecStart= of the browser with the call of your python script. For the example look at execute Python file on Systemstart.

answered Apr 12, 2020 at 11:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.