How to use LEDs from sys interface?

I am using a Apalis imx6 Ixora Carrier board and I want to use led 4 and led 5. I tried with the sys interface as follows:
echo 33 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio33/direction
echo 1 > /sys/class/gpio/gpio33/value
cat /sys/class/gpio/gpio33/value

but it is not working.So I want to understand how to use/reconfigure pins and how to use LEDs from sys interface.

Thanks in advance!


Hi @Payal

Greetings from Toradex Community

You can access the leds like this, e.g. switch on all 4 LED, wait a second, switch them off again:

 echo 1 > /sys/class/leds/LED_4_GREEN/brightness
 echo 1 > /sys/class/leds/LED_4_RED/brightness
 echo 1 > /sys/class/leds/LED_5_GREEN/brightness
 echo 1 > /sys/class/leds/LED_5_RED/brightness
 sleep 1
 echo 0 > /sys/class/leds/LED_4_GREEN/brightness
 echo 0 > /sys/class/leds/LED_4_RED/brightness
 echo 0 > /sys/class/leds/LED_5_GREEN/brightness
 echo 0 > /sys/class/leds/LED_5_RED/brightness

Because the led driver did already reserve the gpio your effort to export one of the gpio’s used for the LEDs fails.

If you want the pins to be exportable as gpios you would have to change the device tree so that the pins are muxed to be gpios but not used by any kernel driver.

Hello @ashok.tx,

Thanks for your quick reply. I have tried as you mentioned but in /sys/class/leds directory only mmc0, mmc1 and mmc2 are present.

So I really have no idea what is going wrong. Am I missing something?


Hi @Payal

Could you please provide me the error logs.
is this a custom Linux image??

Hi @ashok.tx ,

root@apalis-im6:~# ls /sys/class/leds
mmc0:: mmc1:: mmc2::

Hi @Payal

Could you please check whether you’re loading imx6qdl-apalis-eval.dtsi dtb file??
if yes ,please chage/load imx6q-apalis-ixora-v1.1.dtb dtb file from u-boot.Please use below command for the same in u-boot terminal.

setenv fdt_file imx6q-apalis-ixora-v1.1.dtb

Hello @ashok.tx ,

Thank you for your valuable reply. By default imx6qdl-apalis-eval.dtb was getting loaded. As you suggested I changed it to imx6q-apalis-ixora-v1.1.dtb by using setenv fdt_file imx6q-apalis-ixora-v1.1.dtb command. And I can see the leds are glowing.

Now I want to change the fdt_file to imx6q-apalis-ixora-v1.1.dtb from the source code so that I don’t have to manually change it every time I flash the image.

Could you please help me with that

Thanks in Advance.



Hi @Payal

Please update fdt_file= imx6q-apalis-ixora-v1.1.dtb in uEnv.txt which is present
in our BSP directory(Apalis-iMX6_LXDE-Image-Tezi_2.8b6)