# How do I run a python program at PYNQ start up?

**URL:** https://discuss.pynq.io/t/how-do-i-run-a-python-program-at-pynq-start-up/741
**Category:** Support
**Created:** [December 11, 2019, 5:17pm UTC](https://discuss.pynq.io/t/how-do-i-run-a-python-program-at-pynq-start-up/741 "2019-12-11T17:17:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![anoir\_nechi](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@anoir\_nechi](https://discuss.pynq.io/u/anoir_nechi)
#### Post date: [December 11, 2019, 5:17pm UTC](https://discuss.pynq.io/t/how-do-i-run-a-python-program-at-pynq-start-up/741/1 "2019-12-11T17:17:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)
#### Post date: [December 11, 2019, 5:51pm UTC](https://discuss.pynq.io/t/how-do-i-run-a-python-program-at-pynq-start-up/741/2 "2019-12-11T17:51:56Z")

</div>

You haven’t mentioned board or PYNQ version.

Your problem is probably that for the images we build, we run a script on startup to flash the LEDs on the board after boot. This is to give visual indication that the board is ready.

This script downloads the base overlay and runs code to flash LEDs. (Search for flash\_leds.py on the GitHub if you want to check what it does)

This is already a startup service.

If you add your own service, and it starts first, your design will be overwritten when the LED service starts.

You could change the priority of the services, but it probably makes more sense to remove/modify the LED service.

Cathal

---

<div class="post-metadata">

### Author: ![anoir\_nechi](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@anoir\_nechi](https://discuss.pynq.io/u/anoir_nechi)
#### Post date: [December 12, 2019, 2:02pm UTC](https://discuss.pynq.io/t/how-do-i-run-a-python-program-at-pynq-start-up/741/3 "2019-12-12T14:02:34Z")

</div>

Thank you for your answer and sorry for the missing details it is the newest version of PYNQ\_Z1 board.

I solved the problem I just added my code to the file that you have mentioned in your answer earlier and it is running just fine
