Running a Python Program on boot with the Raspberry Pi
One of the most common questions asked about the Raspberry Pi is how to get code you wrote to run automatically as soon as you boot it up. We get why this question is so common; a lot of people have entered this world of open electronics by way of the Arduino, and simply giving it power will start it up and run your code. With the Pi, there is a lot more going on so in this tutorial we will show you how to get your code up and running automatically as soon as the Pi starts.
There are a lot of different operating systems out there for the Raspberry Pi, so we are going to focus on the most popular: Raspbian. We are using the version dated: 2018-06-27 deviating from this may result in different / additional steps so if you are very new to this, we recommend following the tutorial exactly. Please Note: This will not work on the Lite version of Raspbian.
The Parts Needed:
This Raspberry Pi 3 tutorial will be requiring a few parts:
Step 4 – Clean Up The File
Scroll down to the bottom using the arrow keys. We are going to delete the lines circled in the attached image. Be sure to keep the line “exit 0”
Step 6 – Save and Reboot
Once this is done, press “Ctrl + X” and then “Y” to save it. Now we should be able to reboot our Pi. Type into the terminal:
That’s all there is to it! As the Pi reboots, your program should now run!
If you have any questions, or need further clarification please post in the comments section below; this way future users of this tutorial can see the questions and answers!