26,39 €
Master BeagleBone programming by doing simple electronics and Internet of Things projects
If you want to learn programming on embedded systems with BeagleBone by doing simple electronics projects, this book is for you. This book is also helpful to BeagleBone owners who want to quickly implement small-scale home automation solutions. It is assumed that you have familiarity with C and Python programming. Some familiarity with electronics is helpful but not essential.
The whole world is moving from desktop computers to smartphones and embedded systems. We are moving towards utilizing Internet of Things (IoT). An exponential rise in the demand for embedded systems and programming in the last few years is driving programmers to use embedded development boards such as Beaglebone.
BeagleBone is an ultra-small, cost-effective computer that comes with a powerful hardware. It runs a full-fledged Debian Linux OS and provides numerous electronics solutions. BeagleBone is open source and comes with an Ethernet port, which allows you to deploy IoT projects without any additions to the board. It provides plenty of GPIO, Anlaog pins, and UART, I2C, SPI pins which makes it the right choice to perform electronics projects. This gives you all the benefits of Linux kernel such as multitasking, multiusers, and extensive device driver support. This allows you to do programming in many languages including high-level languages such as JavaScript and Python.
This book aims to exploit the hardware and software capabilities of BeagleBone to create real-life electronics and IoT applications quickly. It is divided into two parts. The first part covers JavaScript programs. The second part provides electronics projects and IoT applications in Python.
First, you will learn to use BeagleBone as tool to write useful applications on embedded systems. Starting with the basics needed to set up BeagleBone and the Cloud9 IDE, this book covers interfacing with various electronics components via simple programs. The electronics theory related to these components is then explained in depth before you use them in a program. Finally, the book helps you create some real-life IoT applications.
An easy-to-follow guide full of real-world electronics programs and quick troubleshooting tips using BeagleBone. All the required electronics concepts are explained in detail before using them in a program and all programs are explained in depth. Most of the theory is covered in the first part; while the second part gives you some quick programs.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 236
Veröffentlichungsjahr: 2016
Copyright © 2016 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: January 2016
Production reference: 1220116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-001-3
www.packtpub.com
Cover image by Mr. Vipin Vikam (Silver photo studio, near Kasba Ganpati, Pune)
Author
Yogesh Chavan
Reviewers
Juan Cortez
Chris Desjardins
Michael Hirsch
Pavel Mamontov
Commissioning Editor
Amarabha Banerjee
Acquisition Editor
Kevin Colaco
Content Development Editor
Susmita Sabat
Technical Editor
Pranil Pathare
Copy Editor
Ting Baker
Project Coordinator
Milton Dsouza
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
YogeshChavan is a Linux enthusiast and open source promoter, living in Pune, India. He has now been teaching operating systems, device drivers, and embedded systems in colleges and institutes for more than three years. These include the computer science department of Pune University, Symbiosis Institute of Computer Studies and Research (SICSR) college, and the Centre for Development of Advanced Computing (C-DAC) institute. He has about six years of experience in the software industry. His previous industrial role was of a software maintenance engineer at Red Hat Software Services.
Yogesh has overseen many engineering projects under GEEP (http://www.geeksofpune.in). He has given many talks at the annual open source event, GNUnify (http://gnunify.in).
Yogesh enjoys cutting edge technologies. He is a hardware hobbyist who likes playing with smartphones, tablets, routers, and Arduino. He is big fan of Android and various Linux distributions. He has compiled and modified kernel and firmwares for many phones and routers. He wishes to be a humble contributor to the open source world.
I would like to thank my wife for putting up with my late-night writing sessions. This book would not have been possible without her devotion. I would also like to give thanks and gratitude to the editors, Akash, Susmita, and Kevin, that patiently guided me. They are the source of continuous encouragement.
I would like to thank my guru Dr. Vijay Gokhale Sir, who taught me a lot more than OS. I would also like to thank my friends, Omkar Kulkarni and Ashish Shah and online friend Swiftgeek, who helped me with the electronics concepts. Also, I thank my friend, Amit Karpe, for introducing me to Packt Publishing. I thank Mrs. Nutan Chaudhari, who gave me her BeagleBone White for the purpose of testing. I used Fritzing software to draw the circuit diagrams throughout the book. I would like to thank the Fritzing team. I also thank the BeagleBoard crew for creating wonderful open source hardware boards. Finally, I would like to thank the entire open source software movement.
JuanCortez is a first-generation college student from El Paso, Texas, majoring in electrical and computer engineering at the University of Texas at Austin. During his time in college, Juan dedicated most of his time providing services to various organizations, including the Equal Opportunity in Engineering Program, the University of Texas Longhorn Band, and Engineering Student Life. Outside of school, Juan had the distinct pleasure of interning at five different companies: Intel, Texas Instruments, Cirrus Logic, Toshiba, and IBM. In the summer of 2013, Juan interned at Texas Instruments and worked directly under the BeagleBone Black hardware architect Gerald Coley. During his time at Texas Instruments, he developed tutorials on how to program on the BeagleBone and entered their Intern Design Contest to showcase the skills that he has acquired during his internship. He is currently a software engineering intern at IBM and is working with big data by utilizing Apache Spark, which is a fast and general engine for large-scale data processing. Apart from work, Juan loves to volunteer and he mentors young students by exposing them to science, technology, engineering, and math (STEM) through fun projects and experiments.
Chris Desjardins is an embedded systems software engineer with 15 years of experience. His main focus throughout his career has been on real-time systems and multiprocessing. He has written code for a wide range of systems from small highly-parallel low power DSPs to huge real-time distributed processing systems, and everything in between. He currently loves living and working in Amsterdam, Netherlands. Look him up on LinkedIn at http://nl.linkedin.com/in/chrisdesjardins/
Michael Hirsch's research includes geospace remote sensing via tomography of the aurora. He has deployed autonomous outdoor climate-controlled one meter cubes with single photon sensitive cameras to rural Alaska in order to capture the faintest and fastest moving aurora that is invisible to the naked eye. He developed automatic OpenCV-based algorithms, reducing the data stream from terabytes/day to megabytes/day.
Michael founded SciVision, Inc. with applications including machine vision, embedded remote sensing systems, and wearable and batteryless sensors.
Pavel Mamontov is a Russian-born designer and web developer residing in New York City. He holds a BS degree in digital media from Drexel University and an MFA degree in design and technology from Parsons School of Design. He is currently employed at Metropolitan College of New York as an in-house web developer. In his free time, he loves to tinker with open source and open hardware technology, draw, and occasionally volunteer for various labor organizations.
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 whole world is moving from desktop/computers to smartphones/embedded systems. We are at the door to Internet of Things (IoT). The number of Internet connected users crossed 3.2 billion in 2015, which is almost half of the total population. The number of connected devices has exceeded the number of humans already. IoT is going to bring a combination of solutions, mixing physical world and digital world. We will interact with the digital world in newer ways than keyboard and mouse. Everyday objects will have logic in them to do their work in a better way. Multiple things will work collectively in order to achieve better results. IoT will bring lot many possibilities and opportunities along.
IoT implementation needs power-efficient embedded system solutions. There has been an exponential rise in the demand of the embedded systems in the last few years. Therefore, there is a demand for embedded programming as well. Embedded development boards such as BeagleBone play a key role here. These boards provide opportunities to new programmers to get their hands on ARM-based embedded systems. BeagleBone comes as an ultra-small, cost-effective solution with a powerful hardware that runs Debian Linux. This book tries to explore the hardware and software capabilities of BeagleBone to create real-life electronics and IoT applications quickly.
Being an open source hardware board, BeagleBone is the perfect choice to study embedded systems. Board design files and in-depth datasheets are open for being studied. It comes with an Ethernet port that allows deploying the IoT projects without making any addition to the board. It provides plenty of GPIO, ADC, UART, I2C, and SPI pins that make it the right choice for electronic projects. One can install Debian, Ubuntu, Android, and many other Liunx distributions. By default, it comes with a full-fledged Debian Linux OS running on it. This gives you all the benefits of Linux kernel such as multitasking, multiuser, and extensive device drivers support. It also allows you to do programming in many languages, including C, C++, JavaScript, Python, Ruby, Perl, and so on. This book uses BeagleBone as a tool to write useful applications on the embedded systems. Starting with the basics to set up BeagleBone and Cloud9 IDE, this book covers interfacing with various electronic components via simple programs. The electronics theory related to these components is explained in detail before using them in a program. Then, the book covers some real-life IoT applications.
This book is divided in two parts: the first part is covers programs in JavaScript and the second part of this book provides electronics projects and IoT applications in Python. Most of the physicial computing theories and concepts are covered in the JavaScript part. Programs are explained in the explanation section, immediately after it's source code. Troubleshooting steps are given wherever needed. Some programs have an execution section, which explains how a program works internally. Programming language conventions and error handling are loosely followed to make programs short and easy to understand. The language that is to be covered first is a tough choice. I choose JavaScript as it is energy-efficient, event-driven architecture. It is more suited as an IoT solution. Only sending the important information reduces the processing that is to be done on the Thing connected to the Internet. Javascript is a natural language of web. It comes preinstalled in the BeagleBone along with Node and Cloud9. You can start Javascript programming immediately after connecting BeagleBone. Let's start the journey of programming the BeagleBone.
Chapter 1, Cloud9 IDE, gives the essential information you need before you start programming on BeagleBone. It gives hardware and software-related information about the boards in the BeagleBone series. It provides you different ways to connect to BeagleBone and start Cloud9 IDE to program.
Chapter 2, Blinking Onboard LEDs, covers how to use Cloud9 IDE to write the first physical computing program—blinking onboard LED on the BeagleBone. It covers another program that creates a display pattern among the LEDs.
Chapter 3, Blinking External LEDs, explains the General Purpose Input/Output (GPIO) theory and how to attach the external LEDs to the GPIO pins. Then, it covers blinking LED and display pattern programs.
Chapter 4, Controlling LED Using a Push Button, teaches how to read from input components using polling. The interrupt method programs for each of these methods are covered.
Chapter 5, Reading from Analog Sensors, covers the theory about Analog I/O and how BeagleBone supports it. Then, it has programs to read from the TMP36 temperature sensor and light sensor.
Chapter 6, PWM – Writing Analog Information, explains how the Pulse Width Modulation (PWM) technique is used to write the analog information and how BeagleBone supports it. It has a program to fade-in LED and control the servo motor using PWM.
Chapter 7, Internet of Things with BeagleBone, explains how to implement IoT in JavaScript using BeagleBone. It covers important information about IoT. Then, there are three real-life examples. Two of them are programs to remotely control LED and servo motor. Another program is to shoot an e-mail alert when overtemperature is detected.
Chapter 8, Physical Computing in Python, explains rewriting all the programs that are covered from Chapter 3 to Chapter 6 in the Python language.
Chapter 9, UART, I2C, SPI Programming, covers popular buses in the embedded systems—UART, I2C, and SPI. All these protocols are explained here in detail. This chapter covers programs that communicate over each of these buses.
Chapter 10, Internet of Things Using Python, teaches IoT programs in Python. It has programs that were similar to the programs covered in Chapter 7. It has an additional program that uploads the temperature data over the Cloud website and we will receive the temperature graph over time for analysis.
Appendix A, GPIO Control in Bash, teaches how to set the direction and turn GPIO on/off directly by writing sysfs files.
Appendix B, BeagleBone Capes, provides information about BeagleBone add-on boards called capes.
Appendix C, Pinmux and the Device Tree, gives details about the new hardware description files that help the kernel to initialize BeagleBone. They are called device tree. It covers how to use the device tree files to select the role of the BeagleBone pin among other possibilities.
This book does not cover BeagleBone Programmable Realtime Units (PRUs) and building/customising installable image.
The required hardware is as follows:
The optional hardware is as follows:
This book is for anyone who wants to learn programming on the embedded systems and understand key concepts such as GPIO, PWM, and bus. It is intended for a programming beginner who is willing to explore the embedded systems programming by doing electronics projects. This book will be helpful for a BeagleBone owner who wants to quickly implement small-scale home automation solutions. Some hands-on experience is expected on C or Python. Some familiarity with electronics is helpful. However, it is not essential.
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.
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/ProgrammingTheBeagleBone_Graphics.pdf.
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.
BeagleBoard foundation has created a few low power ARM-based open hardware boards. The most successful board among them was BeagleBone Black. Actually, it is a series of boards that match physical size with the same processor and slightly different hardware. There are three variants in this series—BeagleBone White, BeagleBone Black and BeagleBone Green. This book is about programming boards in this BeagleBone series. We will see details about BeagleBone hardware as the first topic of this chapter. Then we will learn how to connect and set up BeagleBone for our work. All BeagleBones come with a programming interface called BoneScript. It is a faster and easier way to deal with components of BeagleBone. We are going to use BoneScript for programming in the first part of this book. At the end of this chapter, we will learn about IDE (Integrated Development Environment), which helps us to do programming in BoneScript—Cloud9.
Here are the topics that will be covered in this chapter:
The BeagleBoard foundation is a non-profit corporation promoting open source hardware and software. It has been releasing low power, hacker-friendly embedded boards since 2008. They have created a few powerful and educational single board computers. These boards are sold to the public under the Creative Commons share-alike license that encourages sharing. These boards are collectively called BeagleBoards. They have a GitHub page at https://github.com/beagleboard. Here you can find hardware information files and software related to released boards. Support for these boards comes from a very active developer community. The BeagleBoard group on Google has more than 10,000 members. You can view posts and join the group here: http://beagleboard.org/Community/Forums. Their IRC (Internet Relay Chat) channel #beagle on freenode is active. You can join the channel and ask questions at http://beagleboard.org/chat. There are more than 500 different projects registered with BeagleBoard at http://beagleboard.org/project.
There are two different series of released boards by beagleboard.org. First is the BeagleBoard series. This series has candidates—original BeagleBoard, BeagleBoard-xM and BeagleBoard-X15. These are comparatively big, square-sized boards. Their processors are slightly better in terms of performance and have an additional DSP (Digital Signal Processor) that can do better audio/video processing. These boards have many peripherals available onboard. They are more powerful and comparatively costly. These boards are perfect in scenarios where major audio/video processing is involved or performance is important.
Another series is called the BeagleBone series. This series has candidates—BeagleBone White, BeagleBone Black, BeagleBone Green. These boards are compact, lightweight and share the same physical size (3.4 inch × 2.1 inch). They all have the same Texas Instruments AM335x sitara ARM Cortex-A8 processor. These boards lack DSP and lag behind in scenarios with major audio/video processing. But these processors are fine in other scenarios. They come with fewer peripherals on board. You can attach many peripherals externally. They are far cheaper than boards in the BeagleBoard series. They provide many expansion i/o pins of type GPIO/I2C/SPI/PWM/UART/CAN/ADC. So you can connect lots of sensors, modules, electronic components, displays, and so on. to these boards. All these boards share the same expansion pins layout. This means if you study expansion of one board in the series, the knowledge applies to other boards in the series too. There are small differences in these boards. Please refer to the following table to learn the differences. All these characteristics make BeagleBone a popular choice among hardware hackers. Besides hardware, they can all boot up from the same firmware image. So all software stack is the same for them. These boards can be programmed using the same programming interface. All these boards come with preinstalled Cloud9 IDE, which allows you to write and deploy applications on that board in many programming languages remotely via web browser.
This book covers programming all boards in the BeagleBone series:
BeagleBone White
BeagleBone Black
BeagleBone Green
Processor
720MHzARM CortexA8
1GHz ARMCortex-A8
1GHz ARMCortex-A8
RAM
256MB DDR2
512MB DDR3
512MB DDR3
Storage
microSD slot only
2/4GB emmc, microSD slot
4GB emmc, microSD slot
Display/Audio
possible via external cape or USB port
onboard micoHDMI
possible via external cape or USB port
Power connector
via MiniUSB or 5.5mm DC jack(5V)
via MiniUSB or 5.5mm DC jack(5V)
Micro USB only
Boot debugging
onboard serial and JTAG via MiniUSB
via external USB-serial to header pins
via external USB-serial to header pins
Other connector
one standard 2.0 USB host port, one MiniUSB client port, one Ethernet port
One standard 2.0 USBhost port, one MiniUSB client port, one Ethernet port
one UART and one I2C grove connector, one standard 2.0 USB host, one Micro USB client port, one Ethernet port
Expansion
2x 46pin i/o expansion header
2x 46pin i/o expansion header
2x 46pin i/o expansion header
Comparison between different BeagleBones
This is the first board released in the BeagleBone series. It was released at the end of 2011. At that time, it was just called BeagleBone. Now after more boards have been released in this series, it is called Original BeagleBone or BeagleBone White (BBW). BBW brought single cable development environment. One MiniUSB cable from PC to BBW gives power to BBW, access to storage of BBW and network-over-USB capabilities for communication. The same cable also gives serial access and JTAG access for debugging via FTDI chip. For more information about BeagleBone White, visit the following links:
The BeagleBone Black board is shown in the following image:
BeagleBone Black was released in April 2013. It arrived with more processor speed, more RAM, onboard storage and Micro HDMI connectivity
