LEDs

Last Update: 2015-09-27T12:03:28

The Arduino Yśn has seven (7) LEDs (Light Emitting Diodes); three (3) of which can be directly controlled from the command line via the Linux file system, of the remaining four (4), three (3) can be directly controlled by the ATmega32u4, one (1) is directly control by power. Those in the Linux file system are locate in /sys/class/leds. All have an on/off state, and drivers are available to do fancy things - like blink MORSE CODE. The others are discussed below.

Label on the Yun
Description
RX
Serial reciver (sic)
TX
Serial transmit
L13
Pin 13
WAN
WAN (ethernet) indicator
ON
Power indicator
WLAN
WLAN (WiFi) indicator
USB
USB

There are four (4) system scripts to control the LEDs, but none are of general use. The scripts are:

  1. /etc/rc.d/S95done - after remounting storage and calling /etc/rc.local, it calls 'set_state' in /etc/diags.sh
  2. /etc/rc.d/S96led - sets LEDs based on what UCI says is in /etc/config/system, if anything
  3. /etc/diags.sh - a script that controls one (1) led that is directly related the the board
  4. /sbin/led.sh - used to "set" (1/on) or "clear" (0/off) the LEDs it knows about via UCI in /etc/config/system

LED Controls

After some testing, this can be said about the LEDS with the following silkscreened labels on the Yun (Added: 2015-01-30, Updated: 2015-04-22)

The remaining three (3) LEDs can be controlled via Linux and it's the filesystem, and all use the same general form.

/sys/class/leds/{NAME} /sys/class/leds/{NAME}/{PARAMETER}

The three (3) controllable LEDs on the Yśn are:

  1. ath9k-phy0 - the physical radio of the Atheros AR9331
  2. ds:green:usb - the USB (Universal Serial Bus)
  3. ds:green:wlan - the WLAN (Wireless Local Area Network)

In the default state, all three (3) have the same parameters:

See bottom of page for Examples on use.

Web Console

In addition to the file system, the web console adds controls to the LEDs via a webform which ultimately writes to a configuration file in /etc/config (which uses the UCI library to do the writing.) After logging in (via the web), hit the [Configure] button, then on the top of the page is a link the advanced configuration panel (luci). Choose System->LED Configuration, then click the [Add] button to configure the LED, and hit the [Save] button.
(Added: 2015-01-30, Updated: 2015-04-22)

Triggers

The following "triggers" are available for the Yśn. Their parameters are described on a OpenWrt webpages. ( http://wiki.openwrt.org/doc/uci/system#leds )
NOTE: Some triggers may require the addition of a kernel module (see below).

Trigger
Description
None
The LED is always in default state. Unlisted LED are default OFF, so this is only useful to declare a LED to be always ON.
Timer
The LED blinks with the configured on/off frequency.
Default-on
The LED is ON. Deprecated, use default=1 trigger=none instead.
Heartbeat
The LED flashes to simulate actual heart beat thump-thump-pause. The frequency is in direct proportion to 1-minute average CPU load.
Flash Writes
The LED flashes as data is written to flash memory.
Network Activity
The LED flashes with link status and/or send and receive activity on the configured interface.
WiFi Activity
The LED flashes on events triggered in physical interface, rather than in software network interface.
USB Device
The LED turns ON if USB device is connected.
Morse Code
The LED signals a message using Morse code.
GPIO
Allows LEDs to be controlled by gpio events.
Net filter
Flash LED when a particular packets passing through your machine.

Kernel Modules

The following packages (for the kernel) are available (for the Arduino Yśn) to modify the LEDs.

Package
Description
iptables-mod-led
iptables extension for triggering a LED.
kmod-input-gpio-keys-polled
Kernel module for support polled GPIO keys input device
kmod-ipt-led
Netfilter target to trigger a LED when a network packet is matched.
kmod-leds-gpio
Kernel module for LEDs on GPIO lines
kmod-ledtrig-default-on
Kernel module that allows LEDs to be initialised in the ON state.
kmod-ledtrig-gpio
Kernel module that allows LEDs to be controlled by gpio events.
kmod-ledtrig-heartbeat
LED Heartbeat Trigger
kmod-ledtrig-morse
Kernel module to show morse coded messages on LEDs.
kmod-ledtrig-netdev
Kernel module to drive LEDs based on network activity.
kmod-ledtrig-netfilter
Kernel module to flash LED when a particular packets passing through your machine.
kmod-ledtrig-oneshot
Kernel module that allows LEDs to be triggered by sporadic events in one-shot pulses.
kmod-ledtrig-timer
Kernel module that allows LEDs to be controlled by a programmable timer via sysfs.
kmod-ledtrig-usbdev
Kernel module to drive LEDs based on USB device presence/activity.
rssileds
A small process written in C to update the signal-strength indicator LEDs
strongswan-mod-led
StrongSwan LED blink on IKE activity plugin

To install a module, at the command line issue the following commands.

opkg update opkg install {package-name}

Examples

Labels updated on: 2015-09-27

get

[email protected]:/sys/class/leds# cat ds\:green\:usb/brightness 255 [email protected]:/sys/class/leds# cat ds\:green\:usb/trigger [none] switch0 default-on timer phy0rx phy0tx phy0assoc phy0radio phy0tpt netdev

set - example #1

[email protected]:/sys/class/leds# echo 0 > ds\:green\:usb/brightness [email protected]:/sys/class/leds# cat ds\:green\:usb/brightness 0

  1. In the example above we set the "brightness" to zero (0)
  2. We verify that by reading the value.

set - example #2

[email protected]:/sys/class/leds# echo timer > ds\:green\:usb/trigger [email protected]:/sys/class/leds# cat ds\:green\:usb/trigger none switch0 default-on [timer] phy0rx phy0tx phy0assoc phy0radio phy0tpt netdev [email protected]:/sys/class/leds# ll ds\:green\:usb/ -rw-r--r-- 1 root root 4096 Jan 28 08:33 brightness -rw-r--r-- 1 root root 4096 Jan 28 08:36 delay_off -rw-r--r-- 1 root root 4096 Jan 28 08:36 delay_on lrwxrwxrwx 1 root root 0 Jan 28 07:35 device -> ../../../leds-gpio -r--r--r-- 1 root root 4096 Jan 28 07:35 max_brightness lrwxrwxrwx 1 root root 0 Jan 28 07:35 subsystem -> ../../../../../class/leds -rw-r--r-- 1 root root 4096 Jan 28 08:35 trigger -rw-r--r-- 1 root root 4096 Jan 28 07:13 uevent
  1. In the example above we set the "trigger" to timer
  2. We verify that by reading the value.
  3. We also see two (2) new paramters showed up delay_off and delay_on

Additional Examples

LED Configuration With OpenWRT
http://n-dimensional.de/blog/2014/07/04/led-configuration-with-openwrt/

LED configuration example from ShapeShifter
http://forum.arduino.cc/index.php?topic=290149.msg2029465#msg2029465