QUB-ASL / bzzz

Quadcopter with ESP32 and RaspberryPi
MIT License
7 stars 1 forks source link

Run Python script on startup #65

Closed alphaville closed 1 year ago

alphaville commented 1 year ago

Run the Python script on startup using crontab. Make sure you run it from within a virtual environment. Check the old Raspberry Pi (run crontab -e).

patchedByBatman commented 1 year ago

I followed this guide and ran this command sudo crontab -e and added this line @reboot python3 /home/bzzz/Desktop/bzzz/raspberry/read_sbus/read_sbus_from_GPIO_receiver.py at the end of the file.

alphaville commented 1 year ago

@gunturiCM just be careful with sudo. You may or may not need to use it. Does it work now?

patchedByBatman commented 1 year ago

Had some issues. But everything is fixed now. The Python script in a virtual environment starts after powering up as expected.

This is for future reference

The modifications were: In crontab, the above line was changed to @reboot sleep 10 && /home/bzzz/Desktop/run_sbus_rx.sh and the shell script from the previous setup was modified and added to the desktop. The contents of the bash script are.

#!/bin/bash

pushd /home/bzzz/Desktop/
source bin/activate
python3 /home/bzzz/Desktop/bzzz/raspberry/read_sbus/read_sbus_from_GPIO_receiver.py
popd

Then python virtual environment support was installed sudo apt-get install python3-venv

Then create and activate the venv.

sudo python3 -m venv /home/bzzz/Desktop/
source bin/activate

Change permissions to allow pip to be able to install modules in venv sudo chmod -R a+rwx ~/Desktop/

Install the required modules inside the venv

python3 -m pip install bitarray
python3 -m pip install pigpio
python3 -m pip install pyserial
patchedByBatman commented 1 year ago

@gunturiCM just be careful with sudo. You may or may not need to use it. Does it work now?

Yes, professor, it works now.