32,39 €
If you have experience with the Python language and are interested in getting started with electronics, then BeagleBone Black is the perfect platform for you and this book will provide you with the information you need.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 170
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: July 2015
Production reference: 1080715
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-970-2
www.packtpub.com
Author
Alexander Hiam
Reviewers
Pete Bachant
Hardik Vijaykumar Pandya
Acquisition Editor
Shaon Basu
Content Development Editor
Anand Singh
Technical Editor
Bharat Patil
Copy Editor
Merilyn Pereira
Project Coordinator
Vijay Kushlani
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
Alexander Hiam is a freelance embedded systems designer. He has a bachelor's degree in computer science (embedded systems) from Marlboro College. He is the sole proprietor of Gray Cat Labs, where he has been doing contract software and hardware development since 2012.
Alex developed and actively maintains the PyBBIO Python library for BeagleBone. He has designed BeagleBone Capes professionally for clients, and he also actively contributes to the BeagleBone community by helping provide support on the mailing list and IRC channel and mentoring for the BeagleBoard.org organization during Google Summer of Code.
I'd like to thank my cat, Moondog, for being so patient with me while I worked on this book, as he was sure I should have been playing with him instead.
Pete Bachant is a mechanical engineering PhD student at the University of New Hampshire who enjoys writing Python and uses the BeagleBone to interact with motion control and data acquisition hardware.
Hardik Vijaykumar Pandya is an electrical engineering graduate from TU Delft in the Netherlands. He's been working on open source hardware and software for the last 7 years and has conducted state-wide workshops on them in different universities across Gujarat, India.
His projects have been selected for display at the national level and his work on hobby electronics has been lauded by the mayor of Ahmedabad a number of times. His work on optical shape and motion recognition using the Microsoft Kinect camera also won the best and most innovative project of the year award at Nirma University.
Nowadays, he reviews books on subjects related to electronics and manages his own business in the same domain. He does a lot of public speaking on the topics of getting started with electronics and entrepreneurship. He also writes articles at http://hardik.org and shares his views on Twitter. His Twitter handle is @hvpandya.
He can be reached for questions and queries at <[email protected]>.
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.
The BeagleBone Black is a powerful system that can be used in a huge number of cool projects and is a great platform to learn about embedded systems and embedded Linux, but it can be difficult for beginners to find the resources they need to get started with it. The goal of this book is to use the Python programming language to introduce you to many of the different hardware interfaces available on the BeagleBone Black, and to teach you how to use them to communicate with external hardware with the help of the PyBBIO and Adafruit_BBIO Python libraries. This book will take you through the system, from initial setup to creating complete programs, and each new concept along the way is introduced with practical and contextual examples.
Chapter 1, Before We Begin, introduces you to the BeagleBone Black and to each of its hardware interfaces that are used throughout the book.
Chapter 2, Getting Started, takes you through the initial steps to get your BeagleBone Black setup and ready to use, and briefly introduces you to the PyBBIO and Adafruit_BBIO Python libraries.
Chapter 3, Digital Outputs, goes more in depth into using the GPIO modules to generate digital outputs, and guides you through your first hardware interface programs to blink some LEDs.
Chapter 4, PWM and ADC Subsystems, describes in more detail the pulse width modulation and analog-to-digital converter subsystems, and guides you through using them to fade LEDs, control servo motors, measure light levels, and more. It also introduces some basic concepts for analog signal conditioning.
Chapter 5, User Input, presents some methods of using external hardware to interface with your BeagleBone programs, including potentiometers, buttons, and rotary encoders.
Chapter 6, Program Output, covers some methods of using external hardware to provide feedback to the user, from LED and LCD displays to sending e-mails and text messages.
Chapter 7, Serial Communication, describes in more depth the UART, I2C, and SPI serial subsystems and how they can be used to communicate with external digital devices.
Chapter 8, Interfacing with External Devices, walks you through the steps required to interface with a new digital device by writing a Python module to communicate with an accelerometer over I2C.
Chapter 9, Using the Network, shows you some ways of taking advantage of the BeagleBone Black's network connection to remotely control and monitor your applications.
Chapter 10, A Practical Example, walks you through using what you've learned to build a BeagleBone Black weather station with remote monitoring and automatic over/under temperature e-mail or text message alarms.
Appendix A, The BeagleBone Black Pinout, provides you with a visual description of the BeagleBone Black's expansion headers and the different ways each pin can be used.
Appendix B, Disabling HDMI, teaches you to disable the HDMI output.
This book specifically targets the BeagleBone Black. It also assumes a Windows OS where setup steps are required to be run on a desktop or laptop PC, as in my experience Windows has been the main OS of folks who are just starting out with BeagleBone.
If you are a Python programmer and have never had any experience with embedded Linux and hardware development, this book is for you. Some previous Linux experience will be helpful, but is not required.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, folder names, filenames, file extensions, pathnames, and user input are shown as follows: "This will open the crontab file in nano, which is a command line text editor."
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Select Obtain IP address automatically and click on OK."
Warnings or important notes appear in a box like this.
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.
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.
Image Disclaimer
This book includes images of breadboard wiring which were generated using Fritzing (http://fritzing.org), and schematics generated using Eagle (http://cadsoftusa.com/). It also includes some screen captures of a Rigol oscilloscope.
Before we start hooking up hardware and writing code, we'll need to have an understanding of what we're working with. This chapter will introduce you to the BeagleBone and highlight the various interfaces it provides to connect to external devices. It will cover:
The BeagleBone boards are a series of small, powerful, and affordable Linux computers that are perfect for embedded applications such as home automation, robotics, industrial control, and much more. They are designed by BeagleBoard.org (http://beagleboard.org/) and are fully open source. They are based on the Texas Instruments AM335x 1GHz ARM Cortex-A8 series of microprocessors, and can run a number of different operating systems, including various GNU/Linux distributions, Android, and even Windows Embedded CE. The current BeagleBone model being produced is the BeagleBone Black rev C, which ships with a Debian GNU/Linux distribution. Therefore, this book will focus on using Debian on the BeagleBone Black, though much of the information given will apply to other BeagleBone models and Linux distributions as well.
The following screenshot shows the BeagleBone board:
The BeagleBone Black's AM335x microprocessor contains a number of built-in peripheral interface subsystems, enabling it to accept and generate many different forms of inputs and outputs. The BeagleBone Black includes two 2 x 23 pin rows of female header pins, giving a total of 92 connection points for hardware expansion using the processor's peripheral interface subsystems.
The general purpose input/output (GPIO) module handles all the digital input and output. In this context, digital refers to the fact that the signals are binary; they are either 1 or 0, represented by fully on and fully off respectively. In the case of the AM335x, the fully-on level is 3.3V, and the fully-off level is 0V. The GPIO module is used for inputs such as switches and buttons, which are either on or off. Its outputs can be used to control devices, such as LEDs, buzzers, and relays.
The analog-to-digital converter (ADC) module is used to measure analog voltages. The AM335x ADC can only measure voltages between 0V and 1.8V (and voltages outside this range may damage your BeagleBone), but, in later chapters, you will learn how to divide larger voltages to be within this range. The ADC can be used to receive inputs from devices such as potentiometers, which can be used to create varying voltages, measure the voltage output of analog sensors for temperature, light, sound, and different types of gases, and with some additional external components it can be used to measure electrical current.
The pulse width modulation (PWM) module is essentially used to generate a square wave signal at a fixed frequency, and then vary its duty cycle. It gives us the ability to accurately generate pulses of a configured duration, repeating at a configured frequency. Like the GPIO module, the PWM module on the BeagleBone Black operates at 3.3V. These PWM signals can be used to control servo motors, vary the speed of DC motors and the brightness of LEDs, and with some additional external components they can be used to generate varying voltages.
The universal asynchronous receiver/transmitter (UART) modules are used to transmit and receive RS-232 style serial signals, which is an industry standard for serializing and transferring information between two devices using a pair of unidirectional digital signals. They can be used to communicate with PCs, Bluetooth and Wi-Fi radio modules, and GPS receivers. The BeagleBone Black's UART modules also operate at 3.3V.
The serial peripheral interface (SPI) module is used to communicate over SPI, which is another industry standard serial protocol. Whereas UARTs are generally used to connect two devices, SPI is made to connect one master device to one or many slave devices. It is commonly used on devices such as small character and graphics LCD screens, external ADCs, and DACs (Digital-to-Analog converters), as well as on many different types of sensor. The BeagleBone Black's SPI modules operate at 3.3V as well.
Inter-Integrated Circuit (I2C) is yet another industry standard serial protocol. It also allows a master device to communicate with a bus of many slave devices, but it requires fewer pins than SPI. It is commonly used by real-time clocks (RTCs), as well as in many types of sensors, including Micro-Electro-Mechanical Systems (MEMS) devices, such as accelerometers, magnetometers, and gyroscopes. The BeagleBone's I2C modules operate at 3.3V.
The majority of the demo programs in this book use external hardware that must be purchased separately. Each time a demo program is given, which requires additional parts, they will be listed by part number and/or description. We will do our best to use the most readily available and lowest cost parts. All of the parts used can be purchased from one or more of the following resources:
The circuits in each demo will be assembled using solderless breadboard and jumper wires. Both come in many different shapes and sizes.
Breadboards and jumper wires can be purchased from any of the preceding links, and you'll probably want to start out with one standard-sized breadboard and a jumper wire kit, such as that from Adafruit:
That should provide enough breadboard space and jumper wires to assemble most, if not all, of the demo circuits in this book.
Just like with software, it is inevitable when assembling hardware that things won't always work the first time. There are many tools that can greatly reduce the time it takes to fix these problems. The most useful for the circuits in this book will be a multimeter, which is a tool that measures voltage and current, and often additional properties such as resistance, capacitance, and frequency. Both SparkFun and Adafruit carry very affordable digital multimeters. While these are not high quality measurement tools, they are certainly suitable for these circuits. Though not essential, I would highly recommend having some sort of multimeter on hand when building the circuits in this book.
More helpful than a multimeter for debugging tools such as PWM and serial protocols is an oscilloscope, which shows you a plot of voltage over time to visualize many different signals in a circuit. This is a more expensive tool, and will be less necessary for these circuits. Throughout the book, however, you will see screen captures of an oscilloscope to show various signals, and it should become evident just how helpful they can be. Again, Adafruit and SparkFun carry affordable oscilloscopes.
The BeagleBone