Blinking LEDs with the Beagle Board

Technology
Blinking LEDs with the Beagle Board

Beagle Board GPIO Demo

One of the things that drew me to the Beagle Board was that it has a whole bunch of easily accessible sensor interfaces sticking right off its expansion header. All you need to do is solder on some kind of connector (I went for the Arduino-esque female headers as shown in the picture above).

Once you’ve done that, it’s a matter of figuring out what to do with them. What mystified me about the Beagle Board was just how the heck you talk to these pins. Linux supports all the popular sensor interfaces: general-purpose input/output (GPIO), Inter-Integrated Circuit (I2C), and Serial Peripheral Interface (SPI).

I was tempted to plug the Beagle Board right away into a bunch of sensors I had laying around, but was hindered by the fact that the Beagle Board uses 1.8 volt signaling (I’ll tackle that issue in a future post). To get started, I just wanted to blink an LED, which meant I needed to figure out how to use GPIO with Linux on the Beagle Board.

I checked out Table 17 in the Beagle Board system reference manual to figure out which physical pin corresponded to which GPIO port. I wanted a pin that was close to one of the ground pins (27 and 28) on the expansion header, so I went for GPIO_168 (pin 24).

One thing I’m still not clear on is the meaning of the options (A, B, C, and D) in Table 17. It seems that when I request the GPIO port, I get it no problem, so I’m guessing that the operating system is taking care of “setting the mux control register in the OMAP3530.”

So I knew that GPIO_168 corresponded to physical pin 24, but I didn’t know how to get to it. I came across some Linux documentation in the AVRFreaks Wiki that spelled it all out for me: as you’ll see in the example, all you have to do is use the Linux shell to write some commands to some pseudo-files in the /sys directory ($PORT is the port number):

Command Effect
echo $PORT > /sys/class/gpio/export Open a GPIO port for writing
echo $PORT > /sys/class/gpio/unexport Release the GPIO port
echo “high” > /sys/class/gpio$PORT/direction Take the port high
echo “low” > /sys/class/gpio$PORT/direction Take the port low

To try this out on a Beagle Board, you’ll need to have gone through the Beagle Board tutorial on getting the Angstrom Linux distribution running. Once you are done with this, you will have Linux running on the Beagle Board, and you’ll be able to interact with it using a serial terminal (for example, minicom on Linux, screen on Mac OS X, or HyperTerminal or PuTTY on Windows) and type commands into it.

So log in to your Beagle Board as root, and enter the following program into a file called strobe_gpio:

strobe_gpio shell script example

The vi editor is included with the Beagle Board, so you can type vi strobe_gpio, type i (to get into insert mode), then paste the program in. Next, press Escape (to get back into command mode), and type ZZ to save the file. This should drop you back into the Linux shell. (There are many vi tutorials in the universe if this is proving to be troublesome.)

Next, type chmod 755 strobe_gpio. Then, insert an LED as shown (short end into pin 28, long end into pin 24) in the picture at the top of this post. Try the command ./strobe_gpio 168 and you should see the LED blink.

This is definitely not an effective demonstration of the full power of the Beagle Board, but it is a first step in getting it to talk to sensors and other microcontrollers.

Update: Boireau Laurent has posted some more information about how this works in the Beagle Board Google Group, along with a suggestion that the community create a “beginners site with such simple or more complex exemples, with shell scripts and small C programs, demonstrating ‘hello world’ capabilites, and basic interaction with LEDs, buttons, timers, interrupts, serial, SPI, I2C, PWM, interfacing a webcam, using the NEON or the DSP”. I’d find such a site incredibly useful!

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Tagged

I'm a tinkerer and finally reached the point where I fix more things than I break. When I'm not tinkering, I'm probably editing a book for Maker Media.

View more articles by Brian Jepson
Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK