Book Image

BeagleBone Black Cookbook

Book Image

BeagleBone Black Cookbook

Overview of this book

There are many single-board controllers and computers such as Arduino, Udoo, or Raspberry Pi, which can be used to create electronic prototypes on circuit boards. However, when it comes to creating more advanced projects, BeagleBone Black provides a sophisticated alternative. Mastering the BeagleBone Black enables you to combine it with sensors and LEDs, add buttons, and marry it to a variety of add-on boards. You can transform this tiny device into the brain for an embedded application or an endless variety of electronic inventions and prototypes. With dozens of how-tos, this book kicks off with the basic steps for setting up and running the BeagleBone Black for the first time, from connecting the necessary hardware and using the command line with Linux commands to installing new software and controlling your system remotely. Following these recipes, more advanced examples take you through scripting, debugging, and working with software source files, eventually working with the Linux kernel. Subsequently, you will learn how to exploit the board's real-time functions. We will then discover exciting methods for using sound and video with the system before marching forward into an exploration of recipes for building Internet of Things projects. Finally, the book finishes with a dramatic arc upward into outer space, when you explore ways to build projects for tracking and monitoring satellites.
Table of Contents (16 chapters)
BeagleBone Black Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

System images


In this section, we will give you the recipes to download, install, and update the Debian distribution firmware and software kernel that comes preloaded on your board. Finally, we will walk you through changing over from the currently shipping Debian 7.0 (Wheezy) to the newer Debian 8.0 (Jessie).

There are two basic methods to install and update your board's software: install the OS onto the eMMC solid-state internal drive or a compatible SD card (refer to the compatibility list in further chapters). In either case, the process is commonly called flashing the image, which is how we will refer to it.

Note

One of the signature features of the BBB is its ability to use many different flavors of Linux to run the board. In the further chapters, you will find references and material to install various versions of Linux, including Ubuntu, ArchLinux, and Android.

OS image flashing – internal drive boot

Although your board comes preloaded with a shipping version of Debian 7, you certainly want to understand how to replace it or update it when necessary. Here, we will discuss the recipe to flash the OS to your internal solid-state drive along with how to update to Debian 8.

As of the writing of this book, Debian 8 (Jessie) is still considered a testing option, whereas Debian 7 (Wheezy) is the official shipping firmware OS for the BBB. Additionally, you will notice "LXQt" as part of the URL download link. LXQt is a lightweight Qt variant of LXDE, the Lightweight Desktop Environment. Qt is a toolset to build cross platform applications that you can use on Mac OS X, Windows, and Linux. It uses the C++ programming language and has a nice GUI builder, so it is a popular choice for many open source-centric developers.

Getting ready

You will need the following:

  • BeagleBone Black powered down.

  • A 5V DC power supply. You can also use a 5V "wall wart" power adapter with a USB port on it as long as it can deliver 1A.

  • A microSD card (4GB or greater).

  • An SD card reader. You will insert the microSD card into the card reader and the card reader into an SD port on your desktop machine.

  • A board connected to either an HDMI monitor or an LCD cape (as explained earlier in this chapter).

Note

If you had it connected, ensure that you remove the Ethernet cable before proceeding with this recipe as an Ethernet connection requires more current and will likely cause the software flashing to fail.

How to do it...

The following steps are used to flash the OS to your internal drive:

  1. Using the wget command, get the software and put it on your desktop computer.

    The latest version of the shipping OS, Debian 7 (Wheezy), is available at http://beagleboard.org/latest-images. So, you need to get the exact URL and append it accordingly in the following command:

    $ wget https://rcn-ee.com/rootfs/bb.org/release/YEAR-MONTH-DAY/lxde-4gb/BBB-eMMC-flasher-debian-7.8-lxde-4gb-armhf-YEAR-MONTH-DAY-4gb.img.xz
    

    The preceding link references a Rev. C board, the currently shipping version. If you have another version of the BBB, you can find software for prior releases at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Debian_Build_Instructions.

    Note

    Debian testing version

    You can also alternatively install Debian 8 (Jessie) using the same steps as the following, substituting the URL and appending the month, day, and year accordingly:

    https://rcn-ee.com/rootfs/bb.org/testing/YEAR-MONTHDAY/lxqt-4gb/BBB-eMMC-flasher-debian-8.0-lxqt-4gbarmhf-YEAR-MONTH-DAY-4gb.img.xz

  2. Next, unpack, unzip, or unarchive the downloaded file using your favorite archive tool. On my Mac, I use Unarchive since it's easy to use and flexible. After unarchiving, there will be an .img file available in your chosen folder.

  3. Now, we will flash the .img file to the microSD card. The easiest method is to use a GUI-type tool such as Pi Filler (originally designed for Raspberry Pi but works equally well on the BBB) for the Mac, or Win32 Diskimager on your Windows box.

    Wait for a prompt from the imaging software before actually inserting the SD card into the desktop's slot. Depending upon the speed of your desktop box's environment, the flashing/writing process will take anywhere from 15 to 30 minutes.

  4. Remove the SD card from your desktop after the flashing finishes and then remove the microSD card. Ensure that your BBB is powered down and then insert the card into the microSD slot on the BBB.

  5. Press and hold the Boot switch, which is the small button on the BBB above the microSD card slot. Take a look at the the following image to confirm that you are pressing the Boot switch and not one of the other switches:

  6. While holding this button down, insert the 5V supply into the power jack.

  7. As the board boots up, the array of LEDs next to the Ethernet jack at the other end of the board will begin flashing in a sweeping pattern.

  8. When the boot completes, all four LEDs should be lit and not blinking. Remove the power cable and then remove the microSD card from the BBB.

  9. Now, plug the 5V supply back into the board again. The BBB will boot directly from the eMMC.

  10. In your terminal window, we will now SSH into the board with the following command:

  11. When the login prompts appear, use the following credentials:

    username: Debian
    password: temppwd
    

    You should now be ready for action with the default graphical desktop showing the BeagleBone Black logo in the lower-right corner of the screen. This means that you are almost ready to go….

There's more…

Good practice to manage your system OS and files includes having enough room to add more packages, being able to clone your eMMC, and backing up your code image.

Expand your partition

Unless you use an SD card larger than 8 GB, you're likely to run out of space quickly on your card even after a modicum of packages are installed. So, save yourself a whole lot of hurt and expand your partition size….now! The following steps will be useful:

  1. Change to the root user with this command:

    $ sudo -i
    
  2. Check the disk space usage using the following command:

    root@beaglebone:~# df -h
    
  3. Go to this directory as follows:

    # cd dir: /opt/scripts/tools
    
  4. Check the available files using this command:

    # ls
    

    You will see the grow_partition.sh script. This is a bash script included in the BBB distribution that will run a routine to expand your SD card space.

    Now, run the following:

    # bash grow_partition.sh
    

    Alternatively, you can also run the following command:

    # sh grow_partition.sh
    
  5. Finally, running ls again on your drive will show a higher percentage of available space:

    # ls
    

Backing up a code image to a file

  1. Insert a microSD card into your desktop machine's card reader and confirm that it's recognized.

  2. On your desktop box (Mac, in our case), open Terminal and type the following:

    $ diskutil list
    
  3. From the list shown, write down the ID for your SD card. In my case, it looks similar to this:

    /dev/disk1
    
  4. Now, we will run a routine that backs up the content of the card to your desktop and simultaneously archives it to save space:

    sudo dd if=/dev/rdisk1 bs=1m | gzip -9 > ~/Desktop/backupimage.img.gz
    
  5. Input your password at the prompt. When you do so, the routine will run and may take several minutes depending on the amount of data you're backing up.

OS image flashing – the SD card boot

In this section, you will learn the recipes to load the OS and boot from a microSD card. Much of the process is similar to how we flash the eMMC internal drive; however, it is important to take note of the differences.

Getting ready

You will need the following:

  • BeagleBone Black powered down

  • A 5V DC power supply or a USB tethered to the BBB.

  • A MicroSD card (4 GB or greater)

  • An SD card reader. You will insert the microSD card into the card reader and the card reader into an SD port on your desktop machine.

  • A board connected to either an HDMI monitor or an LCD cape (as explained earlier in this chapter).

How to do it...

Perform the following steps:

  1. Using the wget command, get the latest software image and put it on your desktop computer.

    The latest version of the shipping OS is at http://beagleboard.org/latest-images. So, you will need to get the exact URL and append it accordingly in the following command. Note the URL difference from the prior recipe for flashing the internal drive:

    $ wget https://rcn-ee.com/rootfs/bb.org/release/YEAR-MONTH-DAY/lxde-4gb/bone-debian-7.8-lxde-4gb-armhf-YEAR-MONTH-DAY-4gb.img.xz
    

    The preceding link references a Rev. C board, which is the currently shipping version. If you have another version of the BBB, you can find software for prior releases at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Debian_Build_Instructions.

    Note

    Debian testing version

    You can also alternatively install Debian 8 (Jessie) using the same steps by substituting the following URL and appending the month, day, and year accordingly:

    https://rcn-ee.com/rootfs/bb.org/testing/YEAR-MONTHDAY/lxqt-4gb/bone-debian-8.0-lxqt-4gb-armhf-2015-05-04-4gb.img.xz

  2. Next, unpack, unzip, or unarchive the downloaded file using your favorite archive tool. On my Mac, I use Unarchive as it's easy to use and flexible. After unarchiving, there will be an .img file available in your chosen folder.

  3. Now, we will flash the .img file to the microSD card. The easiest method is to use a GUI-like tool such as Pi Filler for the Mac or Win32 Disk Imager on your Windows box.

    Wait for a prompt from the imaging software before actually inserting the SD card into the desktop's slot. Depending on the speed of your desktop box's environment, the flashing/writing process will take anywhere from 15 to 30 minutes.

  4. Remove the SD card from your desktop after the flashing finishes and then remove the microSD card. Ensure that your BBB is powered down and then insert the card into the microSD slot on the BBB.

    Either with the USB tether or a 5V power supply, power up the BBB.

  5. In your terminal window, we will now SSH into the board with this command:

  6. When the login prompts appear, use the following credentials:

    username: debian
    password: temppwd
    

Updating your current OS kernel

Sometimes, you want to stick with what you have already installed as it runs fine and does the job. But more often than not, you want the latest and greatest kernel, including updating to Debian 8.0, aka Debian Jessie. The following steps show you how:

  1. Ensure that you are logged in as the root user with the following command:

    $ sudo -i
    root@beaglebone:~#
    
  2. Check the version of the kernel that you have currently installed:

    # uname -r
    3.8.13-boneXX
    
  3. Navigate to the directory with the update kernel script:

    # cd /opt/scripts/tools/
    
  4. Run a command on the kernel you currently have installed that pulls down to your local drive information regarding any changes:

    # git pull
    

    Note

    We will explore the git command in a later chapter.

  5. Now, we will run the script that takes advantage of the information we just pulled down and updates our OS:

    # ./update_kernel.sh
    
  6. Time to reboot! Run the following command:

    # reboot
    
  7. When the login prompts appear, use the following credentials:

    username: debian
    password: temppwd
    
  8. Finally, verify that the script did what we expected through the following command:

    $ uname -r
    3.8.13-boneXX
    

Compare the preceding screen output with the version you wrote down in Step 2 of this recipe. You should, hopefully, see the new version kernel goodness.

See also

If you know a specific version you want, you can also update or modify your kernel with an alternative method using a series of command-line steps:

  1. Log in as root as follows:

    $ sudo -i
    
  2. Check the kernel version with this command:

    # uname -r
    
  3. Update your repositories with this command:

    # apt-get update
    
  4. Find available kernel versions using this:

    # apt-cache search linux-image
    

    The screen output will deliver a long list of kernel options. Scroll the list until you find one with the label: Linux kernel, version 3.8.13-boneXX (with the XX being a two-digit number).

  5. Install the kernel you want by explicitly specifying a version number from the list in the prior step as follows:

    # apt-get install linux-image-x.x.x-xx
    
  6. Reboot your board as follows:

    # reboot
    $ uname -r
    

    Your new kernel should now be installed on your board.