Monday, May 21, 2012

An SSD1306 LCD controller in Perl for the BeagleBone

I've been hacking away on the BeagleBone some more, and I've come up with a controller for the common SSD1306 LCD controller, using the SPI interface. This controller is behind a bunch of the available small graphical LCD panels out there.

I've also written supporting libraries to display both text and PNG files, although don't expect too much from a 128x32 monochrome image!

I've uploaded my notes and libraries here:

Coding it is as simple as:

my $lcd = BeagleBone::SSD1306::Text->new(
  rst_pin => 'P9_15',
  dc_pin => 'P9_16',
  # remainder of pins must be connected to SPI pins
$lcd->display_string("Hello world!");

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);