4.9 LED Test

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:

  • One MYD-C437X-PRU development board
  • One USB to TTL converter used to connect J25 of MYD-C437X-PRU development board and host PC, set the baudrate of serial port on host PC to 115200-8-n-1

Software Preparation:

  • Linux Kernel 4.1.18
  • echo, led_test application

Test Steps:

  • View the device node of LED devices as below:
# ls /sys/class/leds/
myc:blue:cpu0       myd:blue:mmc1
myd:blue:heartbeat  myd:blue:usr3
  • Control the LED by echo command as below:
#echo "0" > /sys/class/leds/myc:blue:cpu0/brightness
#echo "1" > /sys/class/leds/myc:blue:cpu0/brightness
#echo "0" > /sys/class/leds/myc:blue:cpu0/brightness

#echo "1" > /sys/class/leds/myd:blue:mmc1/brightness
#echo "0" > /sys/class/leds/myd:blue:mmc1/brightness

#echo "1" > /sys/class/leds/myd:blue:heartbeat/brightness
#echo "0" > /sys/class/leds/myd:blue:heartbeat/brightness

#echo "1" > /sys/class/leds/myd:blue:usr3/brightness
#echo "0" > /sys/class/leds/myd:blue:usr3/brightness
  • Control the LEDs by 'led_test' application as below:
# 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:blue:cpu0 -l 0
Set led myc:blue:cpu0 off, brightness = 0
# led_test -d myc:blue:cpu0 -l 1
Set led myc:blue:cpu0 off, brightness = 1
  • Observe the state of the LEDs

Note: myc:blue:cpu0 is triggered by cpu0, so it can not be controlled directly. In order to control this LED, the trigger should be disabled by writing '0' to /sys/class/leds/myc:blue:cpu0/brightness, then it can be controlled normally as other LEDs.