34,79 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 412
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2015
Production reference: 1121115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-292-9
www.packtpub.com
Author
Charles A. Hamilton
Reviewers
Nathan Burles
Anuj Deshpande
Deepak Karki
Agrima Seth
Commissioning Editor
Edward Gordon
Acquisition Editor
Richard Brookes-Bland
Content Development Editor
Rohit Kumar Singh
Technical Editor
Vijin Boricha
Copy Editor
Shruti Iyer
Project Coordinator
Mary Alex
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Production Coordinator
Conidon Miranda
Cover Work
Conidon Miranda
Charles A. Hamilton is the owner of HudsonWerks, a New York City-based DIY hardware and development shop for new products. Passionate about emerging technologies, open source hardware, and the maker movement, his background as a "technology creative", entrepreneur, and maker provides readers with a unique perspective.
Besides BeagleBone Black, Charles works frequently with other hardware platforms, including the Raspberry Pi, Arduino, and UDOO development boards, open source board architecture and PCB design, micromechatronics, and sensors. He is also an advocate and keen user of emerging low-cost manufacturing and design tools such as 3-D printers and laser cutters. Among other subjects, Charles keenly follows advances and design challenges in the arenas of IoT, space technologies, and next-generation health and wellness devices. He writes and blogs at http://www.hudsonwerks.com.
He is a former creative director at AT&T and product developer at a New York City-based new product development agency. Charles' development expertise spans devices in the consumer electronics, digital media, display, voice recognition, and telecommunication markets. He is also a proud papa to his 4-year-old son, Hudson.
I would first like to acknowledge the support of Jason Kridner, the Texas Instruments embedded applications Evangelist and founder of Beagleboard.org, without whom this book would never have achieved liftoff. Additionally, immeasurable thanks need to go to John Reaves of Learning Worlds and Masuo Kitano of Seiko Epson Corporation, who ignited the prototyping-and-build-something-crazy spark in me. Jonathan Hirschman of PCB:NG gave it a further push by showing us the way to cook up PCBs from scratch, literally. Finally, more than thanks are necessary to the two people that showed the greatest forbearance in seeing this project to its conclusion: my wife, Mary, and little boy, Hudson. Without their encouragement, patience, and love, this book would never have happened. For this, I am humbled and grateful.
Nathan Burles is a postdoctoral researcher with a PhD in computer science. He is currently working for University of York on subjects as diverse as artificial neural networks, automated programming / software improvement, and optimization for power consumption.
In his free time, Nathan enjoys tinkering with embedded systems and electronics ranging from full systems, such as Raspberry Pi and BeagleBone Black, to simple microcontrollers, such as Arduino, adding circuitry to communicate using 433MHz RF and infrared.
He blogs about his projects and topics such as website development, Android, and dancing at http://www.nburles.co.uk.
Anuj Deshpande is a fan of BeagleBone Black and all things embedded. He dabbles in embedded Linux and loves to prototype ideas and build interactive installations.
Some of the projects that Anuj has been a part of are Userspace Arduino and Tah. He completed his bachelor's degree in computer science from PICT, Pune.
Anuj currently runs his own development and consulting firm called Makerville Solutions (http://makerville.io).
Deepak Karki is a software developer and open source Evangelist based in Bangalore, India. He enjoys working with like-minded hackers and is often a participant in hackathons in and around the city. During the day, Deepak works on challenging hyperconvergence problems with Nutanix, and in the night, he keeps busy pushing code onto GitHub.
He was a Google Summer of Code (GSoC) student for beagleboard.org in 2014 and, consequently, a mentor for the same organization during GSoC 2015. Deepak's main areas of interest include SaaS application development, embedded systems, parallel computing, networks, and security.
Lately, he has been heavily involved in IoT projects and is working with World Wide Web Consortium (W3C) to help standardize Internet of Things by contributing to their WoT platform.
Apart from writing code, Deepak loves teaching and working out. You can catch him at github.com/deepakkarki or on #beagle freenode IRC as nick: karki_.
Agrima Seth is currently a senior year student pursuing a bachelor's degree of engineering in information technology at University of Pune, India. Her research interests include machine learning and information retrieval systems. She is currently an intern with the SIG (Generalized Information Systems) research team under Professor Josiane Mothe at IRIT, France. Here, Agrima is working on performing effective data indexing and query reformulation on TREC datasets to study and create better information retrieval systems. She has been the recipient of Sir Ratan Tata Memorial Scholarship and other merit scholarships.
Apart from machine learning, Agrima has also worked on computer graphics and computer vision at Indian Institute of Space Science and Technology, India. Her work is published at arXiv (http://arxiv.org/abs/1409.5024). Agrima has worked on a project for Thermax India on making a mini solar tracker using MSP430. She has been involved in the creation of a machine learning group at her institute where she trained undergraduate students on various machine learning techniques and computer graphics. Agrima is a voracious reader and a trained Indian Classical dancer who enjoys participating in public speaking events.
A complete list of her work is available at http://agrimaseth.github.io, and the latest happenings can be read at https://agrimaseth.wordpress.com.
I would like to thank my parents and my HoD, Dr Sangeeta Jadhav, for constantly encouraging me to pursue my dreams and work towards achieving excellence.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
It's maker madness out there! SBCs, MCUs, FPGAs, PCBs, GPIOs, BeagleBone Black and Whites, Raspberry and Banana Pis, Odroids, Udoos, Arduinos, MCUduinos, TinyDuinos…
What does this impossible stew of acronyms and techno arcana mean? How do we make sense of it all, especially if all you want to do is make, invent, and design great whizzy things that go beep and bump and flash brightly or just grab hot data from temperature sensors? Most importantly, what to do if you are not a specialist, an engineer, or a hard-core software programmer?
This is a book precisely for those of you who want to know about BeagleBone Black but are afraid to ask, overwhelmed by its complexity, or underwhelmed by the dearth of understandable, timely information about this tiny but powerful microcomputer.
Why BeagleBone Black?
Although many of the competing small board computers (or SBCs) have their strengths, the virtues of BeagleBone Black are significant:
As you begin tasting the various recipes throughout this book, perhaps a key difference worth keeping in mind is that the designers of BeagleBone Black regard the board as a prototyping platform to build embedded applications and products. An embedded computing device is typically part of a larger electronics system. This is quite unlike the design strategy of other boards, such as Raspberry Pi, which is a device specifically created as a full-blown desktop system and targeted at the grade school market.
This book explores a range of recipes for the novice user, gaining in complexity as the material progresses. In a nutshell, these are the chapters and their topics:
Chapter 1, Setting Up for the First Time, starts by booting up your board out of the box, getting it connected online, teaching how to control it remotely, and then diving into the essential Linux command-line commands.
Chapter 2, Basic Programming Recipes, moves briskly along to scenarios using several flavors of programming ingredients on BeagleBone Black, including BoneScript (an easy JavaScript variant for BeagleBone), Node.js, Python, and Johnny Five.
Chapter 3, Physical Computing Recipes Using JavaScript, the BoneScript Library, and Python, tells it like it is as we will take the recipes discussed in Chapter 2, Basic Programming Recipes and apply them to the use of buttons, sensors, LEDs, and motors.
Chapter 4, Exploring GNU/Linux Recipes Using Bash, Autotools, Debugger, and systemd, looks at some foundational Linux tools that you will need to bend the board to your will, tools that come in handy for a wide variety of use cases.
Chapter 5, Basic Programming Recipes with the Linux Kernel, helps you start putting your arms around the system kernel by installing the latest version and then building a custom kernel. We will also will cook up some mischief with one of the hallmarks of all ARM devices, Device Tree, which makes it easier to add peripherals and daughterboards to your system. We will finish using the universal cape overlay, a toolset that makes manipulating GPIO pins and Device Tree infinitely simpler.
Chapter 6, Run Faster, Run Real Time, enables you to get more advanced in your skills; you will learn how to modify the Linux kernel (yikes!) and then dive into the realm of real-time computing, looking at recipes to use the RT-PREEMPT patch, Xenomai, and the unique subsystem features of BeagleBone Black—the programmable real-time units (PRUs).
Chapter 7, Applied Recipes – Sound, Picture, and Video, looks at some ways to use sound, display, and video in your projects. We will begin by wiring up a mini sound amplifier and speakers and then take this lesson to creating a high-quality audio platform using the open source music platform, Volumio. Then, we will cook up a variety of recipes to utilize video and different types of displays in projects, including an OLED and a mini LCD. This chapter ends by building a video chat client from source.
Chapter 8, The Internet of Things, plunges into a sampling of things for the Internet of Things; things such as looking at ways to use sensors with middleware systems, setting up location-based devices to interact with BeagleBone Black, and mix a recipe for making a smarter object, specifically a cloud-driven digital picture frame.
Chapter 9, The Black in Outer Space, concludes the book by heading into more distant regions: outer space (or near space, to be more exact), delving into recipes to track satellites and craft, such as the International Space Station. We will discuss how to use the very low-cost but powerful and exciting Software Define Radio chip RTL-SDR.
Describing every permutation and combination to set up BeagleBone Black is beyond the scope of this book. Although every recipe starts by describing your hardware requirements, we will suggest a baseline setup here that can be assumed for nearly all chapters.
There will be a number of recipes scattered throughout the book that require additional hardware, such as sensors, jumper wires, resistors, breadboards, and so on. Never fear! The vast majority of these parts is very low cost and typically already a part of your physical computing and electronic kits. There are a few examples, however, where you might need to spend a little more money on daughterboards (called capes) and some other peripherals, such as powered USB hubs.
The hardware requirements are as follows:
The software requirements are as follows:
You will learn to load other versions of the software as we proceed through the book. Note thatprior versions of the board were shipped with Angstrom Linux. However, this book will not run recipes using this distribution.
Homebrew: If you are using a Mac box, adding Homebrew to Mac gives you Linux-savvy tools on your desktop. It includes a basket of Linux utilities so that you don't always have to fire up the board to run a test. For a "how-to" on installing Homebrew, refer to the developers' website at http://brew.sh/.Drivers: If on Mac, install the latest versions of developer Joshua Wise's HoRNDIS drivers for USB tethering to BeagleBone Black, which you can find at http://joshuawise.com/horndis#available_versions. We will provide more details on this step in Chapter 1, Setting Up for the First Time.This is a book primarily for those of you who are new to microcontrollers, small board computing, and physical computing. Although we will get into some relatively advanced examples, the vast majority of our book's recipes are for the aspiring maker, casual programmer, and budding engineer or tinkerer who has wondered how to get started on a full-blown microcomputing Linux system.
You might find some things in here that you could have found in some form on the Web. As we are dealing with open source tools and technology, this is inevitable. However, what we found when trying to learn about using BeagleBone Black for the first time was that although we could find some answers, it is always a struggle to get to an answer quickly.
As we proceed, our intention is to do our best to give you clear and simple introductions to concepts. So, for example, if you already know your way around things such as i2c, sysfs, and GPIO pins and know how to write custom functions in Python, you may find this book a bit too slow.
Given the speed of changes in the small board computing sector, many online tutorials are quickly aging out or just too advanced for a beginner. Thus, we believe that there is a dearth on the market of good, "easy-to-succeed" introductory books and material on BeagleBone Black.
Furthermore, unlike Raspberry Pi, which is surrounded by warm and fuzzy support forums, the BeagleBone community forum is comparatively sparse. Worse, it is often intimidating and unwelcoming to a new user. Our intention is to be light-hearted, fun, and inviting for a first-time user.
In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
In many cases, you will also be downloading code from the author's github site at https://github.com/HudsonWerks.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/2929OS_GraphicBundle.pdf. Where noted, you may also download some of the images and diagrams from the author's website at http://www.hudsonwerks.com/beaglebone-black-recipe-book/images/
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this chapter, we will focus on the following topics:
Getting off to a running start with your BeagleBone Black requires diving into a number of fundamental recipes first. After all, you have to learn to chop and dice before making a proper soup.
As you probably already know, creating the right development environment saves time, reduces errors, and creates a good workflow. To this end, after we get our display hardware hooked up, it's critical to learn a bit about the Linux commands that power our projects. Then, we will move on to getting your board both connected online and controlled remotely over a network. Next, we will learn the basics of installing and managing applications (packages). Finally, we will explore how to get an OS onto your board, whether it's with the internal solid-state drive (eMMC) or via an SD card.
BeagleBone Black (BBB) designers have worked hard to simplify the user's first out-of-the-box experience. Although things get more challenging later, which is natural, it is pretty close to Plug and Play at the outset.
You do not even need to load any software as the platform arrives preloaded with a custom distribution of Linux Debian on the internal solid-state drive (eMMC).
Here's what you need:
Perform the following steps:
Unless otherwise noted, all images are copyright Charles A. Hamilton.
There is no reason to recapitulate all the material covered in the START.htm presentation. Instead, review it as a good jumping off point for the upcoming recipes in this chapter.
Power down: Before proceeding, remove all cables and power (USB, Ethernet, DC cord, HDMI, and so on).
Perform the following steps:
If the planets are aligned and the drivers are installed properly, you will see the following at the top of the browser window:
Your board is connected! BeagleBone Black rev 0A5C S/N xxxxxxxxxxxx running BoneScript 1.2.3 at 192.168.7.2.
At this point, you're ready to fly; at least at low altitude. With a co-pilot…on an emulator.
Giving your BBB the proper amount of love and power is crucial to having a happy board. Following these basic guidelines will ensure that your BBB operates reliably and predictably.
The board's user manual recommends that you supply current to at least 1.2A (or 6W). However, if you connect up anything over the USB, at least 2A (or 10W) is recommended. Here are some additional rules of thumb:
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
In many cases, you will also be downloading code from the author's github site at https://github.com/HudsonWerks.
The BBB's on board micro HDMI port provides a relatively easy way to attach a display device. With the new Debian distribution, compatibility, and ease of installation, the process is greatly simplified. We will take a look at two types of devices you may be using: an HDMI monitor and a small form-factor LCD (without HDMI).
Using a display is not a requirement to operate the board and is merely optional. You will learn how to control the BBB without a display later in this chapter.
Running your board with an HDMI monitor is the default method to use your BBB.
Given the large universe of LCDs out there, this is not a definitive list. However, it does lend guidance on displays that will work with the BBB. You will also be pleasantly surprised that most consumer-grade HDTVs work pretty well out of the box with your board.
Check your resolution at http://elinux.org/Beagleboard:BeagleBoneBlack_HDMI.Plug in one end of your HDMI cable to your monitor and the other end, which is the micro HDMI end, into your powered-down BBB.Fulfill the power requirements; power up your board with a 5V adapter.Since HDMI displays can draw a lot of power, don't try to run off your desktop's USB slot. Otherwise, you will get flaky results at best and, more likely, no picture at all.
There's no obligation to use only an HDMI display on BeagleBone Black. For example, with the right HDMI to VGA converter cable, you can actually attach a standard VGA monitor to the BBB. Compatible converters can be found at http://elinux.org/Beagleboard:BeagleBone_Black_Accessories#HDMI_Adapters.
You may also develop an embedded prototype device that only needs a small LCD and no HDMI. Here's one recipe for a scenario using a 3.5-inch screen from Circuitco (http://elinux.org/CircuitCo:BeagleBone_LCD3) that I've used in my own projects. The display is in the category of add-ons to the BBB called capes, which are akin to the shields on an Arduino board. Capes are typically robust daughterboards and, unfortunately, tend to be much more expensive than Arduino add-ons.
CircuitCo LCD3 cape
Perform the following steps:
The pin line up at the bottom of the PCB (printed circuit board)
For more information on the following topics, refer to the respective websites:
Fancy GUIs are nice, but on BeagleBone Black, you will be mainly working with the command shell and its accompanying command-line tools to provide access to the operating system. First, let's take a look at some terminology: command shell, command-line shell, command line, or simply shell will all be used somewhat interchangeably as they all basically refer to the same thing—a means to provide access to the operating system with the command line and without a GUI. Bash is the default shell on Linux.
Terminal is yet another typical way to refer to the shell. The term is derived from its preceding technologies where any interaction with a computer required using a text-based terminal interface.
Often intimidating to new users, command shell is the starting point for any serious embedded system project. The Debian distribution for BeagleBone Black comes preloaded with two command-line tools to use a command shell: LXTerminal and Root Terminal. Although there are others with more robust and colorful interfaces that you can install, such as xterm and eterm, for simplicity's sake, we will use LXTerminal. In the next section, you will learn about the command syntax required within the tool. Finally, we will create, edit, and save a text file from the command line.
Ensure that your BeagleBone Black is set up and running in the manner described in the Introduction section. (Note that here, we will show the two different methods of running the board: powered via USB and powered via 5V).
This will show the following output:
Congratulations! You've just sent your first command to BeagleBone Black (and it wasn't Hello World). But we're getting ahead of ourselves. Commands are for the next section.
Let's take a quick look at the various parts of what LXTerminal shows us. Firstly, we know that Linux likes to keep the current user name at the front and center, in this case debian. This way, you always have a quick reference point to know whether you are a root user, which gives you total control over the system, or just another user with limited privileges.
Then comes the address of the device you're working on: beaglebone. You can actually customize the name, but we will save that for the appendix. Lastly, consider the $ sign, which denotes that you're logged in as a regular user. If you were a root user, the symbol would be the # sign. You will learn more about users and root users in a later section.
The command line is your friend.
For advanced users, this is an obvious statement; for the beginner, not so friendly. Where do you start with that darn blinking cursor?
