When writing about the Beaglebone in the past, I mentioned that you needed to be running Angstrom in order to have access to certain devices, since they weren’t yet supported by the kernel in Ubuntu.
Well, I’m rather late in giving Ubuntu its props, but that’s no longer true. Ubuntu has caught up to Angstrom in protocol support: analog input, PWM, SPI and I2C are all working.
In order to get these features, you need to have a recent kernel. I’m not sure exactly which kernel version they were added in — 3.2.twentyish — but current kernel version for Ubuntu is 3.2.28. If you’re running an earlier kernel, I’d recommend that you upgrade.
To determine your current kernel version, run the following command
ubuntu@omap:~ uname -r 3.2.21-psp16
You have a couple of options for getting the latest and greatest Ubuntu kernel.
Creating a new Ubuntu Image
If you aren’t already running Ubuntu on your Beaglebone, you can download a new image.
You’ll need to use Robert C Nelson’s customized Ubuntu build. The instructions for creating the image are on the eLinux Beagleboard page, under “Demo Image”. (Don’t be put off by the word “demo” — it’s a fully functioning Ubuntu distribution, with a vast array of available packages).
The procedure is quite reliable and mercifully free of obscure Linux commands, but you will need to be running Linux to write the image to the microSD card.
Before starting, you’ll need to decide which Ubuntu version to run on your Beaglebone. The latest released version is usually a good bet, currently Precise 12.04. That’s the one I’m using.
However, if you plan to use a GUI desktop, then you may want to drop back to the previous version, Oneiric 11.10. That’s because the 12.04 release is compiled with hardware floating point support (aka “armhf”), and while that makes some things faster (the apt-get package manager is noticeably zippier), it reportedly makes some GUI packages too slow to use. The kernel version in Oneiric is the same as in Precise, so as far as I know you can still get analog in, PWM, I2C and SPI with that release.
You should refer to the eLinux page for the latest instructions, but here are the steps you would currently following to create a microSD card with Precise 12.04 on a Linux desktop:
1. Begin by downloading the image file. It’s not huge, a little over a hundred megs:
2. While you’re waiting for it to download, insert your microSD card. It needs to be 4G or higher. Personally, I’m sticking with 4 or 8G cards, since some people have reported problems with higher capacities: it depends on the manufacturer. Also, I’d suggest you use a USB card reader that has a microSD card slot. I’ve personally had problems with those SD card-sized adapters that allow you to fit a microSD card into an full SD card slot.
3. Determine what your microSD card device ID is, and make sure it wasn’t automatically mounted by Linux. The easiest way to determine the device ID is to run the dmesg command after inserting the card: the messages at the end of the output will include the device ID.
The format will be /dev/sdX, where X varies. For example, on my PC it’s /dev/sde. Note that you want the device ID, not the partition ID: that is, /dev/sde, not /dev/sde1.
To check if the card was mounted, run the “mount” command. Look at the lines at the bottom of the output to see if they contain your card’s device ID, such as:
/dev/sde1 on /media/sde1 type vfat (rw)
If so, you’ll need to unmount them before writing the image to the card. Personally, I’ve had problems when unmounting from Ubuntu’s file manager (the device ID is no longer recognized by the OS after doing so), so I’d suggest you do it from the command line:
sudo umount /dev/sde1
4. Once the download from step 1 has completed, you’re ready to run the commands to write the image to the microSD card.
tar xJf ubuntu-12.04-r5-minimal-armhf-2012-07-29.tar.xz cd ubuntu-12.04-r5-minimal-armhf-2012-07-29
Note: In the following command, replace “/dev/sdX” with the actual device ID from step 2 (e.g. /dev/sde). Unlike the previous commands, this one needs to be run as root:
sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone
This script handles all the nitty gritty work for you: it repartitions the card, builds the boot and root partitions and downloads the latest kernel for you. The whole thing should be done in 20-30 minutes. If you find it still grinding away after an hour, there’s likely a problem with the card or the way its connected to your PC: if you ignored my advice from step 2, you might want to reconsider it now.
5. When the script completes, you’re all done. Unmount the card from your Linux PC, if necessary, then pop it into the Beaglebone. The initial bootup will be slower than subsequent boots, generally a few minutes. You’ll need to login as user-ID ubuntu, password temppwd. The ethernet port is configured for DHCP (using /etc/network/interfaces, not connman, yay!), and SSH is enabled by default.
Upgrading the Ubuntu Kernel
Unlike Angstrom, Ubuntu doesn’t automatically deliver new kernel releases via its package manager, apt-get. So, if you installed Ubuntu on your Beaglebone awhile ago, you’ll find that kernel version has become quite outdated. Fortunately, Robert C Nelson has made the upgrade process quite easy to do manually.
The procedure depends on which Ubuntu release you’re running on your Beaglebone. In my case, running the 12.04 armhf image, instructions are at http://rcn-ee.net/deb/precise-armhf/LATEST-omap-psp:
ABI:1 EXPERIMENTAL http://rcn-ee.net/deb/precise-armhf/v3.2.0-rc2-d0/install-me.sh ABI:1 TESTING http://rcn-ee.net/deb/precise-armhf/v3.2.0-psp0/install-me.sh ABI:1 STABLE http://rcn-ee.net/deb/precise-armhf/v3.2.28-psp21/install-me.sh
The “stable” version is, of course, the best choice. So, to upgrade hte kernel to 3.2.28, I’d run the following commands on my Beaglebone:
wget http://rcn-ee.net/deb/precise-armhf/v3.2.28-psp21/install-me.sh sudo bash install-me.sh
The script will download and install the kernel and related files (kernel modules, etc.). The process should take about 5 minutes, depending on the speed of your microSD card. If all goes well, the script should end with a reboot message:
. . . `/boot/vmlinuz-3.2.28-psp21' -> `/tmp/boot/zImage' `/boot/initrd.img-3.2.28-psp21' -> `/tmp/boot/initrd.img' Please Reboot
Instructions for upgrading the kernel in other Ubuntu versions, and for other hardware architectures, can be found in other subdirectories of http://rcn-ee.net/deb. For example, if you’re running 11.10 Oneiric on your Beaglebone, upgrade instructions are in http://rcn-ee.net/deb/oneiric-armel/LATEST-omap-psp. (In Ubunuese, “omap-psp” means Beaglebone, apparently.)
Enabling Analog Input
After booting your new image, you should find PWM, SPI and I2C in their expected file system locations:
ubuntu@omap:~$ ls /dev/i2c* /dev/i2c-1 /dev/i2c-3 ubuntu@omap:~$ ls /dev/spi* /dev/spidev2.0 ubuntu@omap:~$ ls -Fd /sys/devices/platform/omap/e* /sys/devices/platform/omap/ecap.0/ /sys/devices/platform/omap/ehrpwm.0/ /sys/devices/platform/omap/ecap.1/ /sys/devices/platform/omap/ehrpwm.1/ /sys/devices/platform/omap/ecap.2/ /sys/devices/platform/omap/ehrpwm.2/ /sys/devices/platform/omap/edma.0/
Analog support has a twist: the file system interface is implemented in a kernel module, which isn’t loaded by default. To load it, enter the following command:
sudo modprobe ti_tscadc
The file system interface should then be visible:
ubuntu@omap:~$ ls /sys/devices/platform/omap/tsc/a* /sys/devices/platform/omap/tsc/ain1 /sys/devices/platform/omap/tsc/ain5 /sys/devices/platform/omap/tsc/ain2 /sys/devices/platform/omap/tsc/ain6 /sys/devices/platform/omap/tsc/ain3 /sys/devices/platform/omap/tsc/ain7 /sys/devices/platform/omap/tsc/ain4 /sys/devices/platform/omap/tsc/ain8
To have the kernel module loaded automatically when the Beaglebone is rebooted, enter the following commands:
ubuntu@omap:~ sudo -i root@omap:~# echo ti_tscadc >> /etc/modules root@omap:~# cat /etc/modules # /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. ti_tscadc root@omap:~# sudo depmod -a
You should find that analog input, PWM, I2C and SPI all work the same way in Ubuntu as in Angstrom. Code that you find for using these features on Angstrom will work on Ubuntu without any changes. Here are a couple of articles I wrote on using analog input and PWM:
I’ve recently been using both SPI and I2C on the Beaglebone to write to LCDs from Python, and I plan to write articles on these in the future.