Using gpio

So I found the below code on
http://blog.makezine.com/archive/2009/02/blinking_leds_with_the_beagle_board.html

#!/bin/sh

Hi,

Try the following under minicom, after logging as root to Angstrom.
Check if you have the following directory (that's a special Led driver patch : some versions of Angstrom demo have it, others don't). It is described here : http://article.gmane.org/gmane.linux.ports.arm.omap/8611 and loaded at boot (see log and /etc/init.d).

cd /sys/class/leds/beagleboard::usr1
ls
more trigger
echo none > trigger

That shoud break the connection between LED and mmc
Now :

echo 1 > brightness
echo 0 > brightness

Done !

If you don't have it, just use basic GPIO

cd /sys/class/gpio
echo 150 > export (150 is usr1 LED, 149 is usr0 ... You can also access expansion port GPIO that way, say 168 for pin 24)

That should create directory /sys/class/gpio/gpio150, with all the access you want.

cd /sys/class/gpio/gpio150
echo "high" > direction
echo "low" > direction

Or alternatively :

echo "out">direction (set port as output)
echo "1">value
echo "0" value

Done !
If you want then to unmount the device, use unexport :

cd /sys/class/gpio/
echo 150 > unexport

While you're at it, you can also play with the user button :

cd /sys/class/gpio
echo "7" > export
cd gpio7
echo "in" > direction (set port as input)
more value (should return 0 if usr button is not pressed, 1 if pressed ...).

A c program would do much the same, opening and writing (or reading) to the same files.

We definitely should set up some kind of 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 ... That would make starting applications (say robotics ...) with beagle much faster !! I do prefer learning by example rather than reinventing the wheel by parsing hundreds of pages of doc and googling around, even if the latter can't always be avoided :wink:
Have fun !!

    Laurent

-----Message d'origine-----

Laurent,

Thanks for explaining the GPIO features in more detail. I wrote the
GPIO article and code over at Makezine, but I haven't had much luck
learning anything beyond the basics of what I showed in my article.

I tried to learn how to communicate over I2C from Antti Seppänen's
BeagleBot page at http://www.hervanta.com/stuff/Beaglebot, but a lot
of that went over my head.

I think the tutorials you describe would be very helpful; I think many
would benefit from something that explains what needs to be done to
prepare a kernel to use these interfaces and how to write and compile
userspace code for this. I think it would be helpful to see how to
wire things up, as well, including some information on connecting to
3v and 5v devices (Spark Fun sells a logic level shifting board that
may come in handy: http://www.sparkfun.com/commerce/product_info.php?products_id=8745).

Thanks,

Brian

Thanks So much Laurent and Brian. This worked great

If you don't have it, just use basic GPIO
cd /sys/class/gpio
echo 150 > export (150 is usr1 LED, 149 is usr0 ... You can also >access expansion port GPIO that way, say 168 for pin 24)

That should create directory /sys/class/gpio/gpio150, with all the access >you want.
cd /sys/class/gpio/gpio150
echo "high" > direction
echo "low" > direction

Or alternatively :

Does anybody know how to get this code to work in c? I am using the
code sourcery G++ compiler.

Don't use that, angstrom is not compiled with a CSL compiler, so you're facing lots of compatibility issues when using harry potter toolchains (apart from bugs like -Os, NEON, right shifts and non-qemu platforms not working)

regards,

Koen

Do you have a recommendation for a compiler? Before you responded that
was the one I should put onto the board. I don't mind using a
different one I just don't know what one to use.

I recommended using the angstrom one, which isn't CSL for sure.

regards,

Koen

if that's the case, i suspect a number of web sites should update
their recommendations. if you google on something like "angstrom
beagleboard compiler", you find a number of sites like this:

http://garrenblog.blogspot.com/2008/10/adventures-in-beagleboard-land-compiler.html

which read, "The compiler used with the Beagleboard is the one from
Codesourcery." so if people should be using a different one, a link
to that one should probably be more prominently displayed everywhere.

rday

Just use the toolchain OE builds for you or install a native one from the feeds on the beagle itself, you can't go wrong that way. I can't stop people from posting nonsense to wikis and blogs, no do I want to.

regards,

Koen

Just use the toolchain OE builds for you or install a native one from
the feeds on the beagle itself, you can't go wrong that way. I can't
stop people from posting nonsense to wikis and blogs, no do I want to.

I still have not gotten OE to work Yet. I am just using the angstrom
2.6.28 from

http://www.angstrom-distribution.org/demo/beagleboard/

...LOL Oh you know what I might be using the right compiler, I assumed
that g++ stood for code sourcery g++. I followed this....

Sorry for making so many dumb requests but...I was wondering if koen
had made an angstrom image with a decent gui c++ compiler that had a
library with easy access to the gpio and usb ports and such? And if so
where can I download it, and what is the compiler called in Angstrom?

"opkg install task-native-sdk" in any image and the compiler is
called
'g++"

regards,

Koen

Statement that you had made. So Do I have the right compiler? This is
the one I am using. I think I might be mistaken.

And my streak as an idiot continues!!!!!!!!!!!!!forever hahahahfhahh

thanks

Yes

regards,

Koen

oh and if I do have the right G++, is there some documentation on it
that you know of so I can figure out what general and special
functions it has?

Thanks for all the help...

Ohh and I have a data plan on my cell phone and it provides ethernet
to the beagle it is awesome...but I still have not figured out how to
get it to work in the image with the desktop, only working for command
line.

Well thanks to everyone above I have put together a C program to blink
the LED...unfortunately the code seems much more confusing than it has
to be. Let me know if there is an easier way to do this. Another issue
is that the port pin must be initialized before the program is run or
it will not work. Let me know if there is a fix for this. I took most
of this code from...

http://www.avrfreaks.net/wiki/index.php/Documentation:Linux/GPIO#Getting_access_to_a_GPIO

and modified it a bit to work. Please re-post with fixes if possible.
For Angstrom image 2.6.28

Sorry that was a bit confusing

<echo 150 > /sys/class/gpio/export>

Type the > after 150

I wrote a small lib for myself to use the GPIO pins from C++ in a much
easier way, wrote a few examples to drive LCD displays as well
including a nokia 6100 lcd using SPI

https://github.com/majestik666/Beagle_GPIO

Nice work. Similar to what I have done myself but quite a bit more polished :slight_smile: