Run python file on startup

Hello,

I have a rpi-rgb- led matrix 16 rows and 32 cols.

I wrote a Python file in order to run my own text which changes every minute.

I wrote the following code in rc.local:

#!/bin/shpio -e

_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”
fi

python3 /home/lo/rpi-rgb-led-matrix/bindings/python/samples/rungoed.py -m=adafruit-hat --led-rows=16 --led-cols=32 --led-slowdown-gpio=0 &
exit 0

The program is not running at startup.

I changed the code to:
#!/bin/shpio -e

_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”
fi

cd /home/lo/rpi-rgb-led-matrix/bindings/python/samples &
python3 rungoed.py -m=adafruit-hat --led-rows=16 --led-cols=32 --led-slowdown-gpio=0 &

exit 0

The code doesn’t work either.

If I use
python3 /home/lo/rpi-rgb-led-matrix/bindings/python/samples/rungoed.py -m=adafruit-hat --led-rows=16 --led-cols=32 --led-slowdown-gpio=0

on the command prompt it works perfect.

I hope you can give me advice what I have to change.

Thank you.

Lo

does rc.local actually run?

Have you looked at your rpi distro documentation on how to enable it and whether it’s enabled (google systemd rc.local)

May be you have to call python3 with a full path.

Thank you so much for your advice.

I read https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/ and followed the instructions.

Now my programs starts when starting the Raspberry Pi.

I’m happy.
Thank you.

Yvonne

1 Like

Thank you for your help. As you can see I succeeded.

1 Like