Wednesday, May 16, 2012

First steps with Perl on the BeagleBone

Today I received a BeagleBone A5, which is a very small board containing a 720 MHz ARM CPU and 256 MB of RAM, among other things.

The first step was to start flashing the built-in LEDs via a Perl script..
I found a script on another site ( but it's not "modern" Perl, and was working in an inefficient way. (Opening and closing the LED filehandles continually).
Here's my updated version:

use strict;
use warnings;
use autodie;
use Fcntl qw(:DEFAULT);

unless (-w "/sys/class/leds/beaglebone::usr0/brightness") {
    die "I think you need to run this as root..\n";

my @leds = map {
    my $tmp;
    sysopen($tmp, "/sys/class/leds/beaglebone::usr$_/brightness", O_WRONLY);
} (0..3);

print "Hit Ctrl-C to exit..\n";
while (1) {

sub led {
    my @vals = @_;
    for my $i (0..3) {
        syswrite($leds[$i], "$vals[$i]", 1);
    select(undef, undef, undef, 0.05);


  1. Did you compile Perl yourself for or on it?
    I've tried to crosscompile Perl for my Synology NAS but failed because cross compilation isn't really maintained.
    The Perl that ships with DSM 4.0 is 5.8.6 ;(

  2. I didn't compile Perl for it..
    I'm running Ubuntu 12.04 (Precise Pangolin) on it, so it already had Perl 5.14.2 available, and plenty of modules.

  3. I would love a PERL tutorial or example of reading and writing GPIO's and reading analog inputs too! :-) Love that I can program this thing in PERL!

  4. Actually, after some googling, I found these two links:

    If you combine those two, you can pretty quickly make a perl script to read or write gpio38 (port 8, pin 3). The read was a bit tricky, since you need to set some higher order bits in the mux byte to set the direction. See the second link above.

  5. Hello Unknown,
    I guess you must have missed my entire Perl library that makes this stuff quite easy?
    I thought I blogged about it -- see the repo at

    It's not what I would call finished, but it does provide support GPIO in both directions as well as support for a LCD controller.