June 13, 2013
Beaglebone and Hardware interfacing
Hardware interfacing is what a Beaglebone is all about.
Two things require special care.
One is that the the Beaglebone uses 3.3 volt logic and will be damaged
by 5 volt logic signals.
The other is that analog signals must be in the
range 0.0 to 1.8 volts or damage will occur.
Here are some links:
Javascript, node, and bonescript
One approach to writing software to control external devices
(or in a degnerate case, internal devices such as one of the four on-board LED's)
is to use "bonescript". This is a javascript library, and the intent is that you
would be using this via the Cloud 9 IDE (which I strongly disrecommend).
Just ssh into your beagleboard, use your editor of choice (such as vim),
create a file mything.js, then run it from the command line via "node mything.js".
This spares you the agony of dealing with Cloud 9 bugs.
Other languages
You have a multitude of options. You can program in C.
For some unexplainable reason there seems to be a strong following using Python (I hate Python).
You can install ruby and use ruby bindings to the BBB IO system.
I haven't heard anything about using Perl, yet - but I haven't looked either.
You can write bash scripts and control pins using entries in the filesystem.
Take note that the BBB kernel IO scheme changed as of the 3.8 kernel,
some of the links that follow discuss this, beware of information online
that describes the old arrangement.
If you dig a bit, you will find that bonescript works via the filesystem.
Other language bindings may do so also.
Linux device drivers
It is not out of the question to write your own device driver,
though this is not a task to be underestimated.
The biggest annoyance with a device driver is that it needs continual care
and feeding if you update linux kernels and expect your driver to keep working.
I supply dates for many of the above. They describe general concepts, but kernel device drivers
are definitely an area where the devil is in the details, and the details are always changing.
Hardware Interfacing
The AM3359 chip has 128 gpio pins, of which 65 are routed to the BBB headers.
The headers each have 46 pins (so there are 92 header pins in all).
25 pins are dedicated to things other than GPIO pins
(There are 9 pins for the analog inputs, and a number of power and ground pins).
These numbers do not add up right, and I have yet to straighten it all out.
Some easy ways to connect to the IO pins would be:
There are numerous charts and diagrams showing the assignment of signals on the P8 and P9 headers.
It is worth double checking these against each other.
Pins and current drive capability
GPIO pins can source varying amounts of current.
Some sources say 8 or 6 mA, others say 6 or 4 mA.
One fellow ground his way through the datasheet to discover:
The max current source capability is 6mA for all GPIO pins EXCEPT
gpio0[7,12,13,14,15,18,19,20]
gpio1[8,9,10,11]
gpio3[5,6,13]
which are 4mA max.
Of the GPIO signals brought out to P8 and P9 headers, all are 6mA max EXCEPT
P9_19 gpio0[13]
P9_20 gpio0[12]
P9_24 gpio0[15]
P9_26 gpio0[14]
P9_41 gpio0[20]
P9_42 gpio0[7]
which are 4mA max.
Dealing with 3.3 volt logic
The BBB pio inputs will not like to be driven by 5 volt signals.
The easy approach for inputs is a resistor divider.
A 2.5 volt signal will drive 3.3 volt logic to a true (high) state.
The BBB output are 3.3 volt also and will not directly drive good old
5 volt TTL. There are special chips designed to change levels and
solve this problem, but a plain old NPN transistor (like a 2N3904)
works just fine. A n-channel FET like the 2N7000 might be even better.
I have been entirely successful just using a generic NPN bipolar transistor (like the 2N3904)
and driving the base directly from the BBB GPIO pin. This sounds a bit unsavory though
since nothing obvious is limiting the base current (BBB pins can source 6 or 8 mA depending
on the pin).
The Beaglebone 3.3 volt logic can actually drive some 5 volt logic families
directly (in particular you can drive 74HCT parts directly with 3.3 volt logic).
Special 3.3 volt interface chips (that you really don't need)
One good choice is probably the Texas Instruments TXB0108 chip:
You can buy the chip from Digikey for about $2.00, but they are surface mount.
Another option is the SN74LVCC3245.
The 74HC4050 is available in a DIP package and handles 6 signals.
Feedback? Questions?
Drop me a line!
Tom's Computer Info / tom@mmto.org