November 30, 2013

My second day with the Beaglebone

My first day with the Beagle Bone Black (hereafter dubbed the "BBB") certainly boiled down to a rough start. But in a way it has aimed me in the right direction. I will avoid Cloud 9 (there seems to be a concensus that it is full of bugs) and just create files with vi (which is indeed vim on the BBB) and run them on the command line with "node file.js".

The second day has gone much better, I have blinked an onboard LED, an offboard LED, and written a 10 line http server using node.js.

The offboard LED provided some interesting insights. The BBB uses 3.3 volt logic, and I measured a logic high at 3.15 volts on one of the GPIO pins. This was pretty weak driving an LED through a 270 ohm resistor. The green LED I was using drops 2.05 volts (which is pretty typical) so the current would be 1.1/270 = 4 mA, which is pretty feeble.

It was easy to add a NPN transistor, drive the base directly from the BBB GPIO pin and connect the LED and resistor to the collector, the emitter to ground. The LED is now being driven by an external 5 volt supply. This gives a current of 3/270 = 11 mA. This is exactly how I anticipate interfacing a number of lines that will need to drive 5 volt logic (although some of those may also require pull up resistors.

Another important issue is the state of pins after reset (so systems do not come on enabled and so we can avoid glitches during the interval between power on and when our software takes control. The BBB sets the pins that I have investigated so far to zero states (I measure 0 volts). With my transistor (which is effectively an inverter), this means that my LED is not coming on, although if I was using this to drive a line with a pull up, the pull up would be bringing the line high -- I will have to use an inverter to follow up lines like this in critical situations.

File layout on the BBB

There is no locate command, and ls -lR is lame as far as generating full path names. It turns out that "find / >beagle.list" did exactly what I wanted and now I can grep through this file almost as easy as using locate (maybe better). My first question is where is /var/lib/cloud9 on my BBB? I have /usr/share/cloud9 - but no /var/lib/cloud9 -- maybe this is why it did not run? Don't blame me. We have /usr/lib/node_modules/bonescript

Looking ahead

I see the future as writing a node.js server that offers http as well as socket IO on port 1776 (or some port). The client GUI will be written using JQuery and will use socket IO to talk to the server. Here is an example of how one guy did this: I thought it would be interesting to try his demo, so I did a git clone onto my linux machine, looked the files over and found that there are only 300 lines of code involved in two files (a js for the server and html for the client). The first issue I encounter is no socket.io. The next issue is that my beagle has no directory /var/lib/cloud9 (I have tripped over this before), so the question is where to install socket.io when I do install it.

Installing socket.io

I try the command:
npm install socket.io
And get an error: SSL Error: CERT_NOT_YET_VALID

The trick is that I have to set the time first:

ntpdate -b -s -u pool.ntp.org
npm install socket.io
This seems to work, and it is pulling in numerous other packages. However it places a directory node_modules at my current directory. I would rather have socket.io installed alongside the other node_modules, so we repeat the process as:
su
cd /usr/lib
npm install socket.io

Back to the demo

Again I try to run the socket.io demo:
node HtmlLedDemo.js
This seems happy now and is running a server on port 8080. And it works!! (as near as I can tell). So I can study this demo in detail. This is good. Here are the files:
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org