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!


Recent Entries

Comments

Oldest comments listed first.

Posted by: jadon.myopenid.com on February 4, 2009 at 8:14 PM

Setting the mux control

For just about every pin on the device, you can select it as GPIO or as one of many different functions. There are so many peripherals that, despite having hundreds of pins, it is still difficult (impossible) to get one pin configuration to support all the peripherals. The OMAP3 pin mux capability allows you to choose the functions. This makes the expansion port on Beagle far more flexible.

Some folks leave the pin mux settings the way they are done in u-boot. Others configure them with the kernel. One of the community members has done a write-up on how to set them in the kernel:

http://www.hy-research.com/omap3_pinmux.html

This is also a topic of discussion that comes up on the mailing list. It was discussed how to do this from user mode, without needing to change the kernel:

http://groups.google.com/group/beagleboard/browse_thread/thread/ff6f6aa843afd950


Posted by: Jason Kridner on July 20, 2009 at 2:00 PM

Did you mean to use "direction" and not "value"? Don't you need to set both?


Posted by: Brian Jepson on July 20, 2009 at 2:04 PM

Hi Jason,

I didn't need to set value; it worked with direction only (although I haven't tested it recently).

- Brian


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out. Make: The risk-takers, the doers, the makers of things... Welcome to Make: Online!


CRAFT Maker Shed Maker Faire MAKE television




Check out more videos from MAKE.

Maker SHED

Connect with MAKE

Be a MAKE fan on Facebook MAKE on Facebook
Visit our Facebook page and become a fan of MAKE!
MAKE on Twitter MAKE on Twitter
Follow our MAKE tweets!
MAKE Flickr Pool MAKE on Flickr
Join our MAKE Flickr Pool!
    make_tips on Twitter



    MAKE Archives

    Make: Money

    Make: Science Room
    Subscribe to MAKE Magazine!

    Make: Online editors and authors!

    Gareth BranwynGareth Branwyn
    Editor-in-Chief


    Phillip TorronePhillip Torrone
    Senior Editor
    | Web | Twitter


    Becky SternBecky Stern
    Associate Editor
    | AIM | Twitter


    Marc de VinckMarc de Vinck
    Contributing Writer
    | AIM | Twitter


    John ParkJohn Park
    Contributing Writer
    | Twitter


    Sean RaganSean Ragan
    Contributing Writer
    | Twitter


    Matt MetsMatt Mets
    Contributing Writer
    | AIM | Twitter


    Dale DoughertyDale Dougherty
    Editor & Publisher
    | Twitter


    Shawn ConnallyShawn Connally
    Managing Editor
    | Twitter


    Goli MohammadiGoli Mohammadi
    Associate Managing Editor

    Kip KayKip Kay
    Weekend Projects
    | AIM | Twitter


    Collin CunninghamCollin Cunningham
    Contributing Writer
    | AIM | Twitter

    Adam FlahertyAdam Flaherty
    Contributing Writer
    | AIM | Twitter


    John BaichtalJohn Baichtal
    Contributing Writer
    | AIM | Twitter



    More contributors: Mark Frauenfelder (Editor-in-Chief, MAKE magazine), Kipp Bradford (Technical Consultant/Writer), Chris Connors (Education), Diana Eng (Guest Author), Peter Horvath (Intern), Brian Jepson (O'Reilly Media), Robert Bruce Thompson (Science Room)

    Suggest a Site!

    Advertise here with FM.

    Why advertise on MAKE?
    Read what folks are saying about us!

    Click here to advertise on MAKE!



    Current Podcast

    itunesdl.gif Behind the Scenes at MAKE and CRAFT In January, many of the remote MAKE/CRAFT team members (myself included) convened at the Maker Media headquarters at O'Reilly Media in Sebastopol, California. Take a look behind the scenes of your favorite DIY publications as Goli Mohammadi gives us... More...

    Get the Make: Online sent via email
    Enter your email to receive Make: Online each day:



    Sign up for the Make: Newsletter

    Our Make: Newsletter covers news from maker Media, has original columns, Shed deals, and more! You can also read the archives of past issues.


     



    MAKE Fascination video series brought to you by Dow

    Make: Education
    MAKE: en EspaƱol MAKE: Japan
    Important please read


    Subscribe to MAKE Magazine!

    Recent Posts from the Craft: Blog