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!


Sunday, May 5, 2013

Beaglebone Black Experiences

I am just turning my procedures document into something others can read.  I am skipping some of the info I found easily online.


What are you up to?

Where I work, we make equipment that detects nuclear radiation.  Close to that equipment, we have computers that aggregate the information, perform calculations, make decisions, and at some point they might record information in a database or post information for users to observe either on computers or other devices.

Obviously, we are always trying to do more for less. 

I am up to other things at the same time but, basically, I am looking for a small cheap way to get all that done.

The Beaglebone Black ('Bone' for short) is a good place to start.

A bit more about where I am going:

We use C# and the .NET Framework mostly.  I have Unix experience but it is in the distant past.  I really like to dodge using Linux development tools and get the Bone running my C# code.

The way to do that is to get Mono working on the Bone.  Mono is a small CLR and .NET Framework that can run on Linux. 

What is a Beaglebone Black?

A Beaglebone is a ultra-lowcost single board computer: http://beagleboard.org/Products/BeagleBone%20Black

The 'Black' is a recent (2013-05-05) variant with greater power and lower cost.  I jump right into it since you really just need to know if you are not interested in reading any further.

I will keep this simple.


A Little More About the Bone?


If you want to stay with me here ...

Features:
Board:  3.4in x 2.1in (fits in an Altoids tin)
Memory:  512Mb
Disk (well ... not really):  2Gb EMMC and an SD card slot
Microprocessor:  TI AM3359 Sitara ARM Cortex-A8 Microprocessor
Speed:  1GHZ with DC Power (5V) / 500MHZ with USB Power
Ethernet:  10/100 RJ45

Weight:  1.4 oz (39.68 grams)

Connections:
5V Power
USB In
USB Out
Micro HDMI Video Out
RJ45
Micro SD Socket
Numerous general purpose I/O points including serial ports, digital I/O, analog I/O etc. 

The board has three pushbuttons: reset, power and boot.

Where did you get it?

Amazon through Special Computing.  I bought a pair (one for me and one for my son) BeagleBone Black DevKit at a whopping $45.00 each. 

What you get in the box?

Not much but you don't need much.
You get the board and a USB cable to connect it to your computer.
You get a card with almost no info except where to get other info on the web.


Now I am gonna fast forward to doing some things and I will fill in later.


How do you 'Factory Reset' the bone?

See, I munged the thing several times so getting it back to 'as shipped' condition was important.

The 'getting started' site kinda explains the process as 'obtaining the most current Angstrom' distribution: http://beagleboard.org/static/beaglebone/latest/README.htm

However, I ran into a raft of difficult detials:
  • The MD5 Hash check box in the imager dialog MUST be checked.
  • The USER/BOOT switch is on the Black board just above (top side) the SD card coupling.  You hold it down while you power up to make it run from the SD card (which flashes the NAND).
  • Flashing the NAND took ALL of the 45 minutes they said it would and it the LEDs flash like crazy while it is going on.  In particular, USR3 was on a lot but not during normal operation.

Apparently, the SD image with flash the NAND weather or not you push the USER/BOOT button.  I put it in again and rebooted without the U/B button and signed up for another 45 minute reflash.

Mounting a Thumb Drive

  1. Insert the drive (it took a second to blink)
  2. Run dmesg which will give  you a hint what device the drive was loaded
  3. Make a folder to mount it on: mkdir thumb
  4. Mount it: mount /dev/sda thumb
  5. Play
  6. Unmount it: umount /dev/sda

Getting Mono to Work

The Package

Looking for a mono that would go with the Angstrom linux distribution on the Bone, I found:  http://www.angstrom-distribution.org/repo/?pkgname=mono

There are a coupla versions there and I picked:  mono 2.10.8.1-r0 for armv7a (Ångström v2012.05 eglibc armv7a base feed)

Once I had the file in hand,

    mono_2.10.8.1-r0_armv7a.ipk,

I copied it to a thumb drive.

The 'Hello World' App

Now I needed a tiny Windows app to verify my mono would work.

I build a console app with the following source code:


    using System;

    namespace Hello
    {
        class Program
        {            static void Main(string[] args)            {                Console.WriteLine("Hello, Bone!");            }
        }
    }


Not quite sure which .NET version the Mono covered, I built this targeting .NET Framework 2.0.

I ended up with a Hello.exe.  I ran it on Windows to make sure then copied it to the thumb drive.

Putting This On The Bone


I moved the thumb drive to the bone.  Using the procedure above, I mounted it on a directory called thumb.  I installed the mono package:

ipkg install thumb/mono_2.10.8.1-r0_armv7a.ipk



Note: I had completely 'boned' the Bone before (requiring the factory reset procedure) and I believed it had to do the limited free space on the 2Gb drive being bogarted by copy things off the thumb drive.  This time I installed from the thumb drive with better results.

Trying it Out


I copied the Hello.exe program from the thumb drive and ran it


Does not look like much but I did a ton of crap wrong on the way to this so I was pretty glad to see it.

So mono will take a Win app as an argument and run it for you.


Thats it!