EBC Exercise 10 Flashing an LED

The "Hello World" program is the traditional first program for many classes. Flashing an LED is the embedded equivalent. Here we will explore a few ways to flash and LED on the Beagle and explore General Purpose I/O (gpio) along the way. This will call be done from the command line of the Beagle, so there is no need for the host computer.

gpio via the Shell Command Line and sysfs

The easiest way to do general purpose I/O (gpio) on the Beagle is through a terminal window and a shell prompt. In Linux most everything is treated as a file. Even things that aren't files. In our class we'll use a virtual file system called sysfs. sysfs exposes the drivers for the hardware so you get easily use them.

Try this, open a terminal by selecting Applications:Accessories:Terminal

Reading a gpio pin with an Oscilloscope

Unfortunately the gpio pins don't appear here. It turns out the processor has more internal I/O lines than it has physical pins. Each physical pin can can be connected to up to 8 internal lines. BeagleBoardPinMux does a nice job of explaining it all. The big clue is here BeagleBoardPinMux#Beagle which references Table 22 on page 108 of the -xM System Reference Manual.

Note that gpio130 appears on pin 21 of the Expansion Header. Also note that pins 27 and 28 are ground. Attach your scope probe to these. Now, let's put a signal on the pin.

Note that if you are the root user (which is the default case for Angstrom), you will have to type the following command:

$ ./togglegpio 130 0.05

The first argument tells which gpio port to toggle, the second tells how long to delay between toggling. In this example 0.05 s is 50 ms, which should give a period around 100ms. Measure the signal on an oscilloscope.

Assignment: gpio from the shell

Measuring a gpio pin on an Oscilloscope

Answer the following questions about gpio measurements.

What's the min and max voltage?

What period is it?

How close is it to 100ms?

Why do they differ?

Run htop and see how much processor you are using.

Try different values for the sleep time (2nd argument). What's the shortest period you can get? Make a table of the values you try and the corresponding period and processor usage.

How stable is the period?

Try launching something like mplayer. How stable is the period?

Try cleaning up togglegpio and removing unneeded lines. Does it impact the period?

togglegpio uses bash (first line in file). Try using sh. Is the period shorter?

What's the shortest period you can get?

Toggling the LEDs

Modify togglegpio (call it toggleLED) to toggle the LEDs. Can you get the LED to appear to dim by changing the duty cycle of the toggling?

User Button to gpio 130

Write a shell script that reads the User Button and outputs it value on gpio pin 130.

Count the User Button Presses

Write a shell script that displays a count of the number of times the User Button has been pressed.

Copy gpio 130 to gpio 131

Write a shell script that copies the value of gpio pin 130 to gpio pin 131. How much CPU time does it take? What's the delay from the time the input changes until the output changes? How constant is the delay?

Resources

Here is wh1ts article on flashing an LED. It is referenced in the readgpio file that comes on the Beagle.