Skip to content

Run on boot

Step 1. For SD-card version 5EWC0-2023-v0.2.0

This step applies to SD-card version 5EWC0-2023-v0.2.0 only. Install libpynq version 5EWC0-2023-v0.2.6 (or later), earlier versions of libpynq will not work. Execute

cd libpynq-5EWC0-2023-v0.2.6
bin/upgrade-sdcard-image.sh 

This will update some system files, as well as create the startup.sh file in the student home directory.

If it does not change anything then make sure to give it execution permission by the command

sudo chmod +x bin/upgrade-sdcard-image.sh // make it executable
bin/upgrade-sdcard-image.sh 

This will allow you to execute the script. after repeat the bin/upgrade-sdcard-image.sh commands above and checking if it works follow the next step:

Step 1. For SD-card versions greater than 5EWC0-2023-v0.2.0

No action required; go to step 2.

Step 2. Edit the startup.sh file

#
# you can add your executable that must be run when your PYNQ boots up like this
# (remove the '# ' before the path to the executable)
#
# /home/student/name-of-executable

Change the line # /home/student/name-of-executable to /home/student/the-name-of-the-executable-you-want-to-run. To stop running this program when the PYNQ runs, just comment it out, by adding # at the start of the line.

Note that you don't have to login to the PYNQ board - the program always starts after boot.

Step 3. Optional - stopping the program

If the program doesn't finish (which will usually be the intended behavior) but you want to stop it for some reason then

  • log in to the PYNQ board
  • execute killall the-name-of-the-executable-you-want-to-run

This will kill all programs with that name that are running. To accidentally avoid killing other programs it's therefore wise to give your program a unique name (and not e.g. main).

Troubleshooting

If on following these steps your program does not work then check the following aspects:

Check if it is running

First of check if the program is running in the background

PS -A | grep the-name-of-the-executable-you-want-to-run

It will show the following

785 ?        00:00:15 the-name-of-the-executable-you-want-to-run

If it does no show this output it means that there is a typo in the /home/student/startup.sh file. Make sure you refer to the binary executable and not to the c code file, for example heartbeat and not heatbeat.c.

Font does not load

When importing fonts, make sure that the path is absolute and not relative. This ensures that if the program boots from a different location than when the user executes ./executable-file, it can still find the fonts correctly.

InitFontx(fx16G, "../../fonts/ILGH16XB.FNT", ""); // ../../ means the relative path

The program does start on boot, but it does not contain the font. To recognize that the program did boot but that the font is the issue, make sure to have a different start-up color than black to easily recognize that it has initialized even if there is no text

Relative font launched as user Relative font launched on boot Relative font launched on boot with blue background

To fix the font, change the path to an absolute path

InitFontx(fx16G, "/home/student/libpynq-5EWC0-2023-v0.2.6/fonts/ILGH16XB.FNT", ""); 

This way the program will also be able to find the font when it start from boot with a different path then when it runs from the terminal.

Logging while on auto boot

Too see the output of the program when it runs on boot run the following command

sudo journalctl _SYSTEMD_UNIT=bootpy.service

Note: default user password is student, fill that in when prompted. This command opens a window where all output is redirected of the startupscript. The windows uses vim layout meaning, press uppercase G to go to the end, lowercase g to go to the top, arrows to navigate, and :q to quit the interface. To search type / followed by the search term.

If you would like to log information to a file for storage as debugging purposes add the following to your script:

//include time library
#include <time.h>

//Initialize additional material. 

//initialize the log file and write the start time of the program
FILE *file;
time_t rawtime;
file = fopen("/home/student/log.txt", "a"); //here 'a' means we append and not write over the whole file
time(&rawtime);
fprintf(file, "%s", ctime(&rawtime)); //print time and date only one time

//Note that the first fprintf is only to set a date to indicate when the program start execution. 

//Do stuff

//Use fprintf to write info to the logfile.
fprintf(file, "This is a debug statement!\n");

//Do stuff

//close the file at the end of execution
fclose(file);

This will open a file for logging and after adding a timestamp on the top you can use fprintf() in the same style as the normal printf() to provide additional information while it runs in the background. All the information will then be printed in /home/student/log.txt. This can also be used during normal execution from the terminal as active user to log statistics regarding senors values. Note that errors during execution will not be outputted here.

To then view the output use

cat /home/student/log.txt

or anyother tool such as nano or vim.