BeagleBone LEDs
Last time I talked about how to use general-purpose I/O with the BeagleBone, a small Linux-based embedded controller. Since I wanted to use the LEDs on board, the first thing I had to do was figure out how to make the LED driver release them so I could treat them as normal I/O.
More Insights
White Papers
- IDC Analyst Connection: Using Blade Systems to Cut Costs and Sharpen Efficiencies
- Application Testing Strategies in the IBM z/OS Environment
Reports
- Strategy: How to Conduct an Effective IT Security Risk Assessment
- Strategy: Smartphone Smackdown: Galaxy Note II vs. Lumia 920 vs. iPhone 5
Webcasts
- The Untapped Potential of Mobile Apps for Commercial Customers
- Why is Information Governance So Important for Modern Analytics?
The general-purpose I/O and LED drivers aren’t specific to the BeagleBone; they are common in modern Linux systems and the 2.6 and above /sysfs file system is a great way to access low-level hardware through simple file system access.
By default, each of the LEDs has a predefined function known as a trigger. Here’s a session at the shell with the LEDS:
Start in /sys/class/leds
root@beaglebone:/sys/class/leds# ls beaglebone::usr0 beaglebone::usr1 beaglebone::usr2 beaglebone::usr3
There are four LEDs. The convention is to have the color between the colons, but the BeagleBoard defies that convention.
root@beaglebone:/sys/class/leds# cd beaglebone::usr2
I've changed the directory to the 2nd LED.
root@beaglebone:/sys/class/leds/beaglebone::usr2# ls brightness device max_brightness power subsystem trigger uevent
There are a few files in the directory. Later, you'll see that the exact files depends on the trigger mode of the LED.
root@beaglebone:/sys/class/leds/beaglebone::usr2# cat trigger [none] mmc0 timer heartbeat backlight gpio default-on
Currently the trigger is set to none (indicated by the brackets).
root@beaglebone:/sys/class/leds/beaglebone::usr2# cat max_brightness 255
The LEDs pretend they can handle 255 levels of brightness, but in reality they are either off (0) or on (anything else).
root@beaglebone:/sys/class/leds/beaglebone::usr2# echo 255 >brightness root@beaglebone:/sys/class/leds/beaglebone::usr2# echo 10 >brightness
Either of the lines above will turn on the LED.
root@beaglebone:/sys/class/leds/beaglebone::usr2# echo 0 >brightness
This line turned it off.
root@beaglebone:/sys/class/leds/beaglebone::usr2# echo timer >trigger
Let's try the timer trigger.
root@beaglebone:/sys/class/leds/beaglebone::usr2# ls brightness delay_on max_brightness subsystem uevent delay_off device power trigger
The files in the directory have changed. There is now a delay_on and delay_off file.
root@beaglebone:/sys/class/leds/beaglebone::usr2# cat delay_* 500 500
Both files contain 500 and thus the LED is blinking at 500mS on and 500 mS off.
root@beaglebone:/sys/class/leds/beaglebone::usr2# echo 1500 >delay_on root@beaglebone:/sys/class/leds/beaglebone::usr2# echo 100 >delay_off
Now it is blinking with 1.5 seconds on and 100mS off.
Different boards have different device names and different triggers as well. Naturally, any language that can write to the /sys filesystem can control the LEDs.
The /sys filesystem has many different devices, not just gpio and leds. Sometimes documentation is sparse, but with a little sleuthing and experimenting you can interoperate with many different device drivers in the same manner.
Are you using /sys to control I/O on your systems? Or do you resort to "native" methods for performance? In my case, anything I'm probably using Linux for can survive the slight performance overhead involved in using the /sys filesystem.

