DIY Portable Face Recogniser Autorun Python

Run Program Manually

We have the Python program ready to run manually.

cd DIY_Portable_Face_Recogniser
python3 main.py

However, a portable device should just be starting the program when it is switched on. We will configure Raspberry Pi to do so.

Additional Scripts on main.py

Just before setting up the autorun, add the following lines to the Python program

### Start PulseAudio & connect to Bluetooth
call('sudo killall bluealsa', shell=True)
call('pulseaudio --start', shell=True)
call('pactl load-module module-bluetooth-discover', shell=True)
call('bluetoothctl << EOF\nconnect 41:42:87:63:FD:3E\nEOF', shell=True)

in lines between “from datetime import date, datetime” & “if Reset:”

Crontab Schedule

There are a few different ways to autorun the program automatically. We use the Crontab in this tutorial.

crontab -e

When you open crontab for the first time, you will be prompted to choose one of the text editors to use. It is entirely up to you but I usually use nano.

Once you are in an editor, add following schedule at the bottom of the crontab.

@reboot cd /home/pi/DIY_Portable_Face_Recogniser/ && python3 main.py

This indicates to autorun the “main.py” from the program folder every time after starting the Raspberry Pi.

Save & Exit from crontab by “Ctrl+C” and then “Y”.

Now restart the Raspberry Pi.

sudo reboot

The program should autorun after restarting.

The End

This is the end of the tutorial. I hope this tutorial was useful for somebody out there. I have the complete “main.py” for you to download below.

Thank you.

Complete main.py