tutorial ZYBO-Linux(III): Program ZYBO with linux. Small program to use the leds

(Last Updated On: March 10, 2018)

This is the third part of Linux tutorial for Linux using the ZYBO board from Digilent.

In this part I am going to describe the steps to start up Linux from the previously c burnt SD card. The communication with the board are hold via Ethernet. At the end some easy programs will be shown to handle with the Zybo Leds.

0- You have to burn a SD card with the Debian image. Done in the  Linux-Debian step (I). Also remember to change the Jumper JP5 to the SD position.


adapter USB-Ethernet

1- Connect the ZYBO board via Ethernet to the computer. If your laptop does not have an Ethernet port, you would need an USB adapter like in the picture below.

2- Configure your connection in the net configuration and select Ethernet or wired connection.

Introduce the following address in the IPv4 and IPv6 settings, since the preloaded image have this as default:

You must ignore the Ipv6 connection

3- Open the terminal in a Linux computer (Ubuntu, Debian, etc). We did this on the previous step. Then connect via ssh (secure sehll) with the board. Therefore the following command should be written on the terminal:

The address which come by default is This can be changed in another images or configurations.
4- To access to the root folder graphically, to see and modify their content. Open a any folder (Nautilus) and then click on “connect to Server” as the following image is showing:

Introduce the IP of the previous Ethernet port:

Connection to the root via Ethernet

Write “sftp://” and then press connect. After that you hould be able to see the content of the root folder.

Root folder

This can be done in Debian with the command

5- Create a new text document with the root folder of the SD by right click on the folder and then selecting new file. Then you can rename the file as you want, for example blink.c

New text file

7- Write the code inside the text file editing it with the normal text editor. Just double click on the icon and the notebloc will open.

Empty text editor

Userspace applications are not allowed (in linux and in every OS in general) to access to direct to the hardware, and therefore the led or buttons.While using an operating system like linux in this case, the linux kernel act as an interface.
We are going to use the easiest GPIO driver: Sysfs Interface (Read the official linux doc for more info). We will see more details after this example.
Write your code, or copy and modify the following example code. This small program blink the MIO-7 led built on Zybo: Download this other blink-example.c.

In the text editor it should appear like this:

7- Save and compile the program. Therefore we are going to use the preinstalled GNU gcc compiler of Linux. For that the structure is:

Another useful options for the compiler:

  • –help
  • -g (build with debugging symbols)
  • -O0 (turn off optimization)
  • -O2 (full optimizations)
  • -S (generate assembly output instead)
  • -Wall (turn on all compiler warnings)

In this after opening a terminal, the following command is written:

Now, if the compilation have run without errors, you should see an empty like as shwon in the following picture:

Error-Free compilation

In the case of any mistake or compilation error are in the code, the compiler shows you the error and tell you in which line the error can be found. For example something like this:

Compilation with error

8- Now is time to execute our program, of course only if it has compiled without errors! Therefore, the next command will run the code:

After that the led should blink.
Important note: to stop the program, you should press Control + C

sysfs GPIO driver: Code Examples in C

The sysfs drivers files and documentation can be seen on the linux github.

The procedure to use the external GPIO (general purpose input output):

  • First the GPIO has to be exported writing the number of the pin inside the text file on the directory: /sys/class/gpio/export (in this case 913 for the LED MIO07)
  • Later the direction has to be written into the file /sys/class/gpio/gpio913/direction (“out” or “in”)
  • To write the value into the GPIO pin, a value “1” or “0” should be written in the text file on the directory: /sys/class/gpio/gpio913/value.

For the ZYBO board the offset value the base address of the GPIO is 906. So manage the pin of the PS (processor System) connected to MIO 7 (led) you have to set the 906+7 = 913. For the buttons MIO 50 and MIO 51–> 906+50 = 956 and 906+ 51 = 957

The processor system is connected to the Pmod JF (MIO)

Example for configuring the the ps-buttons (MIO50-51), pins(MIO-13 JF1) and led (MIO-7): Download the c-file gpio_example.c

A simply pwm generated by software:

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top