Home > BeagleBone > Puppy’s First Month

Puppy’s First Month

My BeagleBone, along with some other goodies, arrived about a month ago. March was a busy month and while I did have some time to play with the little guy I didn’t have time to write about it. The few articles cover a variety of things that I experienced so far.

Adafruit Beagle Bone Starter Pack

Adafruit Beagle Bone Starter Pack

I purchased adafruit’s BeagleBone Starter Pack. That turned out to be a good choice. It made things plug and play for a software guy like me. I didn’t have to fuss with finding the right power supply. The puppy and half size breadboard are easily mounted onto a simple plexiglass plate that nicely keeps everything together.

I plugged the power supply and a network cable into the BeagleBone and within a minute I could access it using ssh. Neat! Here are the various access points:

  • ssh (port 22) – for access to a shell
  • bone101 (port 80) – small server written in node.js serving up an intro presentation
  • GateOne (port 443) – access to a shell through Firefox or Chrome
  • Cloud9 IDE (port 3000) – text editor and debugger for node.js applications through Firefox, Chrome or Safari
Being a programmer I really wanted to make the BeagleBone do something. After lots of Goggling I decided to start with blinking an LED. GigaMegaBlog has some very good articles on the BealgeBone. Beaglebone Coding 101: Blinking an LED was a very good starting place. It describes how to use the cloud9 IDE to some fun things with an LED. 

The cloud9 IDE is an online development environment for Javascript and Node.js applications as well as HTML, CSS, PHP, Java, Ruby and 23 other languages. The blink.js script demonstrates how to blink the User 3 LED on the board. That worked all and well but I’m not interested in writing JavaScript and blink.js hides how things work. So I started digging and it turns out that blink.js is using Linux’s sysfs.

sysfs is an implementation of a virtual file system. It exposes system devices to user space using a file system topology model. At the base of the topology are logical device groupings such as bus, class, and devices. Within those groupings there can be more logical groupings. Eventually the topology reaches a node that represents a physical device. Under the physical device node there can be nodes representing sub-devices or actions.

The LED’s on the board can be driven using sysfs:

  • /sys/class/leds provides interfaces to the User LED’s.
  • /sys/class/leds/beaglebone::usr3 represents an instance of the User 3 LED.
  • /sys/class/leds/beaglebone::usr3/brightness represent an action that can be performed on the User 3 LED. In this case you can:
    • Write a value (0, 1) to the file. That will set the LED to on (1) or off (1).
    • Read a value from the file. It will return the brightness (0, 1) of the LED.

The following shell script will blink the User 3 LED.

#!/bin/sh
while :
do
  echo 1 > /sys/class/leds/beaglebone::usr3/brightness
  sleep 1
  echo 0 > /sys/class/leds/beaglebone::usr3/brightness
  sleep 1
done

You’ll notice that blink.js is actually toggling two LED’s (ledPin, ledPin2). This is a bit confusing because only one LED is blinking. In fact both “pins” are set to set high and then low. But only one pin (ledPin2 = bone.USR3) actually has an LED attached to it. The other (ledPin = bone.P8_3) is a General Purpose Input/Output (GPIO) port that’s not connected to anything at this point. Even more interesting is that all the User LED’s are controlled by a GPIO port. But you can’t use the sysfs GPIO interface to control them. If you try you’ll get a “Device or resource busy” error. I suppose that’s because the sysfs-leds driver has grabbed it first.

Here’s how bone.P8_3 maps to sysfs-gpio. P8_3 is pin 3 on expansion header P8. According to the BeagleBone manual this is signal name GPIO1_6. From the signal name we can calculate the GPIO port number. In this case it is 38 (1 x 32 + 6). The first number is an offset of size 32. The second number is an offset from that number. Just multiple the first number by 32 and then add the second number. It’s all kind of confusing and it gets to be more fun when you bring in mux’ing.

Here’s now to access GPIO port 38 using sysfs:

  • /sys/class/gpio provides an interface to GPIO ports.
  • /sys/class/gpio/gpio38 is an instance of GPIO port 38. BeagleBone has 66 of these ports.
  • /sys/class/gpio/gpio38/direction represents an action that can be performed on GPIO port 38. In this case you can write a value (“high”, “low”) to the file. That will set the GPIO port to that value.
  • /sys/class/gpio/gpio38/value represents an action that can be performed on GPIO port 38. In this case you can read a value (“0”, “1”) from the file. It return the GPIO port’s value.

By the way, /sys/class/gpio/gpio38 isn’t there by default. You have to create it by writing the port number to /sys/class/gpio/export. For example:

echo 38 > /sys/class/gpio/export

You can find more on this at:


Advertisements
Categories: BeagleBone Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: