LoginSignup
43
35

More than 5 years have passed since last update.

メモ:Raspberry Piの基板上のLEDを別の用途に使う

Last updated at Posted at 2015-06-14

Raspberry Piの基板上にはLEDが2つあって、1つは電源(赤)、もう1つはGPIO接続のLED(緑)。
参考: Raspberry Pi Schematics
デフォルトの状態では点灯トリガが「mmc0アクセス時」になっている。これを変更することで別の使い方ができる。

sysfs経由で制御する。

$ cd /sys/class/leds/led0
$ ls -la
合計 0
drwxr-xr-x 3 root root    0  6月 15 00:27 .
drwxr-xr-x 3 root root    0  6月 15 00:27 ..
-rw-r--r-- 1 root root 4096  6月 15 00:27 brightness
lrwxrwxrwx 1 root root    0  6月 15 00:27 device -> ../../../leds-gpio
-r--r--r-- 1 root root 4096  6月 15 00:27 max_brightness
drwxr-xr-x 2 root root    0  6月 15 00:27 power
lrwxrwxrwx 1 root root    0  6月 15 00:27 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root 4096  6月 15 00:29 trigger
-rw-r--r-- 1 root root 4096  6月 15 00:27 uevent

現在設定されている点灯トリガの確認をする。

$ cat trigger
none [mmc0] timer oneshot heartbeat backlight gpio cpu0 default-on input rfkill0 phy0rx phy0tx phy0assoc phy0radio

デフォルトで[mmc0](mmc0アクセス時に点灯)に設定されている。
heartbeatに変更してみる。

$ sudo sh -c "echo heartbeat > trigger"
$ cat trigger
none mmc0 timer oneshot [heartbeat] backlight gpio cpu0 default-on input rfkill0 phy0rx phy0tx phy0assoc phy0radio

一定間隔でチカチカと点灯する(ハートビート)ようになる。
initスクリプトなどで設定してあげれば、kernelが起動できているかどうかの確認用に使える。

点灯トリガをnoneにし、brightnessに明るさの値を設定してあげることで、点灯状態を制御できる。明るさとして設定できる最大値はmax_brightnessの値となる。

$ cat max_brightness
255
$ cat brightness
0
$ sudo sh -c "echo none > trigger"
$ cat trigger
[none] mmc0 timer oneshot heartbeat backlight gpio cpu0 default-on input rfkill0 phy0rx phy0tx phy0assoc phy0radio

GPIO接続のため単純なON/OFF制御しかできないので、brightnessに書き込む値は、0以外で点灯、0で消灯になる。

$ sudo sh -c "echo 255 > brightness"
$ sudo sh -c "echo 0 > brightness"

/boot/config.txtにDevice Treeのパラメータを記述することで、点灯トリガの初期値を変更することができる。詳しくは/boot/overlays/READMEを確認すること。
(Raspberry Pi 3 については、接続の関係で下記の方法と違う設定となる。/boot/overlays/README内のpi3-act-led設定を確認すること)

点灯トリガをheartbeat状態で起動するのであれば、

dtparam=act_led_trigger=heartbeat

none状態(消灯状態)で起動するのであれば、以下のように書いておく。

dtparam=act_led_trigger=none

sysfsのLEDクラスについては、kernelソースのドキュメントディレクトリ Documentation/leds/leds-class.txt に記載がある。
他の点灯トリガについては、kernelソースのディレクトリ drivers/leds/trigger を確認する。
あるいは、kernelソース全体から 関数 led_trigger_register() 、および関数 led_trigger_register_simple() を呼び出しているところを探す。

43
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
35