Getting started

Here are my BeagleBone Black (Revision A5B) notes.

These litte boards are my favourite. Very straightforward and easy to use.

Getting ssh to a 3B, as in three Bs in BeagleBone Black, is easy.

I connected 3B via USB using ovided USB cable to my Ubuntu running laptop.

Then sshed to root@192.168.7.2 with no password.

Then I plugged the 3B via CAT5 to a switch. Another network interface was created automatically.

Lesson I should’ve learned first is that time on the board won’t be accurate and I need to update it first.

Ideally the update should go to startup somewhere.

/usr/bin/ntpdate -b -s -u pool.ntp.org

Angstrom upgrade

One thing I wanted to avoid this time (I had some failures with the previous white BB) is changing image on the board.

Instead I decided to simply stick with Angstrom and just make an upgrade of the system. It’s definitely much easier than installing new image.

opkg --tmp-dir ~ update
opkg --tmp-dir ~ upgrade

Adafruit_BBIO - GPIO Python library

I checked for any Python GPIO library and found one from Adafruit. Fun fact, it’s a fork of RPi GPIO.

Install instructions from https://github.com/adafruit/adafruit-beaglebone-io-python

/usr/bin/ntpdate -b -s -u pool.ntp.org
opkg update && opkg install python-pip python-setuptools
pip install Adafruit_BBIO

Check if all got installed okay:

root@beaglebone:~# python
Python 2.7.3 (default, Jul  3 2013, 18:32:36)
[GCC 4.7.3 20130205 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_BBIO.GPIO as GPIO
>>>

Installation of Mosquitto MQTT broker

There isn’t any Mosquitto package for Angstrom so I installed Mosquitto by hand.

opkg install packagegroup-core-buildessential
cd
mkdir install
cd install
wget http://mosquitto.org/files/source/mosquitto-1.2.3.tar.gz
tar xvfz mosquitto-1.2.3.tar.gz
cd mosquitto-1.2.3
make
make install

I tried to run mosquitto but it threw an error at me:

Error: Invalid user 'mosquitto'.

Turns out that when you try to run mosquitto as root it tries to run itself with privileges to user mosquitto.

User mosquitto was obviously missing so I created one.

adduser mosquitto

mosquitto then started sucessfully.

root@beaglebone:~# mosquitto
1391363541: mosquitto version 1.2.3 (build date 2014-02-01 14:09:24+0000) starting
1391363541: Using default config.
1391363541: Opening ipv4 listen socket on port 1883.
1391363541: Opening ipv6 listen socket on port 1883.

I forgot to add /usr/local/lib to /etc/ld.so.conf before I compiled mosquitto so I had to add the path to PYTHONPATH manually to make it available in python. See .bashrc below.

NTP installation

I installed NTP to avoid having wrong time after every reboot.

opkg update && opkg install ntp
systemctl enable ntpdate.service
systemctl enable ntpd.service

I checked http://www.pool.ntp.org/ to get list of servers for /etc/ntp.conf

I also changed the nptdate.service and ntp.conf as per http://derekmolloy.ie/automatically-setting-the-beaglebone-black-time-using-ntp/

Basically the changes were to use 'ExecStart=/usr/bin/ntpd -q -g -x' in /lib/systemd/system/ntpdate.service and commenting out the following lines in /etc/ntp.conf

# Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself
#server 127.127.1.0
#fudge 127.127.1.0 stratum 14

These changes make sure that NTP keeps time up-to-date.

Setting static IP address

I found an excellent post re how to setup static IP address on BeagleBone. Setup basically takes two steps:

root@beaglebone:/usr/lib/connman/test# ./set-nameservers ethernet_c8a030bb9eae_cable 8.8.8.8
Setting nameserver to ['8.8.8.8']
root@beaglebone:/usr/lib/connman/test# ./set-ipv4-method ethernet_c8a030bb9eae_cable manual 192.168.2.222 255.255.255.0 192.168.2.1
Setting method manual for ethernet_c8a030bb9eae_cable
New IPv4.Configuration:  {'Netmask': dbus.String(u'255.255.255.0', variant_level=1), 'Gateway':
dbus.String(u'192.168.2.1', variant_level=1), 'Method': dbus.String(u'manual', variant_level=1), 'Address':
dbus.String(u'192.168.2.222', variant_level=1)}

It’s definitely good to read the mentioned post and get familiar with how the networking works.

Environment setup

Then I got my usual stuff.

pip install virtualenv
pip install virtualenvwrapper
pip install mercurial
opkg install sudo

Added myself an user:

adduser brain

Then I added the new user to sudoers and also added my key to authorized_keys.

I also changed /bin/sh to /bin/bash in /etc/passwd for user brain.

I added basic .bashrc file and sourced/reconnected to the board to get new env setup:

# Virtualenv setup
export WORKON_HOME=$HOME/.brain
source /usr/bin/virtualenvwrapper.sh
# Useful aliases
alias ls='ls --color'
alias l='ls -lh | more'
alias ll='ls -lha | more'
alias lrct='ls -lrcth | more'
alias v=vim
# The following is to include Mosquitto's Python library
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/

One-Wire DS18B20

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    part-number = "BB-W1";
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
        /* the pin header uses */
        "P9.22",
        /* the hardware IP uses */
        "gpio0_2";

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
               dallas_w1_pins: pinmux_dallas_w1_pins {
                    pinctrl-single,pins = <                             0x150 0x37                         >;
               };
        };
    };

    fragment@1 {
        target = <&ocp>;
        __overlay__ {
            onewire@0 {
                compatible      = "w1-gpio";
                pinctrl-names   = "default";
                pinctrl-0       = <&dallas_w1_pins>;
                status          = "okay";

                gpios = <&gpio1 2 0>;
            };
        };
    };
};
dtc -O dtb -o BB-W1-00A0.dtbo -b 0 -@ BB-W1-00A0.dts
cp BB-W1-00A0.dtbo /lib/firmware/
echo BB-W1:00A0 &gt; /sys/devices/bone_capemgr.9/slots
import time

w1="/sys/bus/w1/devices/28-00000494f4fd/w1_slave"

while True:
    raw = open(w1, "r").read()
    print "Temperature is "+str(float(raw.split("t=")[-1])/1000)+" degrees"
    time.sleep(1)

Source: http://hipstercircuits.com/dallas-one-wire-temperature-reading-on-beaglebone-black-with-dto/