How to use sysfs to turn on and off LED in Milk-V Duo 64M

I am trying to turn on and off an LED with sysfs. I have my LED connected on Milk-V Duo Pin 1. From my understanding the physical pin is XGPIOA[28]. I tried the following

echo 448 > /sys/class/gpio/export # At this time, generate the /sys/class/gpio/gpio448 directory.

echo out > /sys/class/gpio/gpio448/direction # Reconfigure IO direction as output:

echo 1 > /sys/class/gpio/gpio448/value # Light the LED

echo 0 > /sys/class/gpio/gpio448/value # Turn off LED

echo 448 > /sys/class/gpio/unexport # Release GPIO resources

from my understanding the XGPIOA[28] is in 480 - XGPIOA[0] not sure if I understand correctly. When I run the above the LED doesn’t light up or light down. Note: The connection of the LED is the following
LED Anode is connected to Pin1 in the Milk-V Duo board. LED Cathode is connected to a resistor and to the Ground. Also when I start the board the LED is always turned on. Thanks

1 Like

Hi Mahmoud,

Have you tried with gpio508? According to the pinout it should correspond to XGPIOA[28].

I only have Duo256 and Duo S. On my Duo256 the following works as expected for switching onboard LED on/off (using the official buildroot image).

echo 354 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio354/direction 
echo 1 > /sys/class/gpio/gpio354/value
echo 0 > /sys/class/gpio/gpio354/value

Also, check and adjust the pin mode of the Pin you want to use.

duo-pinmux -l
duo-pinmux -r  GP1 # read GP1 pin multiplex mode
duo-pinmux -w GP1/GP1 # put in GP mode

I hope this is helpful

1 Like

Hello Jonathon. Thank you for you advice. The first thing I had to do is change the pinmode so I am able to write to it 1 and 0. The code you provided is exactly what I needed. This is solution.

1 Like