Friday, May 24, 2013

Beagle Bone GPIO

I ran into some trouble accessing the Beagle Bone Black GPIO (general purpose IO) mostly because of a change in the access technique that is a part of the most recently released Angstrom Linux.  


The video I was following was: 
http://www.youtube.com/watch?v=SaIpz00lE84 


It is very well done and I was bebopping along. I wired a transistor driven LED as described in the video and hooked it to pin 12 of the P9 header.  The wheels fell off when the commands were referencing /sys/kernel/debug/omap_mux, and ... I did not have one.  All the stuff I found online talked about going to that directory.

Much searching ensued.  Turns out this document helped a great deal in describing the new technique:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/gpio.txt?id=refs/tags/v3.8.11


Here is what I was able to get to work!


As yet I am unable to remap the mode.


Best I understand the BBB boots into mode7.  I understand that in mode7, that pin is mapped to GPIO1_28. 

So the '1' in there represents the bank.  There are 4 banks with 32 I/O points on each.  The '28' is the I/O point in that bank.  The 'single value' that represents that I/O point is 60 (1 * 32 + 28).  

The second document sent me to the directory /sys/class/gpio.  

cd /sys/class/gpio

In that directory are 'export' and 'unexport' write-only files.  If you echo a number into export 

echo 60 > export

then a local folder is created called gpio60 which give you access to the 60th GPIO or GPIO1_28 ... get it!

So now you go to that directory and look around

cd gpio60
ls -l

In there you will discover some control files.  The direction file can be catted

cat direction

to discover the direction.  Mine was 'in' and I wanted it 'out' so I typed

echo out > direction

This turned off my LED.  It had been on all this time.

I catted the value file

cat value

to discover the value.  Sure nuff, it was 0.  I was able to turn the LED on and off with 

echo 1 > value

and 

echo 0 > value

respectively.

I'm on my way!


No comments:

Post a Comment