简体   繁体   中英

Autostart on raspberry pi

I have been looking for a few weeks now on how to make a .py file start on startup. I have had no luck on any of the methods working, does anyone have any ideas. The file is reasonably small and will need GPIO input from a PIR movement sensor.

in case you using Raspbian you can simply add your script to the /etc/rc.local file see the snippet below:

#!/bin/sh -e
#
# rc.local
#
# Your Py Script here:
/opt/myscript.py

exit 0

Yeah we'll really need to know what OS you're using to be sure but assuming Raspbian the 2nd method on this link is the proper way to do it:

https://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up

If you are looking for a solution that works on bootup to the console, take a look at this link. Basic rundown:

Create a file for your startup script and write your script in the file:

 $ sudo nano /etc/init.d/superscript Save and exit: Ctrl+X, Y, Enter 

Make the script executable:

 $ sudo chmod 755 /etc/init.d/superscript Register script to be run at 

startup:

 $ sudo update-rc.d superscript defaults 

Make sure your script runs fine from the command line first.

Also, if you are dealing with the GPIO pins, make sure you are running your script with the proper permissions. I know when I access the GPIO pins on my pi, I need to use root/sudo to access them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM