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!

34 thoughts on “Blinking LEDs with the Beagle Board

  1. jadon.myopenid.com says:

    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

    1. bumble omap says:

      How come you leave the pin mux unchanged ? Just changing the sysfs files will work ??

  2. Jason Kridner says:

    Did you mean to use “direction” and not “value”? Don’t you need to set both?

  3. Brian Jepson says:

    Hi Jason,

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

    – Brian

  4. Laine Walker-Avina says:

    Note that sticking an LED directly into the expansion header is _highly_ unrecommended. The pins on that header are directly connected to balls on the processor, and are only rated to source/sink a very small amount of current. You should be buffering the pins with a driver or transistor.

  5. rodrigo says:

    i managed to get a similar thing running, that blinks the usr leds.
    i could not get any signal at the gpio ports though…
    no errors while running the commands, value reads 1 and 0 in a coherent manner, but nothing changes at the pin… (scope is at 1mV all the time…)
    any tips?
    thanks!

  6. rahul peddi says:

    i am using ubuntu in beagle board instead of angstorm , can i use the same gpio pins? can i access the gpio pins directly?

  7. Antti Niemelä says:

    On a Beagleboard xM Rev C the GPIO168 (pin24) is pinmuxed to I2C SCL and its state cannot be altered without changing U-Boot and kernel settings.

    GPIO157 (pin 22)  and GPIO156 (pin 20) for instance work fine.

    1. timesuptim says:

      How can we find out which pins will work and which ones wont? I am sure there is a useful list somewhere…
      Best,
      Tim

  8. Anonymous says:

    note, the ‘direction’ file is for specifying weather the pins is input or output. I.E. the pin will drive a line high or low (output) or sink current (input)

    the ‘value’ file is relevant to ‘output’ mode, and will determine if it’s driving high or low

    you should write ‘in’ or ‘out’ to the ‘direction’ file. And ‘1’ or ‘0’ to the value file (if its an output)

    the example may have worked, but it’s for different electrical reasons

    1. timesuptim says:

      Actually the drivers use “high” and “low” to set the direction and the output value in one go. See some details here:
      http://www.avrfreaks.net/wiki/index.php/Documentation:Linux/GPIO#Getting_and_Setting_Direction
      Best,

      Tim

  9. Shruti says:

    I tried this script with BBxM Rev C and I’m getting the following errors
    root@beagleboard:~# ./strobe_gpio 150
    ./strobe_gpio: line 19: while[: not found
    ./strobe_gpio: line 20: can’t create /sys/class/gpio/gpio150/direction: nonexistent directory
    ./strobe_gpio: line 22: can’t create /sys/class/gpio/gpio150/direction: nonexistent directory
    ./strobe_gpio: line 24: syntax error: “done” unexpected

    Please help.

    1. Brian Jepson says:

      Shruti: I don’t have a BBxM to test. You should see if you can find some help via http://beagleboard.org/discuss.

  10. Cesar Marin says:

    Hello colleague
    For your problem of voltage pin i / o of the BeagleBoard I recommend you use to adjust levels sn74lvc8t245dbrg4 chip is Texas Instrument dual feeding may be one of them 1.8 and the other up to 5.0 volts.

    Greetings Cesar Marin

  11. cihan says:

    It works thanks.I have a question about
    how to run shell script for Blinking LEDs with the Beagle Board by all users from web.
    I used exec() command in php but I get permission error.

    I want to turn on/off BB’s gpio using a shell script from web
    Any idea ?

  12. srjcsarah says:

    Engineers Please come and contribute your skills and knowledge to a Santa Rosa Junior College community based sight aimed at simplifying knowledge for all to learn… pm me on the site and ill make you a Mod i will be promoting the content on over 30,000 pages so put your name on the post if it’s original thanks http://srjcnews.com/viewtopic.php?f=33&t=59

  13. djkfjezhhz says:

    Bonjour super site de rencontre tro merci de votre assistance http://fastrencontre.com/tag-plan.html

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
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

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

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

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK