JE-Random-Tech / ProJEcts

All code to the JE Random Tech Videos can be found here
0 stars 2 forks source link

run on startup? #4

Open CShouse1970 opened 2 years ago

CShouse1970 commented 2 years ago

Everything works great! This is for a museum and it will need to be able to start on boot or startup. That way when the power goes off it will just start back running the script. They also won't have a keyboard or mouse. I'm using raspberry pi 3b+ and the windows interface. So far I've been having to open the HapticBoard.py script and hitting the run button. Is there a way to have it start working when the pi boots up? Thanks.

JE-Random-Tech commented 2 years ago

Yes. Usually, to start the program you type python3 HapticBoard.py as shown in the Video at 6:55. You can place this line into a shell script (.sh) file. Using Cron and the @reboot option the python code is executed on startup. If you run into any problems don't hesitate to ask.

CShouse1970 commented 2 years ago

Thanks I'll give this a try.

CShouse1970 commented 2 years ago

I've created a .sh script titled launcher.sh and it works when I execute it. I also added this line to crontab: @reboot sh /home/pi/launcher.sh &. Nothing happens on reboot. I've tried both in desktop and CLI boot options.

JE-Random-Tech commented 2 years ago

Sry, I was thinking a bit too complicated. It is also possible to launch a python script using reboot: @reboot python /bin/your_script.py &. The and at the end is essential as it launches it in detached mode. Concerning the script: have you added execution permissions, and does executing ./script execute the code? I think it would be easier to use the first. Sorry about the confusion

CShouse1970 commented 2 years ago

Thanks so much. I'll let you know if I get the start up working. But what code do I need to use to make each video loop? Once triggered they'll loop until another button is pushed. Thanks.

JE-Random-Tech commented 2 years ago

I am not sure if I understand correctly. If you want to loop the videos on button press you could add '--loop' to

https://github.com/JE-Random-Tech/ProJEcts/blob/e421b75c9b155efdbf32875456d9ddc76ed2246d/Haptic%20Board/HapticBoard.py#L65

as done for the background video in

https://github.com/JE-Random-Tech/ProJEcts/blob/e421b75c9b155efdbf32875456d9ddc76ed2246d/Haptic%20Board/HapticBoard.py#L70

I think that should do the trick you might have to adapt the logic a bit.