BeagleBone Black Cookbook - Charles A. Hamilton - E-Book

BeagleBone Black Cookbook E-Book

Charles A. Hamilton

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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:

EPUB
MOBI

Seitenzahl: 412

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

BeagleBone Black Cookbook
Credits
About the Author
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
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Setting Up for the First Time
Introduction
First boot up
Getting ready
How to do it…
Getting ready
How to do it...
Power requirements – basic guidelines
Display
Connecting an HDMI LCD
How to do it...
Connecting a non-HDMI LCD or cape
How to do it...
There's more…
Essential GNU/Linux commands – the command shell
Getting ready
How to do it...
How it works...
Essential GNU/Linux commands – typical commands
Getting ready
System navigational command – change your directory – cd
How to do it…
There's more…
System navigational command – show your current directory – pwd
How to do it…
System navigational command – find a file – find
How to do it…
Device and system insight – shows what's inside a directory – ls
How to do it…
Device and system insight – find out what USB devices are connected – lsusb
How to do it…
Device and system insight – get information about connected devices – cat/proc/bus/input/devices
How to do it…
There's more…
Device and system insight – get your version of Linux
How to do it…
Device and system insight – find out running processes – ps
How to do it…
Device and system insight – find out the resources used by running processes – top and htop
How to do it…
Device and system insight – quitting processes – kill
How to do it…
Device and system insight – message reports – dmesg
How to do it…
Device and system insight – shows disk space – df -h
How to do it…
Device and system insight – explore network – Ifconfig
How to do it…
Modify content / data commands – make a new directory – mkdir
How to do it…
Modify content/data commands – remove a file or directory – rm
How to do it…
Modify content / data commands – download files – wget
How to do it…
There's more…
Modify content / data commands – open a tar file – tar [options]
How to do it…
There's more…
Modify content / data commands – clean up files – autoclean
How to do it…
Modify content / data commands – purge a package – apt-get purge, apt-get remove --purge
How to do it…
Modify content/data commands – shutdown the system – [options]
How to do it…
See also
Edit a text file from the command shell
How it works...
How to do it...
See also
Connectivity
Connectivity – Ethernet
Getting ready
How to do it...
Connectivity – Wi-Fi
Getting ready
How to do it...
There's more…
See also
Package management – Installing packages using apt-get
Getting ready
How to do it…
See also
SSH / Remote access
Using SSH to control your BBB
How to do it…
Using VNC to control your BBB
Getting ready…
How to do it...
There's more...
System images
OS image flashing – internal drive boot
Getting ready
How to do it...
There's more…
Expand your partition
Backing up a code image to a file
OS image flashing – the SD card boot
Getting ready
How to do it...
Updating your current OS kernel
See also
2. Basic Programming Recipes
Introduction
Introduction to BoneScript
Toggle LED
How to do it...
See also
Using the Cloud9 IDE
How to do it…
See also
Node.js basic recipes
Adding a new module to Node.js
Getting ready
How to do it...
There's more…
See also
Using Node.js with Johnny-Five
How to do it…
There's more…
Python basic recipes
Getting ready
Adding libraries
How to do it…
Running a Python script to control the LEDs
How to do it…
There's more…
3. Physical Computing Recipes Using JavaScript, the BoneScript Library, and Python
Introduction
The essentials of electronics
Header pins and pinmuxing
The process of pinmuxing
There's more…
Controlling external LEDs
Getting ready
How to do it...
Writing an alternative script with Python
There's more…
Using buttons – button press function
Pull-up, pull-down, and floating
Getting ready
How to do it...
There's more…
Using analog sensors
Temperature sensors
Getting ready
How to do it...
There's more…
See also
Variable resistance sensor – photocell
Getting ready
How to do it…
Using motors
DC motors
Getting ready
How to do it...
How it works...

Servo motors
A crash course in pulse width modulation
Getting ready
How to do it...
There's more…
4. Exploring GNU/Linux Recipes Using Bash, Autotools, Debugger, and systemd
Introduction
The basic shell script
How to do it...
Epoch Time shell script
How to do it...
There's more...
Compile and install
See also
Compile and install Git from source
How to do it...
Debugging
See also
Debug a simple C-code application from the command line using GDB
How to do it...
See also
Debug an application remotely from Eclipse and GDB server
How to do it...
There's more…
systemd services
There's more…
See also
Basic commands for systemd services
How to do it...
There's more…
Optimize boot time
How to do it...
Create a systemd service to run at boot time
How to do it...
5. Basic Programming Recipes with the Linux Kernel
Introduction
Kernel building basics
See also
Kernel application binary interface
Getting ready
How to do it...
How it works…
Installing the latest kernel image
Getting ready
How to do it...
Installing and building a custom kernel
Getting ready
How to do it...
Interactions with the kernel – sysfs entries and controlling the GPIOs
Getting ready
How to do it...
There's more…
Device Tree and its roots
There's more…
Device Tree / basic build
Getting ready
How to do it...
Device Tree / advanced – adding DT overlay to run a custom cape
Getting ready
How to do it...
There's more…
See also
Universal cape overlay
Getting ready
How to do it…
There's more…
Running a script to check DT usage on GPIO pins
Getting ready
How to do it…
6. Run Faster, Run Real Time
Introduction
Installing a test tool
Getting ready
How to do it...
See also
Modifying the kernel using RT-PREEMPT
Getting ready
How to do it…
There's more…
Modifying the kernel using Xenomai
Getting ready
How to do it...
There's more…
See also
Programmable real-time units – an introduction
Getting ready
How to do it…
A simple PRU test with an assembler
Getting ready
How to do it…
See also
Running an ultrasonic range sensor with the PRUs
Getting ready
How to do it…
Using Python with the PRUs
Getting ready
How to do it…
See also
7. Applied Recipes – Sound, Picture, and Video
Introduction
Wiring up a mini amp and speakers
Getting ready
How to do it…
Creating a high-quality audio platform with Volumio
Getting ready
How to do it…
There's more…
See also
Using videos and displays in projects
Getting ready
How to do it…
There's more…
Testing a mini LCD cape
Getting ready
How to do it…
Making a video chat client prototype using Linphone
Getting ready
How to do it…
Part I – compiling and installing a Linphone binary from the repository
Part II – compiling and installing Linphone from source
Getting ready
How to do it…
8. The Internet of Things
Introduction
Location-based recipes – hooking up GPS
Getting ready
How to do it…
There's more...
Location-based recipes – Bluetooth LE and Beacons
Getting ready
How to do it…
There's more...
Using sensors and data with ThingSpeak
Getting ready
How to do it…
See also
Making things smarter – building a wireless digital picture frame
Getting ready
How to do it...
See also
9. The Black in Outer Space
Introduction
Grabbing the International Space Station flyover data and visualizing it
Getting ready
How to do it…
There's more…
Tracking using RTL-SDR
See also
Airplane tracking with RTL-SDR
Getting ready
How to do it…
There's more…
Satellite tracking using GPredict and RTL-SDR
Getting ready
How to do it…
There's more…
Satellite tracking using the SatNogs Network client / ground station and RTL-SDR
Getting ready
How to do it…
Adding other interfaces – ISS tracking and text to speech
Getting ready
How to do it…
There's more…
Index

BeagleBone Black Cookbook

BeagleBone Black Cookbook

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

Credits

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

About the Author

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.

About the Reviewers

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.

www.PacktPub.com

Support files, eBooks, discount offers, and more

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.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free Access for Packt account holders

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.

Preface

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:

Physical computing options: With its huge array of pins, you can wire up far more—be it sensors, motors, displays, or other hardware—than almost any other board on the market, even RPi.Out-of-the-box simplicity: As the BBB comes preloaded with a Linux OS (Debian), all you need to get going quickly is a mini USB cable to power up the board. There is no futzing around with installing software or adding peripherals to operate it.Internal drive: While other small board computers of this ilk can only run from an SD or microSD boot, BeagleBone Black comes with an internal solid-state drive, referred to as eMMC, to run the OS.Open source design: If you want to knock it off for a custom project, you can do it; all board designs and schematics are freely available.Real-time applications: Unlike other boards, such as Raspberry Pi, BeagleBone Black has a set of separate processors that can ensure that your code runs rock-solid and according to your expectations, which is an extremely unique feature for a computer at such a low price point.

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.

What this book covers

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.

What you need for this book

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:

BeagleBone Black Revision C: Typically referred to as Rev C, the version of the board we will use is the most current one available on the market at the time of writing. Earlier versions should work with the vast majority of the recipes in this book; however, we cannot guarantee their reliability in all cases.MicroSD card (minimum 8 GB): Even though the board has an internal solid-state drive (eMMC) to run the OS, we often need to test recipes and different flavors of the kernel. So, being able to quickly swap out the operating system on a MicroSD card is an enormous timesaver. In fact, you will see us more commonly booting from the MicroSD than the internal drive.Power supply: You have more than one option to power up, though the recipe will recommend specifically which of these to use:
5V power: This is a 5V 2A (2000mA) switching power supply.A mini-B USB cable: A great many of the recipes allow you to power the board with nothing more than the USB cable that should have come with your board when you purchased it. The standard USB connector goes into the USB port on your desktop client, which becomes the power source for BeagleBone Black.
Display: There are basically three options to get a display going on your board:
An HDMI screen: This out-of-the box approach assumes that you will connect your board to an HDMI monitor. Compatible hardware is listed at http://elinux.org/Beagleboard:BeagleBoneBlack_HDMI. If you do use this option, you will need a micro HDMI to standard HDMI cable.A mini LCD or "cape": We will learn how to connect a small LCD to the board's header pins. As this is somewhat of a custom solution, we do not assume that you will typically use this method except in relevant use cases.A remote session: As we will see in an early chapter, much of your work on BeagleBone Black can be done via remote sessions using Secure Shell (SSH) on a client desktop machine, such as a Mac or Windows box. Note that this will be our favored approach and recommendation because it obviates the need for a keyboard, monitor, and mouse.
A USB hub: We frequently recommend a powered hub, otherwise, the board's power draw will cause some peripherals, such as Bluetooth dongles, to underperform or not perform at all. Note that this must be a powered USB hub.A client machine: Interacting and controlling BeagleBone Black is often greatly simplified by connecting it to a client desktop machine running Windows, Mac OS, or even Linux. We are biased toward the Mac OS, so most of the recipes assume that you are using a Macintosh box. However, if you are not on Mac, the recipes are essentially the same and the principal steps and code are not affected.A board enclosure: This is not actually a requirement but a highly recommended "nice-to-have" tool. Besides protecting the board from damage, enclosing it in some kind of small box makes it much more manageable, especially when you have multiple wires snaking all over the place. You can find a variety of enclosures at http://bit.ly/1KTNPbF and on our site at http://bit.ly/1WrBqrv.

The software requirements are as follows:

Debian Linux: If you purchased your board directly from a well-established distributor, it should have come preloaded with Debian 7 Wheezy (kernel 3.8.x-bone kernel), which will be our principal assumption for the OS. We will also be referencing Debian 8 Jessie (kernel 3.14.x).

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.

Who this book is for

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.

Sections

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:

Getting ready

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.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Reader feedback

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.

Customer support

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.

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.

Downloading the color images of this book

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/

Errata

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

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.

Questions

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.

Chapter 1. Setting Up for the First Time

In this chapter, we will focus on the following topics:

First boot upPower requirements – basic guidelinesDisplayEssential GNU/Linux commands – the command shellEssential GNU/Linux commands – typical commandsEdit a text file from the command shellConnectivityPackage management – Installing packages using apt-getSSH / Remote accessSystem images

Introduction

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.

First boot up

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).

Getting ready

Here's what you need:

Desktop client PC: As noted in the introduction, we will principally be using a Mac box as our client machine. However, the following steps apply equally to a Windows or Linux machine.USB cable: A mini USB-B to USB cable is required, which is typically supplied with your board.BeagleBone Black Rev. C: To reiterate a point from this book's introduction, our recipes use Rev. C, which is the currently shipping version of the board. If you have an earlier board, you may run into occasional conflicts with the recipes.

How to do it…

Perform the following steps:

To power up, plug the USB cable into the BBB and your client box.Wait for the three blue LEDs to light up; each of them functions as a useful indicator of the board's health:
Power: Once power is supplied to the board, the LED next to the 5V barrel jack will remain on without flashingUSR0: Next to the tiny reset button (S1), this light maintains a continuous, solid "heartbeat" blink when poweredUSR2: Two down from the Ethernet jack, this LED flutters subtly during CPU access

Note

Unless otherwise noted, all images are copyright Charles A. Hamilton.

Within a few moments on your client machine, the BEAGLE_BONE drive should appear as a visible volume on your desktop. Browse the folder and open up the START.htm file.Once opened, you will find a clear set of quick start steps, including how to install drivers (if needed).Browse your board—BeagleBone Black's boot system includes a handy web server that allows immediate connectivity. Clicking on the link will take you to the local IP address of the board at 192.168.7.2. Once there, you will find a very helpful presentation on the board.

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.

Getting ready

Power down: Before proceeding, remove all cables and power (USB, Ethernet, DC cord, HDMI, and so on).

How to do it...

Perform the following steps:

Connect the USB cable: With a USB 2.0 A to Mini-B cable, connect the BBB to a USB port on your desktop PC.Look for status lights: After plugging in the USB cable, you will see the board's first LED light up, followed subsequently by the three other LEDs. If all goes well, the BEAGLE_BONE device will appear on your desktop.Install drivers: I won't belabor this step. It suffices to say that your desktop—whether it's a Windows, Mac, or Linux machine—requires certain drivers to recognize and run the BBB via USB properly. If your desktop OS doesn't come with the drivers already installed (as some do), install them via the link, http://beagleboard.org/Getting-Started.Once your drivers are installed, browse to the BASIC_START.htm file on the BEAGLE_BONE device and open it.

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.

Power requirements – basic guidelines

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:

You can power the BBB via the USB tether. However, if you attach additional USB devices, such as webcams, Wi-Fi or Bluetooth dongles, keyboards and mice, and then power them through the USB tether, it may lead to unreliable connections and power fluctuations. We were successful in powering some USB dongles directly via the BBB's USB port, whereas some devices, such as USB webcams, were not reliably powered.If you connect USB devices, it is best to power them from a powered USB hub and then supply power to the BBB via a 5 VDC power supply of at least 1A.5V DC power—most users of the board will invariably recommend that you always power your board using a 5V DC supply.You can also use a 5V wall charger power adapter with a USB port on it as long as it can deliver 1A.

Tip

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.

Display

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).

Note

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.

Connecting an HDMI LCD

Running your board with an HDMI monitor is the default method to use your BBB.

How to do it...

Check the compatibility list for your HDMI LCD monitor at http://elinux.org/Beagleboard:BeagleBone_Black_Accessories#Monitors_and_Resolutions.

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.

Note

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.

You should get a straightforward boot up into the default desktop "beagle" screen.

Connecting a non-HDMI LCD or cape

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

How to do it...

Perform the following steps:

Power down your board.Examine the header pins at the bottom of the LCD3 and note the pin layout: one short row and one longer row. Also, note the Power (PWR) button at one end.

The pin line up at the bottom of the PCB (printed circuit board)

Position the long row of pins on the LCD on top of the P9 pin slots on the BBB and the short pin row on the P8 row. Don't push the pins in yet. The PWR button should rest between the Ethernet port and the 5V barrel jack, as in the following image:Next, slowly push the pins into the BBB headers. All pins should go in more or less simultaneously. It's a little tricky as you also have to squish the PWR button in place at the same time so that it lodges snugly between the 5V barrel and the Ethernet jack, as in the following image:All pins on both sides of the LCD should be firmly pushed into place on the board, and the PWR button should be securely squeezed in place.Power up your board. Most distributions—including the Debian firmware, of course—have compatible drivers for the display, so you should boot right into your desktop within a few moments.

There's more…

For more information on the following topics, refer to the respective websites:

HDMI Troubleshooting: http://elinux.org/Beagleboard:BeagleBoneBlack_HDMIOther LCD cape options: http://elinux.org/Beagleboard:BeagleBone_Capesux driver

Essential GNU/Linux commands – the command shell

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.

Getting ready

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).

How to do it...

Begin by opening up LXTerminal, which you will find in the Accessories application on the lower left-hand side of the screen:You will now see a command prompt that looks similar to this on your screen:Just for fun, let's type in the following at the command prompt:
debian@beaglebone:~$ echo Can you hear me Major Tom?

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.

How it works...

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.

Essential GNU/Linux commands – typical commands

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?