PYNQ: PYTHON PRODUCTIVITY FOR ZYNQ

How do I run a python program at PYNQ 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?

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

2 Likes

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