GPIO and LEDs on PYNQ Ultra96 image


#1

Hi,

I found the ultra96 PYNQ access to the PS I2C and GPIO (mraa-gpio and mraa-i2c), but what is the way to access the 4 user-controllable LED’s? Is it through the /dev/gpiochip0 and gpiochip1 interface? I don’t see the documentation on this, and I don’t want to fry my board randomly setting pins high and low…

Thanks,
David


#2

Hi,

I am looking into this for my own work, will update soon. The prior post I made had good intentions but was incorrect.


#3

Hi,

Unfortunately it’s complicated, they made the user LEDs led drivers rather than just gpio pins. They are setup as ds2 (LED3), ds3 (LED2), ds4 (LED1), ds5 (LED0). You will have to open them as drivers and configure appropriately. This is the closest public example I know of, it is C-code. You will have to use Python and make the system os calls to manipulate the drivers and mimic what they do with C here: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842398/Linux+GPIO+Driver#LinuxGPIODriver-LEDS-GPIODriver

The only other alternative at the moment is to change the device tree entries for the LEDs, turning them back into MIO drivers. Which means you would have to rebuild your own PYNQ image as well. And then you could use the PYNQ GPIO module. The MIO pins are 17,18,19,20 and translating to the right Linux GPIO numbers is another long story.

Yes I know this is a lot of work just to toggle an LED, sorry.


#4

Here is a solution, a lot of overhead just to toggle a bit but it does work:

def ledon(led):
s = “/sys/class/leds/ds” + str(led + 2) + “/brightness”
value = open(s,“w”)
value.write(“1”)
value.close()

def ledoff(led):
s = “/sys/class/leds/ds” + str(led + 2) + “/brightness”
value = open(s,“w”)
value.write(“0”)
value.close()

def ledheartbeat(led):
s = “/sys/class/leds/ds” + str(led + 2) + “/trigger”
value = open(s,“w”)
value.write(“heartbeat”)
value.close()


#5

Thanks for the tip! I’m used to throwing in a Axi-GPIO block to control LEDs, I’m not so familiar with these Linux drivers. I hope its useful for everyone else!

-David