Skip to content

Instantly share code, notes, and snippets.

@channprj
Last active July 12, 2017 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save channprj/c0cb1fd3425b0734fe3a0b22b367bcc9 to your computer and use it in GitHub Desktop.
Save channprj/c0cb1fd3425b0734fe3a0b22b367bcc9 to your computer and use it in GitHub Desktop.
RPi2 내장 LED 컨트롤

RPi2 내장 LED 컨트롤하기

라즈베리파이2 내장 LED 관련 모듈은 /sys/class/leds/ 에 있음.

  • OK (ACT) LED = led0
  • Power (PWR) LED = led1

계속 켜져있거나 깜박이는 것이 거슬릴 경우 루트 계정으로 아래와 같이 간단히 제어가 가능.

# Green LED
# On(1), Off(0)
echo 0 | sudo tee /sys/class/leds/led0/brightness

# Red LED
# On(1), Off(0)
echo 0 | sudo tee /sys/class/leds/led1/brightness

# Allow Access
echo gpio | sudo tee /sys/class/leds/led0/trigger
echo gpio | sudo tee /sys/class/leds/led1/trigger

# Heartbeat Effect
echo heartbeat | sudo tee /sys/class/leds/led0/trigger
echo heartbeat | sudo tee /sys/class/leds/led1/trigger

# Revert Back to Default Setting
echo input | sudo tee /sys/class/leds/led1/trigger
echo mmc0 | sudo tee /sys/class/leds/led0/trigger

LED 모듈의 트리 구조는 아래와 같음.

.
├── brightness
├── device -> ../../../soc:leds
├── max_brightness
├── power
│   ├── autosuspend_delay_ms
│   ├── control
│   ├── runtime_active_time
│   ├── runtime_status
│   └── runtime_suspended_time
├── subsystem -> ../../../../../../class/leds
├── trigger
└── uevent

기본 용도대로 사용하는 것이 좋겠지만, 별도로 센서를 사서 연결하고 사용하기 번거로울 때, Red LED 정도는 특정 이벤트 조건 충족시 여러번 깜박이게 해서 알람 역할을 하도록 하는 것도 나쁘지 않을듯.   triggeruevent 등을 조작해서 원하는대로 조절도 가능.

LED trigger 기본값은 아래와 같음.

root@RPi2:~ # cat /sys/class/leds/led1/trigger
none mmc0 timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on [input] rfkill0
root@RPi2:~ # cat /sys/class/leds/led0/trigger
none [mmc0] timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on input rfkill0

참고

  1. RPi Stackoverflow
  2. RPi Forum
  3. jeffgeerling.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment