BeagleBone Development
Introduction
TI is promoting a small embedded Linux board called BeagleBone. It uses TI's ARM processor: datasheet. The board is small, about 2 by 4 inches, and has an abundance of capabilities. I wanted such a system for several uses as a network attached controller for my projects. The board is available from many suppliers: Adafruit and Makershed for example ($89).
BeagleBone (BB) is evolving out of the Arduino world more than the Linux world. As a result the introductory material is focused on basic, simple to program, examples. The real power comes when the machine is used as a network attached controller communicating on with some electronics and taking commands and providing a display via a web browser. This article will show how I got enough pieces together to accomplish that goal.
Development Choices
I'm using a pc with Windows 7 here.
A 4MB microSD card comes with the BB. It worked fine but I got a couple of 8MB cards and copied images of the Angstrom Linux distribution to them using 7-Zip File Manager and Win32DiskImager. I spent too much time on this because my initial reading seemed to indicate that one could use some built-in tools on BB. These use node.js and a browser based developement system called Cloud9. In the included distribution some of this didn't work and I dropped back to the previous one (May 2012.) This work uses that image. It is good to know how to get a fresh image and a good deal of online help is available to get this piece done. For my work, I simply ignore Cloud9 and the JavaScript stuff.
The BeagleBone can be hooked to a pc via a usb cable to provide access and power. As I wanted a network attached device, I skipped this step and connected a 5VDC supply (which gets me the faster clock rate anyway) and an ethernet cable. Using PuTTY and locating the BB at 192.168.0.12 using Advanced IP Scanner. You could look in your router's tables. PuTTY should be used as a SSH (Secure SHell) terminal. Log in as root (there is no password initially). My Linux/Unix knowledge was never great and now rusty but it is all coming back to me now.
Another initial trauma about BB is that there are so many controllers builtin that there are not enough I/O pins (even though there are a huge number) to access everything at the same time. So every pin is multiplexed and must be configured to connect to the desired device (uart, spi, I2C, digitial I/O, etc.) The initial configuration isn't all that intutive but, it is what it is, so just change it. Two sources are helpful at the start a getting started video at Make and a set of blog posts here.
More on pin muxing later.
Now I wanted to try some things. I wished I'd know about WinSCP sooner rather than later. The Angstrom doesn't have any FTP server installed so I looked high and low for one. If I'd found one I could have used Aptana Studio for development which would have been quicker. (If I find SCP access from Aptana I'll up date this later. Right click on any dir and go to the Connections wizard but I think it only does the various FTPs.) There used to be a number of r* commands in Unix to connect to remote hosts and do things. In our brave new world we need to use s* things where s stands for secure. Where I would have used rcp 30 years ago now I need to use scp. Fortunately WinSCP is just the ticket. With PuTTY and WinSCP I can have as many shells as I need and see both my local files and BB files in an Explorer like model. Way cool. You have to assign a password to root inorder to use WinSCP automatically.
PuTTY tip: Right mouse click in PuTTY is 'paste'. If you select something in the PuTTY window itself and right click is is pasted at the command prompt. Right mouse click in PuTTY top frame get a context menu which has a 'copy all' to clipboard.
The first thing to do was to create "Hello World" in C and compile and run it. That worked first time. Mostly I want to control my electronics via C for speed and simplicty.
The next thing to get some kind of handle on is opkg. Which is the package manager used in the Angstrom distribution.
I use TextPad for my editor because I'm used to it but NotePad++ is better if you don't have Aptana. Syntax coloring in TextPad for HTML and PHP are not great.
For a webserver, after poking around a bit, I found that lighttpd is available. To that I added php.
opkg update opkg install lighttpd lighttpd-module-fastcgi opkg install php php-cgi php-cli php-pear in lighttpd.conf set port to 81 to avoid default server stuff uncomment module-fastcgi uncomment fastcgi.server block change bin-path to /usr/bin/php-cgi restart lighttpd with /etc/init.d/lighttpd restart (I did get an error in this process about 'Job Failed' but it actually works) now /www/pages is the place to put html or php and 192.168.0.12:81/realdata01.php is a typical url
Also note that I couldn't get Pear to work on my system. Pear is a huge archive of useful PHP code.
So now the process is edit, save, drag and drop file on WinSCP then test in PuTTY shell or browser.
Plotting the 'Weather' in my Office
Here is the result I want:
To get here requires two parts: a program to read and log data from a Weather Board (I actually have the previous version from 4 years ago) and a PHP program to generate the page. In addition a package of PHP code called SVGGraph was used to make the plots. SVGGraph was placed in a subdirectory of /www/pages. SVGGraph is really well done and well documented. It isn't perfect, but none of the other graphing options worked.
C code for the logger is here. (8KB) This gives an example of managing serial input. A good deal more information is available here. minicom is loaded with Angstrom or can be gotten with 'opkg install minicom' is useful for serial testing. As BB as about 5 uarts it is easy to connect one to another with a jumper and use minicom to see what you are doing. Connecting to my weather board required a voltage divider. Hook a 5VDC serial output to a 5.6K ohm resistor which is then connected through a 10K ohm resistor to ground. The center tap is ok for 3.3VDC on the BB.
Now we need to take up the matter of pin muxing.
One needs to run ws01 in such a way that it doesn't get killed when the shell exits. One method of running ws01 is to use crontab. That is start ws01 at sometime and after it is started comment out the crontab line that started it so it doesn't start again. Methods such as here don't work in this Linux distribution. Anyway cron jobs are likely to be useful for lots of things in this type of system. So it is good to have an idea how to schedule them. See cron examples.
Angstrom uses a newish package with systemd and the systemctl command. These are a little hard to learn but easy after you get the basic model. You need a program to run (either an executable or a shell script) this needs to be somewhere on the machine. For my example here I wrote a very small program named infinite.c
#include <stdio.h> #include <unistd.h> // gcc -o infinite infinite.c void main(int argc, char**argv){ int i; while(1){ i++; usleep(50000); } }This is all stored in /home/root/serial for no good reason. It just has to be somewhere that won't go away. Now create the following file in:
/lib/systemd/system/infinite.servicecontaining:
[Unit] Description=A program that count up After=syslog.target network.target [Service] Type=simple ExecStart=/home/root/serial/infinite [Install] WantedBy=multi-user.targetNext go to directory: /etc/systemd/system/multi-user.target.wants and
ln -s /lib/systemd/system/infinite.service infinite.serviceto create a symbolic link to the actual file in
/lib/systemd/systemNow commands like
systemctl daemon-reload (rebuilds all the systemd tables) systemctl start infinite.service systemctl stop infinite.service systemctl enable infinite.service (have it start on reboot etc) systemctl kill infinite.servicecontrol the program. Search systemctl for the man page and systemd for more information. Also the program will be started when the machine is powered up or reset.
PHP code for the website is here. (4KB) This is the rough starting place for a PHP based charting interface.
All in all a good experience. (rlb)