Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Hardware Interfacing with the BeagleBone Black
Android Hardware Interfacing with the BeagleBone Black

Android Hardware Interfacing with the BeagleBone Black: Design and implement Android apps that interface with your own custom hardware circuits and the BeagleBone Black

€16.99 €10.99
Book Feb 2015 134 pages 1st Edition
eBook
€16.99 €10.99
Print
€20.99
Subscription
€14.99 Monthly
eBook
€16.99 €10.99
Print
€20.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Feb 19, 2015
Length 134 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781784392161
Category :
Table of content icon View table of contents Preview book icon Preview Book

Android Hardware Interfacing with the BeagleBone Black

Chapter 1. Introduction to Android and the BeagleBone Black

In this book, you'll learn how to install Android to a microSD card for use with the BeagleBone Black and create Android apps that interface with external hardware that is connected to the BeagleBone Black. You will develop software that receives input from the outside world via buttons and sensors, stores and retrieves data from external memory chips, and lights external LEDs. Better yet, you'll learn how to do this in a flexible way that can be easily integrated into your apps.

As you explore the world of interfacing hardware with Android, you will discover that it encompasses many different areas of expertise. Understanding electronic circuits and knowing how to interface them with the BeagleBone Black, understanding the Linux kernel, and developing Android apps are a few such areas. Luckily, you don't have to be an expert in these areas to learn the basics of interfacing hardware with Android. We have done our best to guide you through the examples in this book without requiring you to have an in-depth knowledge of the Linux kernel or electronics theory.

In this chapter, we will cover the following topics:

  • Looking back on Android and BeagleBone Black development

  • Shopping for the hardware essentials

  • Learning about the hardware you'll interface with

  • Installing Android on the BeagleBone Black

Looking back on Android and BeagleBone Black development


The Android operating system has been taking the world by storm. Ever since its introduction to the world in a beta release in 2007, it has grown to become the dominant mobile phone OS. Aside from mobile phones, it has also been used for tablets (such as the Barnes & Noble Nook eReader and the Tesco Hudl tablet) and a variety of other embedded multimedia devices. The OS has added new features and evolved over the years, but it still has the same primary design principles as it did when it was first conceived. It provides a lightweight OS with a touchscreen interface that gives quick and easy access to multimedia applications while using minimal resources.

Aside from its general popularity, Android has a number of advantages that make it an excellent OS for your projects. The source code of Android is open source and freely available from http://source.android.com. It is free for you to use in any products that you create. Android uses the popular Linux kernel, so any expertise that you already have with Linux will aid you in your Android development. There is a well-documented interfacing API that makes developing for Android simple and straightforward.

The broad availability of Android-based devices has generated a large amount of interest in developing software applications, or apps, that target Android. It has become easier to develop Android apps. Eclipse Android Development Tools (ADT) allows app developers to prototype software and then execute that software within an emulated Android device environment. However, the emulated device differs from real hardware in subtle (and sometimes dramatic) ways in terms of speed and appearance. Luckily, a powerful and low-cost hardware platform is available that allows you to quickly and easily test your apps on real hardware: the BeagleBone Black.

The BeagleBone Black (BBB) hardware platform, produced by CircuitCo for the BeagleBoard.org nonprofit organization, is a newcomer to the open source hardware scene. First produced in 2013, this low-cost, ARM-based single board computer is an improvement over the original BeagleBone platform. The BBB is an improvement over the original BeagleBone board that offers increased processing power, built-in HDMI video, and either a 2 or 4 GB (depending upon the BBB's revision) on-board eMMC memory. With a focus on small size and a wide variety of expansion and interfacing opportunities, the BBB provides a lot of processing power at a very low price. The following image shows a typical BBB:

The BeagleBone Black (Source: www.beagleboard.org)

Android runs on the inexpensive BBB, which makes it an excellent hardware platform to use to explore Android and develop your own custom Android projects, for example, if you had an idea for an Android kiosk device, a hand-held gaming console, or some other multimedia device. The combination of Android and the BBB will allow you to prototype such devices quickly and cheaply.

Now that we have taken a quick look at the BBB and Android, let's take a look at the hardware that you will need to make the most out of both of them.

Shopping for the hardware essentials


When you purchase your BBB, you will only receive the board and a USB cable to power and communicate with it. Before you begin any serious software development for hardware-interfacing projects with the BBB, there are a few additional pieces of hardware that you will need. In our opinion, the best place to purchase these items is AdaFruit (www.adafruit.com). Almost everything here is available from this single source, and their customer service is very good. In fact, many of the items listed here are available as a BeagleBone Black starter kit from AdaFruit (product ID 703). The starter kit does not contain a 3.3 V Future Technology Devices International (FTDI) cable, but it does include the BeagleBone Black itself.

Contents of the BeagleBone Black starter kit from AdaFruit (source: www.adafruit.com)

The FTDI cable

A 3.3 volt FTDI cable (product ID 70) allows you to view all of the serial debug output of the BBB. If you are performing any serious development, you must have one of these cables. The cable is necessary if you wish to observe the boot process of the BBB (both bootloader and kernel output as the system is initialized), and it also provides a console shell into Linux and Android. This shell helps you to troubleshoot boot problems, as you will always have a method of interacting with the system when a network connection is unavailable, or when no communication services are up and running.

Power supply

While the BBB can be powered via the USB cable, this method supplies barely enough power to run the BBB. If you are using external capes, or are otherwise attaching external circuits that draw power from the 5 volt pins of the BBB, you must use an external power supply. BeagleBoard.org specifies that the power supply must be a 2 amp, 5 volt DC power supply with a 2.1 mm barrel connector that is center positive. AdaFruit sells a power supply that conforms to the BBB's requirements (product ID 276).

Breadboard and the mounting plate

Experimenting with electronics becomes much simpler if you are able to easily and quickly construct circuits without the worry of soldering. Because of this, we recommend that you invest in a breadboard and some breadboarding jumper wires (product ID 153). Your breadboard doesn't have to be anything big or fancy, but you should use at least a standard half-size breadboard (product ID 64) for the projects given in this book.

AdaFruit Proto Plate (product ID 702) is an additional item that we recommend that you purchase. Proto Plate is a plastic plate that both the BBB and a half-size breadboard mount onto. This helps you avoid accidentally stretching or disconnecting the wires that connect electronic circuits to the BBB. Using Proto Plate makes relocating your BBB and breadboard simple and painless.

MicroSD cards

If you do much work with the BBB, you'll always want to have a few extra microSD cards around! Android will fit onto an 8 GB microSD card with plenty of free space available to hold your own apps. You can write an Android image to a larger microSD card, but most premade Android system images will only consume the first 4–8 GB of space on the card. As most laptops and desktop PCs don't directly accept microSD cards, you should own at least one microSD-to-SD card adapter. Luckily, one of these adapters is typically packaged with each microSD card that you buy.

Learning about the hardware you'll interface with


The best way to learn about interfacing Android software with hardware is to learn while having real hardware components connected to your BBB. This way, your software will talk to actual hardware and you can directly observe how your apps respond to physical interaction with your system. We have selected a variety of electronic components that will be used throughout the book to demonstrate various aspects of hardware interfacing. You are welcome to use as many or as few of these components as your interests and budget permit. It can be expensive to purchase all of these components at once, but make sure to buy all of the components necessary for each chapter if you are interested in implementing the examples in that chapter.

General-purpose components

In Chapter 3, Handling Inputs and Outputs with GPIOs, and Chapter 6, Creating a Complete Interfacing Solution, you will use a variety of electronic components such as pushbuttons, LEDs, and resistors to interface with the BBB. Many of these items can be purchased from any electronics supplier, such as DigiKey (www.digikey.com), Mouser Electronics (www.mouser.com), and SparkFun (www.sparkfun.com). Both Digikey and Mouser offer so many variants of each available component that it can be difficult for an inexperienced hardware hacker to pick the right components to buy. Because of this, we will recommend a few products from SparkFun that will give you suitable components needed to complete the exercises in this book. You are welcome to select your components from another supplier if using a different one is more convenient for you.

Our examples require only three components: a resistor, a pushbutton switch, and an LED. We suggest purchasing a 1K ohm, 1/6 (or 1/4) watt resistor (part #COM-08980), a 12 mm push button switch (part #COM-09190), and any small LED (3–10 mm in size) that can be triggered by around 3 volt or less (part #COM-12903 is a good assortment of 5 mm LEDs).

The AdaFruit memory breakout board

In Chapter 4, Storing and Retrieving Data with I2C, and Chapter 6, Creating a Complete Interfacing Solution, you will interface with a 32 KB Ferroelectric Random Access Memory (FRAM), which is a nonvolatile memory IC, to store and retrieve data. We have selected AdaFruit Breakout Board (product ID 1895) that contains this IC. The breakout board already contains all of the necessary components to interface the IC to the BBB, so you need not worry about many of the low-level details involved in creating a clean, noise-free connection between each IC and the BBB.

The FRAM Breakout Board with its header strip (source: www.adafruit.com)

The AdaFruit sensor breakout board

In Chapter 5, Interfacing with High-speed Sensors Using SPI, and Chapter 6, Creating a Complete Interfacing Solution, you will interface with a sensor IC to receive environmental data. We have selected an AdaFruit breakout board (product ID 1900) that contains these ICs. These breakout boards already contain all of the necessary components to interface the ICs to the BBB, so you need not worry about many of the low-level details involved in creating a clean, noise-free connection between each IC and the BBB.

Preparing the breakout boards

Each breakout board comes with a header strip. This header strip must be soldered into each breakout board so that they can be easily connected to the breadboard. This is the only soldering that is required to complete the exercises in this book. If you are unfamiliar with soldering, there are numerous tutorials online that explain techniques for effective soldering. If you feel uncomfortable soldering the header strips, ask a friend, instructor, or colleague to assist you with the process.

Note

A few online soldering tutorials that we suggest that you check out are:

Installing Android on the BeagleBone Black


The Android OS is a complex piece of software that is constructed out of many components built from a very large codebase. It can be a difficult and time-consuming task to build Android from source, so you will be using a premade Android image from the BBBAndroid project (www.bbbandroid.org) throughout this book.

BBBAndroid is a port of Android Open Source Project (AOSP) KitKat Android to the BBB. There are a few different distributions of Android available for the BBB, but we selected BBBAndroid because it uses the 3.8 Linux kernel. This kernel includes the Cape Manager (capemgr) functionality as well as a few other tools that will assist you in interfacing hardware to Android apps. Other flavors of Android on the BBB use the 3.2 Linux kernel, which is much older and lacks capemgr support. Chapter 2, Interfacing with Android, discusses the capemgr functionality in more detail. The 3.8 kernel is a good balance between enabling the newer features for the BBB while avoiding any potentially unstable, cutting-edge features.

The BBB can boot its OS in a few different ways:

  • Onboard eMMC: The OS resides within the onboard eMMC storage. The Angstrom or Debian OS that comes installed on your BBB boots from the eMMC out of the box.

  • MicroSD card: The OS resides on a microSD card that is inserted into the BBB. If a bootloader is installed on the microSD card, the bootloader installed on the onboard eMMC notices the presence of the microSD and will boot from that instead. In addition, booting from the microSD card is forced when the user boot button is held down during BBB power up.

  • Over the network: The bootloader is capable of downloading a kernel over the network via TFTP. The OS can actually be downloaded at boot time though this is usually only done during commercial product development. This is an advanced feature that is outside the scope of this book.

The BBBAndroid image is designed to be written to and booted from a microSD card. As the image creates a fully bootable system on the microSD card, you will not have to hold the BBB's user boot button during power on to boot into Android. Simply insert the microSD card into the BBB and you'll boot into Android automatically.

Using a microSD card-based OS is advantageous for us because you can easily mount the card on a Linux PC to modify the Android filesystem as you see fit. If the OS is installed in the eMMC, it can be hard to access the OS to change arbitrary files in the filesystem. The system must be running to access the eMMC contents, so making a change that corrupts the system or makes it unbootable makes accessing the eMMC to fix the problem difficult.

Downloading a premade Android image

The main page of the BBBAndroid website provides a download link for the most recent premade image. Like any open source project, details about the version number and size of each image are likely to change over time as bugs are found and changes are made. However, the latest and greatest will be available via the website.

BBBAndroid's images are compressed using the xz compressor utility to save time when downloading, so the image must be decompressed prior to writing it to a microSD card. The tools used to decompress and write the image will vary depending upon the OS that you are using. While the compressed image might only be a few hundred MB in size, the uncompressed image will be 8 GB.

Note

Prior to beginning the decompression of the image, make sure that you have enough hard drive space to hold the uncompressed image.

Creating your Android microSD card using Windows

Under Windows-based OSes, the compressed image can be uncompressed using tools such as 7-Zip or WinRAR and then written to the microSD card using the tool Win32 Disk Imager. All of these tools are freely available for download. To prepare an Android microSD card, follow these steps:

  1. For this example, you'll use the WinRAR application. Download WinRAR from www.rarlab.com and install it. WinRAR will integrate with the Windows Explorer shell of the Windows desktop.

  2. Download and install the Win32 Disk Imager application. It is available from the project's SourceForge page at http://sourceforge.net/projects/win32diskimager.

  3. Right-click on the BBBAndroid image that you downloaded and select the Extract here option on the Explorer shell context menu. An uncompressed version of the image (8 GB in size) will be written to the same location as the compressed image. The decompression process might take several minutes.

    Decompress the xz-compressed image with WinRAR

  4. Insert an 8+ GB microSD card into the system. The card will be detected by Windows as having a valid filesystem on it if it came preformatted (most cards are sold preformatted for your convenience). Irrespective of whether the card is formatted or not, a drive letter is assigned to it by Windows.

  5. Browse to This PC and examine the devices shown under Devices and drives. The card should be shown. Make a note of the drive letter assigned to the card.

    The microSD card will be shown with a drive letter under Windows (drive E in the image)

  6. Launch Win32 Disk Imager. Enter the filename and path to the uncompressed image in the text field, or click on the folder icon to navigate to the file's location. Change the Device drop-down box to the drive letter of the microSD card that you identified in step 4.

    Win32 Disk Imager with the image file specified (note that the drive letter matches that of the microSD card)

  7. Writing the image will take several minutes. Once the write has completed, remove the microSD card from your computer and insert it into your BBB.

  8. Power on the BBB and Android will begin to boot. On the first boot, it will take several minutes for the top-level UI screen to appear. On subsequent boots, it will take only 30 to 60 seconds to reach the top-level UI screen.

Congratulations! Your BBB is now running the Android OS.

Creating your Android microSD card using Linux

Under Linux, the compressed Android image can be uncompressed using the xz command and written to the microSD card using the dd command. To prepare an Android microSD card, follow these steps:

  1. Make sure that you have xz installed. For systems using apt-get, try installing the xz-utils package:

    $ sudo apt-get install xz-utils
    
  2. Decompress the image using xz. Substitute the name of your image file (with the .xz file extension), as shown in the following command:

    $ xz --decompress [IMAGE FILENAME]
    
  3. Once uncompressed, the image will lose its .xz file extension and have a size of 8 GB. Insert your microSD card into the computer. A device in the /dev directory will be assigned to your card. To determine which device it is, use fdisk:

    $ sudo fdisk –l
    
  4. The fdisk utility will display all storage devices currently connected to your computer. One of the devices will report as being the same size as the microSD card. For example, if you insert an 8 GB microSD card, you will see something similar to this:

    Disk /dev/sdb: 8018 MB, 8018460672 bytes
    

    The exact storage capacity of the card varies slightly between manufacturers, but the size is approximately 8 GB. The device assigned to this card is /dev/sdb. Other devices listed by fdisk will be secondary storage devices (such as your hard drive). Before proceeding any further, make certain that you have identified the proper device file that belongs to your microSD card. If you select the wrong device, you will destroy the filesystem on that device!

  5. Write the image to the microSD card using dd. Assuming that the device you identified in step 5 is /dev/sdb, use the following command to perform the write:

    $ sudo dd if=[NAME OF IMAGE] of=/dev/sdb bs=4M
    
  6. Writing the image will take several minutes. Once the write has completed, remove the microSD card from your computer and insert it into your BBB.

Power on the BBB and Android will begin to boot. On the first boot, it will take several minutes for the top-level UI screen to appear. On subsequent boots, it will take only 30 to 60 seconds to reach the top-level UI screen.

Congratulations! Your BBB is now running the Android OS.

Summary


In this chapter, you learned about the hardware that you'll need to develop software for the BeagleBone Black, the electronics components and devices that you will need for the exercises in this book, and how to install an Android distribution onto a microSD card for use on the BBB. In the next chapter, you will learn how Android interacts with hardware at the software level and how the BBB can be configured to interface with the hardware components that you will be using in this book.

Left arrow icon Right arrow icon

Key benefits

What you will learn

Install Android on your BeagleBone Black Explore the three primary hardware interfaces of the BeagleBone Black-GPIO, SPI, and I2C Construct circuits that interface the BeagleBone Black with high-speed sensors, external memory chips, and more Discover the advantages and disadvantages of using GPIO, I2C, and SPI components in your interfacing projects Modify Android to recognize and interface with your own custom and prototype hardware Develop multithreaded apps that communicate directly with custom circuitry

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Feb 19, 2015
Length 134 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781784392161
Category :

Table of Contents

14 Chapters
Android for the BeagleBone Black Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Authors Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Introduction to Android and the BeagleBone Black Chevron down icon Chevron up icon
Interfacing with Android Chevron down icon Chevron up icon
Handling Inputs and Outputs with GPIOs Chevron down icon Chevron up icon
Storing and Retrieving Data with I2C Chevron down icon Chevron up icon
Interfacing with High-speed Sensors Using SPI Chevron down icon Chevron up icon
Creating a Complete Interfacing Solution Chevron down icon Chevron up icon
Where to Go from Here Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.