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

Connectivity


We will show you the two principal recipes to get your BeagleBone Black connected:

  • Ethernet

  • Wi-Fi

Beware that there is a third way to get the BBB online, which is by tethering your board to your desktop machine and piggybacking on its network connection. This is a highly useful but occasionally tricky option.

Connectivity – Ethernet

If you have direct access to your network's router, using the Ethernet connection is pretty much Plug and Play on the BBB.

Getting ready

Here's what you need for this recipe:

  • 5V DC power supply

  • An Ethernet cable

  • A BBB connected to an HDMI monitor. For ease of use and first time connectivity, we suggest that you have your board connected to a monitor for this recipe. After you gain confidence and learn more about connectivity methods, you will be able to dispense with using an external monitor.

How to do it...

Perform the following steps for Ethernet connectivity:

  1. With your BBB powered down, plug in one end of an Ethernet cable to the BBB and the other end to your router.

  2. Power up your board via the 5V power supply.

  3. The connection should occur seamlessly, assuming your Ethernet cable is sound, your internet connection is reliable, and the BBB has no defects.

  4. At your screen's login prompts, enter your login name and password. You will be taken to the desktop.

  5. Next, we will check our connection via a terminal session. In the lower left-hand corner of your screen, click on the bird-like icon and then navigate to Accessories | LXTerminal.

  6. In the open terminal window, type the following:

    $ ping www.google.com
    

    You should be getting ping responses back that look similar to the following output:

Connectivity – Wi-Fi

Since its original release in the spring of 2013, Wi-Fi on the BBB has been a bit of an Achilles Heel for the platform. Compared to the typical experience with Raspberry Pi, you could pull out your hair getting Wi-Fi to work on the BBB. If you were happy using Angstrom only for your projects, you were in luck as this distribution was (mostly) solid, given that several USB minidongles on the market worked well.

However, on Debian and Ubuntu, unless you did not mind using larger dongles with protruding antennae, connections were flaky. Alternatively, you could invest a chunk of time writing custom drivers. So much for out-of-the-box portability.

Fast forward to the (mostly) good news. With the three different Wi-Fi dongles that we tested on the current shipping version of Debian 7 Wheezy for the BBB (using 3.8.13-bone71) and on Debian 8 Jessie, we largely got positive results. The bad news? With the exception of using Debian Jessie, not all dongles were recognized by the BBB without some configuration. However, it is fairly easy to set up the hardware, and you also may get lucky with the dongle you have in your kit and get immediate connectivity.

Note

If you are using Debian 8 Jessie, skip immediately to Method Four: Debian Jessie.

Getting ready

The following are the prerequisites for Wi-Fi connectivity:

  • DC power to the BBB—the board should be powered from a 5V DC 1A minimum supply and not via USB.

  • A connected HDMI monitor.

  • Wired or wireless keyboard and mouse connected to the USB hub.

  • A powered USB hub—the Wi-Fi dongle draws more power than the BBB can deliver if you only power the board via the USB port on your client box. Instead, you need a powered hub to do the job. If you don't use a powered hub, you may be able to get away with decent stability, but you are just as likely to get poor results.

  • Wi-Fi dongle—refer to tables to test compatible versions.

We will divide this recipe into three different setup methods as some dongles are happy with one method while others prefer the second one. We will also include the setup for Debian 8.0 (Jessie) as this distribution has greatly improved and simplified the process.

Some of the setup instructions are derived from http://elinux.org/BBBWiFiConfigs.

The micro USB dongle models

The universe of low-cost Wi-Fi dongles available on the market is fairly large, the following table being a very small subset. The mini dongles we used in these recipes have been historically problematic with the BBB but are now more reliable with the current Debian distribution. Your best results, however, may be with a standard-sized (nonmicro) dongle that also comes accompanied by an antenna.

The following table shows the tested and working models of micro USB dongles for our recipes. Note that the first three models use Method Two for setup and the last two use Method Three. All dongles are priced around USD $10.00-12.00:

Method Two

Product Name

Supplier

Manufacturer

Chipset

Power requirements

NOTES

Ourlink

Adafruit

Realtek

RTL8188CUS

powered USB

This is the same product as #2

802.11b

Adafruit

Realtek

RTL8188CUS

none

This is sold by Adafruit as the same product as #1; however, there seems to be some difference since a powered USB is not required.

Trendnet TEW648UBM

B&H

Realtek

RTL8188CUS

powered USB

The board may freeze up without using a powered USB. May also need to reboot and run. Use the reset (S1) button to get a connection.

Method Three

UWN100

Logic Supply

Ralink/MediaTek

MT7601

powered USB

 

UWN200

Logic Supply

Ralink/MediaTek

MT7601

powered USB

This uses antennae.

Note

UWN200 is not tested by the author but cited by the BBB Google forum posters as a compatible dongle with possibly superior performance given the antenna addition.

How to do it...

Method one: Graphical desktop application

In lieu of the command line, the current distribution of Debian 7 (3.8.13-bone71, Wheezy) includes a handy graphical tool—Wicd Network Manager—to set up Wi-Fi. This recipe is quite simple:

  1. Power up your BBB via 5V DC.

  2. Log in to a desktop session.

  3. In the lower left-hand corner of your screen, click on the bird-like icon and then navigate to Internet | Wicd Network Manager.

  4. In the newly opened window of the application, click on the Switch On Wi-Fi button. The dongle will now begin scanning for accessible networks.

  5. Choose your local network. Enter your password in the popup window according to the type of encryption your network uses. Then, click on OK. After a few moments, your dongle will be connected.

  6. Check the connection with the ping command:

    $ ping www.google.com
    

    If all is well, you will be getting solid pingback messages.

Although the preceding steps are straightforward, you might find that your dongle will not work with this recipe or that you are using a different version of the kernel and easy connectivity eludes you. If so, here are other recipes to get connected.

Method Two: command line option 1

Consult the table at the beginning of this section for the tested models that use Method Two. Note that they all use the same RTL8188CUS chipset. This means that you will likely be able to use other dongles with the following steps as long as they use the aforementioned chipset. Now to the steps:

  1. From your BBB's desktop, open up LXTerminal.

  2. In the command prompt window, open the file in the directory specified in the following path:

    $ sudo nano /etc/network/interfaces
    

    Among other settings, you should see the following lines in the file's open window:

    ## WiFi Example
    #auto wlan0
    #iface wlan0 inet dhcp
    #   wpa-ssid "mynetworkname"
    #   wpa-psk  "mypassphrase"
    
  3. With the exception of the first explanatory line, uncomment (which means remove) the # sign at the beginning of each line. To clarify, it should look similar to this:

    ## WiFi Example
    auto wlan0
    iface wlan0 inet dhcp
       wpa-ssid "mynetworkname"
       wpa-psk  "mypassphrase"
    
  4. Change mynetworkname to your Wi-Fi network's name, and mypassphrase to your Wi-Fi password.

    Note

    If your network name uses spaces or other odd characters, some dongles may not recognize the name and establish a connection.

  5. Close the file by pressing Ctrl + x; when prompted, type y for yes and then press the return (Enter) key.

  6. Power down the BBB in the terminal window with the following command:

    $ sudo poweroff
    
  7. Power up the board again and log in to your BBB desktop.

  8. You will now get a solid Wi-Fi connection. Test it via the command shell with this command:

    $ ping www.google.com
    

    If all went well, you should see a steady screen output from the ping.

Method Three: command line option 2

Consult the table for the tested models that use the following steps. The main difference between these steps and the previous recipe is that the drivers in these dongles require a different interface—a wireless supplicant—with the BBB to function properly. Before starting the steps, be sure to remove any Wi-Fi dongles you may have inserted into the USB hub:

  1. We need to create a .conf file for wpa_supplicant, a tool that comes preloaded on the current Debian distribution. The following command line will be useful for this:

    $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    
  2. Paste in the open file the following information:

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
     ssid="my-ssid"
     scan_ssid=1
     psk="my-psk"
     proto=RSN
     key_mgmt=WPA-PSK
     pairwise=CCMP
     auth_alg=OPEN
    }
    
  3. Two things need to be modified (just as in Method Two): my-ssid, which you will replace with your network's name, and my-psk, which will be your network's password.

  4. We now need to figure out the Wi-Fi dongle's interface name. To do this, we will first examine which interfaces are present using the following command:

    $ ifconfig -a
    

    This command outputs the currently active interfaces, which may include eth0, lo, and usb0.

  5. Reboot your board.

  6. Plug in your dongle and run the same command again:

    $ ifconfig -a
    

    The output should now show the new device's interface name, which could be ra0, wlan0, or so on.

  7. Open the file in the directory specified in the following path:

    $ sudo nano /etc/network/interfaces
    
  8. At the top of the file, paste the following code, replacing interfacename with the name that appeared in Step 6:

    allow-hotplug ra0
    iface interfacename inet manual
      wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
    
  9. Close the file by pressing Ctrl + x; when prompted, type y for yes, then press the return (Enter) key.

  10. Assuming your dongle is still plugged in, run a command that brings up the interface:

    $ ifup interfacename
    
  11. Power down the BBB by running this:

    $ sudo poweroff
    
  12. Make sure your Wi-Fi dongle is plugged into a powered USB hub with the hub's USB cable inserted into the BBB's USB port.

  13. Restart the board; this time, plug into the DC power supply.

  14. You will now get a solid Wi-Fi connection. Test it via the command shell using the following command:

    $ ping www.google.com
    

    If all went well, you should see a steady screen output from the ping.

    Note

    Sometimes you may need to power off, unplug the 5V input, and then plug in again as the dongle isn't always recognized through the S1 (Reset) or the S3 (Power) buttons.

Method Four: Debian Jessie

Using Jessie is the easiest and fastest route to a reliable Wi-Fi connection. Here is how to do this:

  1. Plug an Ethernet cable connected to your router into the BBB's Ethernet port.

  2. Boot up and log in to your BBB connected to a monitor.

  3. Open a terminal window and log in as root with the following command:

    $sudo -i
    #
    
  4. Install the package network manager. Before installing a new package, always begin by updating your repositories as follows:

    # apt-get update
    # apt-get install network-manager
    
  5. Now, open up the new package with this command:

    # nmtui
    

    A rudimentary interface should open up in the terminal window, similar to the following image:

  6. Select Activate a connection.

  7. In the next window, select your network, and you will be prompted for the password.

  8. Quit the network manager screen after putting in your password. Then, check to verify that your dongle now has an IP address in the wlanX interface with this command:

    # ifconfig -a
    
  9. Now, power down, remove the Ethernet cable, and reboot using this command:

    # reboot
    
  10. Run the magical ping command to check how we did:

    $ ping www.google.com
    

    Voila! Your BBB should now be connected wirelessly.

There's more…

Some users report that the board can interfere with a Wi-Fi dongle's USB signal. So, if you do not get a reliable connection, position your powered USB device containing the Wi-Fi dongle a few feet away from the BBB.

See also

Take a look at a list of other compatible dongles here at http://elinux.org/Beagleboard:BeagleBoneBlack#WIFI_Adapters.