Search code examples
python-3.xlinuxzynq

How do I run a python program at Linux start up?


I want to run a simple python program that displays the IP address of my PYNQ board (Running Linux OS) on a PMOD OLED.

from netifaces import ifaddresses
IP_addr = ifaddresses('eth0:1')[2][0]['addr']

from pynq.overlays.base import BaseOverlay from pynq.lib import Pmod_OLED

base = BaseOverlay("base.bit")
display = Pmod_OLED(base.PMODA)

display.clear()
display.write("Board IP",1,0)
display.write(IP_addr,1,3)

To make it run at system start up I followed a tutorial made for the same thing on Raspberry Pi. And here are the steps:

sudo nano /lib/systemd/system/sample.service

added the following text:

 [Unit]
 Description=My Sample Service
 After=multi-user.target

 [Service]
 Type=idle
 ExecStart=/usr/bin/python3 /home/xilinx/sample.py

 [Install]
 WantedBy=multi-user.target

Then the following commands:

$ ExecStart=/usr/bin/python3 /home/xilinx/sample.py > /home/xilinx/sample.log 2>&1

$ sudo chmod 644 /lib/systemd/system/sample.service

$ sudo systemctl daemon-reload
$ sudo systemctl enable sample.service

after rebooting the system the IP is displayed for a little while the cleared as the system has killed the program and cleared the display. How can I make the code run with being stopped?


Solution

  • The answer to my Problem is the following:

    It turned out that there is another python script (/usr/local/bin/flash_leds.py) with higher priority that is clearing the hardware and interrupting the execution of my program.

    So, the simpler solution was to add my code to the already existing code and it is working just fine.