-2

I am making a project which contains face and object recognition. I activated functions with push button. My question is how can i run automatically my GPIO script when reboot raspberry.

I've tried write in .bashrc file. But it causes error(i guess its about camera) that;

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC mmal: camera component couldn't be enabled.

Do you have any suggestions?

1 Answers1

2

You can do this quite easily by adding a line to your crontab file. Do this:

From your $ shell prompt, enter man crontab. Read what it says. When you finish, dismiss the man page be entering q, and then enter crontab -e on the command line.

The nano editor will start, and show you a "default" crontab in which each line is commented - it begins with "#". Using nano, move the insertion point to the first new line at the end of the file. Enter this:

@reboot /usr/bin/python3 ~/somefolder/somefile.py &

Where ~/ is your home directory (probably /home/pi), "somefolder" is a folder in your home directory containing the Python script you want to run, and "somefile.py" is your Python script. The & lets your Python script run "in the background", and doesn't hold things up.

After you've added this line, use nano's Write (^O) to save the file, and accept whatever filename it suggests. Then exit nano using ^X. You'll get a confirmation message that your crontab file has been updated.

Reboot your pi, and your Python script will execute; and it will execute each time your pi reboots.

Seamus
  • 21,900
  • 3
  • 33
  • 70