Channels ▼

Al Williams

Dr. Dobb's Bloggers

BeagleBone LEDs

June 04, 2012

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

More >>

Reports

More >>

Webcasts

More >>

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.

Related Reading






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video