4.9 gpio

On a embbeded Linux system, the LEDs are commonly controlled by sysfs interface.
This example demonstrates how to control the LEDs by sysfs with echo command or led_test application.

Hardware Preparation:

  • Hardware debugging environment to see chapter2.
  • MYD-AM335x series development board

Software Preparation:

  • Linux Kernel 4.1.18
  • echo, led_test application

Test Steps:

  • Copy cross compiled <WORKDIR>/Examples/led/led_test to /usr/bin directory of the MYD-AM335x series development board.

  • View the device node of MYD-AM335X LED devices as below:

    1
    2
    # ls /sys/class/leds
    myc:green:user1 myd:green:user2 myd:green:user3
  • Control the MYD-AM335X LED by echo command as below:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    D3:
    #echo "1" > /sys/class/leds/myc:green:user1/brightness
    #echo "0" > /sys/class/leds/myc:green:user1/brightness
    D39:
    #echo "1" > /sys/class/leds/myd:green:user2/brightness
    #echo "0" > /sys/class/leds/myd:green:user2/brightness
    D40:
    #echo "1" > /sys/class/leds/myd:green:user3/brightness
    #echo "0" > /sys/class/leds/myd:green:user3/brightness
  • View the device node of MYD-AM335X-Y LED devices as below:

1
2
# ls /sys/class/leds
myc:green:user1 myd:green:user2
  • Control the MYD-AM335X-Y LED by echo command as below:
1
2
3
4
5
6
D3:

#echo "0" > /sys/class/leds/myc:green:user1/brightness
D2:
#echo "1" > /sys/class/leds/myd:green:user2/brightness
#echo "0" > /sys/class/leds/myd:green:user2/brightness
  • View the device node of MYD-AM335X-J LED devices as below:
1
2
# ls /sys/class/leds
myc:green:user1 myd:green:user2
  • Control the MYD-AM335X-J LED by echo command as below:
1
2
3
4
5
6
D3:
# echo "1" > /sys/class/leds/myc:green:user1/brightness
# echo "0" > /sys/class/leds/myc:green:user1/brightness
D2:
# echo "1" > /sys/class/leds/myd:green:user2/brightness
# echo "0" > /sys/class/leds/myd:green:user2/brightness
  • Control the LEDs by ‘led_test’ application as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
# led_test -h
Usage: led_test [options]

Version 1.0
Options:
-d | --device name led name myc:blue:cpu0
-l | --light brightness led brightness. 0~255 0: off.
-h | --help Print this message

# led_test -d myc:green:user1 -l 0
Set led myc:green:user1 off, brightness = 0
# led_test -d myc:green:user1 -l 1
Set led myc:green:user1 on, brightness = 1