
Android Hardware Interfacing with the BeagleBone Black
Beschreibung
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Who this book is for
Alle Preise
Weitere Details
Weitere Ausgaben
Andere Ausgaben

Inhalt
- Intro
- Android for the BeagleBone Black
- Table of Contents
- Android for the BeagleBone Black
- Credits
- About the Authors
- About the Reviewers
- www.PacktPub.com
- Support files, eBooks, discount offers, and more
- Why subscribe?
- Free access for Packt account holders
- Preface
- What this book covers
- What you need for this book
- Who this book is for
- Conventions
- Reader feedback
- Customer support
- Downloading the example code
- Errata
- Piracy
- Questions
- 1. Introduction to Android and the BeagleBone Black
- Looking back on Android and BeagleBone Black development
- Shopping for the hardware essentials
- The FTDI cable
- Power supply
- Breadboard and the mounting plate
- MicroSD cards
- Learning about the hardware you'll interface with
- General-purpose components
- The AdaFruit memory breakout board
- The AdaFruit sensor breakout board
- Preparing the breakout boards
- Installing Android on the BeagleBone Black
- Downloading a premade Android image
- Creating your Android microSD card using Windows
- Creating your Android microSD card using Linux
- Summary
- 2. Interfacing with Android
- Understanding the Android HAL
- Android managers
- The HAL development workflow
- Working with PacktHAL
- Installing PacktHAL
- Preparing PacktHAL under Linux
- Preparing PacktHAL under Windows
- The PacktHAL directory structure
- Preparing Android for PacktHAL
- Pushing PacktHAL files under Linux
- Pushing PacktHAL files under Windows
- Setting up the Android NDK for PacktHAL
- Adding the header to the NDK under Linux
- Adding the header to the NDK under Windows
- Multiplexing the BBB pins
- The kernel Device Tree and capemgr
- Defining a cape
- Summary
- 3. Handling Inputs and Outputs with GPIOs
- Understanding GPIOs
- Nuts and bolts of GPIO
- GPIO access methods under Android
- Pros and cons of the file I/O method
- Pros and cons of the memory-mapping method
- Preparing Android for GPIO use
- Building a GPIO-interfacing circuit
- Constructing the circuit
- Checking your wiring
- Including PacktHAL within your apps
- Understanding the Java Native Interface
- Creating a new app project that uses PacktHAL
- Building PacktHAL under Windows
- Building PacktHAL under Linux
- Exploring the GPIO example app
- Installing the app and source under Windows
- Installing the app and source under Linux
- The app's user interface
- Calling the PacktHAL functions
- Using the PacktHAL GPIO functions
- Summary
- 4. Storing and Retrieving Data with I2C
- Understanding I2C
- Devices that use I2C
- Multiplexing for I2C on the BBB
- Connecting to I2C via the P9 header
- Multiplexing for I2C
- Representing I2C devices in the Linux kernel
- Preparing Android for FRAM use
- Building an I2C-interfacing circuit
- Connecting the FRAM
- Checking the FRAM connection with I2C tools
- Exploring the I2C FRAM example app
- The app's user interface
- Calling the PacktHAL FRAM functions
- Understanding the AsyncTask class
- Learning the details of the HardwareTask class
- Summary
- 5. Interfacing with High-speed Sensors Using SPI
- Understanding SPI
- Multiplexing for SPI on the BBB
- Representing SPI devices in the Linux kernel
- Preparing Android for SPI sensor use
- Building an SPI interface circuit
- Connecting the sensor
- Exploring the SPI sensor example app
- The app's user interface
- Calling the PacktHAL sensor functions
- Using the HardwareTask class
- Summary
- 6. Creating a Complete Interfacing Solution
- Building the complete interface circuit
- Exploring the complete example app
- The app's user interface
- Understanding hardware polling in an app
- Using AsyncTask with long-lived threads
- Using the HardwareTask class
- Summary
- 7. Where to Go from Here
- Integrating your solution with Android
- Creating a custom kernel and Device Tree
- Adding hardware communication into the kernel
- Integrating into existing managers
- Creating new managers for custom hardware
- Combining your project with other hardware
- Constructing your own prototype capes
- Commercial capes that interface with Android
- Exploring the BBB's other interfaces
- Programmable real-time units
- Serial communications
- Controller area network
- The analog-to-digital converter
- Pulse width modulation
- Summary
- Index
Installing PacktHAL
All of the various pieces of PacktHAL are located in the PacktHAL.tgz file, which is available for download from Packt's website (http://www.packtpub.com/support). This is a compressed tar file that contains all of the source code and configuration files required to modify BBBAndroid to use PacktHAL and include PacktHAL support in your apps.
Preparing PacktHAL under Linux
Once you have downloaded the PacktHAL.tgz file, you must decompress and untar it. We will assume that you have copied PacktHAL.tgz to your home directory after downloading it and will decompress it from there. We will refer to your home directory as $HOME.
Use the Linux tar command to decompress and untar the file:
A directory named PacktHAL now exists in your $HOME directory. All of the PacktHAL files are located in this directory.
Preparing PacktHAL under Windows
Once you have downloaded the PacktHAL.tgz file, decompress and untar it. We will assume that you have copied PacktHAL.tgz to the root directory of the C: drive after downloading it and will use WinRAR to decompress it from there.
Tip
Where should I unpack PacktHAL.tgz?
You can decompress and untar PacktHAL.tgz on the desktop or wherever else you wish, but you will be performing some command-line commands to copy files around later. It is much simpler to perform these operations if PacktHAL.tgz is decompressed and untarred in the root directory of the C: drive, so we will assume that you are performing these operations from there.
Perform the following steps to extract the PacktHAL.tgz file:
- Open a file explorer window and navigate to the root of the
C:drive. - Right-click on the
PacktHAL.tgzfile in file explorer and select Extract Here.
A directory named C:\PacktHAL now exists. All of the PacktHAL files are located in this directory.
The PacktHAL directory structure
The PacktHAL directory has the following structure:
The cape subdirectory contains the source code and build script for building a Device Tree overlay that enables all of the hardware features that PacktHAL needs. You will learn more about Device Tree overlays later in this chapter. The jni subdirectory contains the source code files that implement PacktHAL. These source files will be added to your projects in later chapters to build PacktHAL support into your apps. The prebuilt directory contains a few premade files that must be added to your BBBAndroid image and Android NDK to build and use PacktHAL. You will install the files in the prebuilt directory to their required locations in the next few sections.
Preparing Android for PacktHAL
Before using PacktHAL with any apps, you have to prepare your BBBAndroid installation. By default, Android is very restrictive on the permissions that it assigns to hardware devices. To use PacktHAL, you must lessen the permission restrictions and configure Android for the hardware that you will interface with. These actions require copying some prebuilt files into your Android system to make a few configuration changes that relax various Android permissions and configure the hardware properly for PacktHAL's use.
You will use the ADB tool to push (push) the necessary files over to your running BBB system. Prior to pushing the files, boot Android on the BBB and connect the BBB to your PC using the USB cable that came with your BBB. Once you have reached this point, continue with the instructions.
Pushing PacktHAL files under Linux
The following steps are used in order to publish PacktHAL files under Linux:
- Before you get started, make sure that ADB can see your BBB by using the
adb devicescommand. The BBB will report as having a serial number ofBBBAndroid. Execute the following command: $ adb devices List of devices attached BBBAndroid device - If you are missing the
adbcommand, install theandroid-tools-adbpackage viaapt-get: $ sudo apt-get install android-tools-adbTip
Why can't Linux find my BBB?
If
adbis installed on your system and you are unable to see the BBB, you might need to add audevrule to your system and perform some additional troubleshooting. Google provides directions for adding this rule and some troubleshooting steps if you run into any difficulty, and this can be found at http://developer.android.com/tools/device.html.BBBAndroid reports the USB device ID of its ADB interface as
18D1:4E23, which is the device ID of a Google Nexus S, so the USB vendor ID for the BBB is 18D1 (the device ID for Google devices). - Once you have verified that
adbcan see the BBB, change into thePacktHALdirectory, shell into Android viaadb, and remount the read-onlyrootfsfilesystem as read-write: $ cd $HOME/PacktHAL/prebuilt $ adb shell root@beagleboneblack:/ # mount rootfs rootfs / rw root@beagleboneblack:/ # exit - Now, push the necessary files into Android's
rootfsfilesystem: $ adb push BB-PACKTPUB-00A0.dtbo /system/vendor/firmware $ adb push init.genericam33xx\(flatteneddevicetr.rc / $ adb chmod 750 /init.genericam33xx\(flatteneddevicetr.rc - Finally, shell into Android's
rootfsfilesystem to sync it and remount it as read-only: $ adb shell root@beagleboneblack:/ # sync root@beagleboneblack:/ # mount rootfs rootfs / ro remount root@beagleboneblack:/ # exit - You have now prepared your BBBAndroid image for PacktHAL under Linux. Remove the power supply cable and USB cable from your BBB to shut it down.
- Then, power up the BBB to verify that Android boots properly with the modifications that you have just made.
Pushing PacktHAL files under Windows
You must locate where your adb.exe file is located. It is part of the platform tools in the Android SDK. In the following instructions, we are assuming that you installed the Eclipse ADT in the c:\adt-bundle directory, making the full path to adb to be c:\adt-bundle\sdk\platform-tools\adb.exe.
The following steps are used in order to publish PacktHAL files under Windows:
- Before you get started, make sure that
adbcan see your BBB by using theadb devicescommand. The BBB will report as having a serial number ofBBBAndroid: $ adb devices List of devices attached BBBAndroid deviceTip
Why can't Windows find my BBB?
It can be notoriously difficult to get
adbto see Android devices under Windows. This is because each hardware manufacturer that creates an Android device provides its own Windows ADB device driver that Windows uses to talk to that device. BBBAndroid reports the USB device ID of its ADB interface as18D1:4E23, which is the device ID of a Google Nexus S. This device is one of the (many) USB devices that are supported by Koushik Dutta's excellent Universal ADB driver for Windows. Ifadbcan't find your BBB, install the Universal ADB driver and then try again. You can download the driver from http://www.koushikdutta.com/post/universal-adb-driver. - Once you have verified this,
adbcan see the BBB, shell into Android viaadb, and remount the read-onlyrootfsfilesystem as read-write: $ adb shell root@beagleboneblack:/ # mount rootfs rootfs / rw root@beagleboneblack:/ #...
Systemvoraussetzungen
Dateiformat: ePUB
Kopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
- Computer (Windows; MacOS X; Linux): Installieren Sie bereits vor dem Download die kostenlose Software Adobe Digital Editions (siehe E-Book Hilfe).
- Tablet/Smartphone (Android; iOS): Installieren Sie bereits vor dem Download die kostenlose App Adobe Digital Editions oder die App PocketBook (siehe E-Book Hilfe).
- E-Book-Reader: Bookeen, Kobo, Pocketbook, Sony, Tolino u.v.a.m. (nicht Kindle)
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an.
Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.
Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.
Dateiformat: PDF
Kopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
- Computer (Windows; MacOS X; Linux): Installieren Sie bereits vor dem Download die kostenlose Software Adobe Digital Editions (siehe E-Book Hilfe).
- Tablet/Smartphone (Android; iOS): Installieren Sie bereits vor dem Download die kostenlose App Adobe Digital Editions oder die App PocketBook (siehe E-Book Hilfe).
- E-Book-Reader: Bookeen, Kobo, Pocketbook, Sony, Tolino u.v.a.m. (nicht Kindle)
Das Dateiformat PDF zeigt auf jeder Hardware eine Buchseite stets identisch an. Daher ist eine PDF auch für ein komplexes Layout geeignet, wie es bei Lehr- und Fachbüchern verwendet wird (Bilder, Tabellen, Spalten, Fußnoten). Bei kleinen Displays von E-Readern oder Smartphones sind PDF leider eher nervig, weil zu viel Scrollen notwendig ist.
Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.
Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.