smellsofbikes: (Default)
2015-03-12 10:59 pm

notes on beaglebone 1: setup

First step: installing software.
I'm type 2 lazy, meaning I do a bunch of work so I can sit in my chair later. As such, I set up port forwarding on my laptop so I can do all my upgrades and work from the laptop rather than having to walk downstairs where the ethernet cable lives.
So: USB connecting bbb to laptop, allowing me to ssh into the bbb and run it. Cat5 cable from bbb to laptop, with port forwarding set up.
On bbb:
ifconfig eth0
ifconfig add default gw
On laptop, start with an ifconfig and look at the output. There should be two eth[x] entries, one of which will include the entry. That's actually the usb. So you want to configure the other one, which is the hardware associated with the port where the cat5 cable lives. For this example I'm presuming it's eth1, and your wireless connection is wlan1.
sudo ifconfig eth1
sudo iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE
sudo iptables --append FORWARD --in-interface wlan1 -j ACCEPT
sudo echo 1 > /proc/sys/net/ipv4/ip_forward

If you're using xubuntu (or apparently a few other distros) that last line won't work because for whatever reason '>' doesn't inherit sudo permissions. So you have to punt:

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Now you can start work on the bbb.
apt-get update
apt-get upgrade
apt-get install alsa-base alsa-utils

Mine already had all the alsa stuff installed. A bunch of programs didn't successfully upgrade, like apache and dbus, which I need to look into later, but I don't actually use any of those for this project so I don't care. [note 1]

Now, disable HDMI so that we can get audio to the usb.

Go to /boot/uboot and edit uEnv.txt to remove the comment status from the line disabling hdmi. It'll be optargs=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN
Then go to /etc/modprobe.d/alsa-base.conf and edit it to change the index on snd-usb-audio from -2 to 0.
Reboot the bbb with your usb soundcard plugged in.
For me, this resulted in being able to play music. I needed some music to play and a player.

apt-get install mpg321
wget http://www.noiseaddicts.com/samples/1456.mp3

(you might want to change your working directory to /home/debian before doing that, rather than sticking an mp3 in /etc/modprobe.d)
and then you can mpg321 1456.mp3 and hear some noise.
mpg321 will also accept url's, so:
mpg321 somafm.com/indiepop.pls
will bring up a menu of soma's indiepop streams that you can connect to and start playing. Take note of the stream names and you can use them directly without having to select This is useful for completely headless operation.
I used a Syba usb soundcard. It works beautifully.

[note 1]
For some reason, led_aging.sh is a screwed-up file, and prevents apt-get update from working correctly on half a dozen packages.
From here: https://groups.google.com/forum/#!topic/beagleboard/LPjCn4LEY2I
do this:
Replace the existing /etc/init.d/led_aging.sh script with:

#!/bin/sh -e
# Provides: led_aging.sh
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start LED aging
# Description: Starts LED aging (whatever that is)

x=$(/bin/ps -ef | /bin/grep "[l]ed_acc")
if [ ! -n "$x" -a -x /usr/bin/led_acc ]; then
/usr/bin/led_acc &
smellsofbikes: (Default)
2015-03-12 11:03 pm

notes on beaglebone 2: systemd

You want a program to start running every time the beaglebone boots.
Use systemd because it's there and it actually works okay.

In /lib/systemd/system/ make a file (programname).service
So for this example, blinker.service

It should look like this:




Then go to /etc/systemd/system/multi-user.target.wants and make a symlink to that file.

ln -s /lib/systemd/system/blinker.service /etc/systemd/system/multi-user.target.wants/blinker.service

The file itself, if it's python, must begin with #!/usr/bin/python (or wherever you have python installed) and be executable.

Then, systemctl --system daemon-reload
and systemctl start blinker.service

and your program should start immediately and also start every time you boot the beaglebone.

If your program is dependent on other services before it starts, you can add those under the [unit] group, like:

That way it will wait until the network is up before running -- which, in the case of what I'm building, is nice, because it's streaming internet radio.