Accessing gpio using python running on linux

Hello, I am a student trying to write to the buildin leds from the pynq z2 using python.
I am currently running the latest linux image from xilinx with python 3.10 if i am not mistaken.
The main problem that i seem to run into is that i don’t have the gpio pin number of for example
the blue led on L15.

Program:
from pynq import GPIO
from time import sleep

    gpio_pin = GPIO(L15, "out") 
    gpio_pin.write(1)
    sleep(2)
    gpio_pin.write(0)

Error:
Traceback (most recent call last):
File “/home/xilinx/2EAI-POZ-2324-Rust-PYNQ/tile/python_test.py”, line 4, in
gpio_pin = GPIO(L15, “out”) # Assuming GPIO pin 8
NameError: name ‘L15’ is not defined

Greetings,
Xander

Hi

Could you please share more information about your design?
Are you using base overlay, or you have a design in Vivado, if yes, then please share the screen shot of AXI GPIO in the Vivado

if you have a bitstream, you need to first load your overlay, then you can list all available IPs in your design, then you can easily see the name of GPIO:

from pynq import Overlay
ol = Overlay('Your_Bitstream_Name.bit')
pl?

Replace the Your_Bitstream_Name with your bitstream name

if you are using the base overlay: for example following code trun on turn off first LED with base overlay:

from pynq.overlays.base import BaseOverlay
from pynq import GPIO
import time

ol = BaseOverlay("base.bit")
ol?

leds_GPIO = ol.leds_gpio 
leds_GPIO?
leds_GPIO.write(0,1)
time.sleep(2)
leds_GPIO.write(0,0)
time.sleep(2)
leds_GPIO.write(0,1)

regards,
Mo

I am just trying to control the gpio pins of my pynq using python and don’t realy care in what way.
I would prefer it however if i dont have to change hardware settings or add to them using gpio_blocks.
Vhdl on the pynq is not new to me but programming the gpio using python is.
So any help is appreciated.

Thank you for the fast response!
Regards,
Xander

Hi @Xander,

In the PYNQ Workshop there is material covering how to use GPIOs.

Mario