Learning BeagleBone Python Programming
()
About this ebook
- Configure and customize your BeagleBone to seamlessly connect it to external hardware using Python
- Learn to write programs that interface with the real world using GPIO ports
- Clear and step-by-step examples, complete with component lists, circuit diagrams, and Python code
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.
Alexander Hiam
Alexander Hiam, MBA, is a corporate consultant whose clients include many Fortune 500 companies. He has written numerous books and taught advertising and marketing at the University of Massachusetts at Amherst.
Read more from Alexander Hiam
Starting and Running a Business All-in-One For Dummies Rating: 4 out of 5 stars4/5Motivational Management Rating: 0 out of 5 stars0 ratingsBusiness Innovation For Dummies Rating: 0 out of 5 stars0 ratingsMarketing For Dummies Rating: 0 out of 5 stars0 ratingsMarketing Kit for Dummies Rating: 0 out of 5 stars0 ratings
Related to Learning BeagleBone Python Programming
Related ebooks
BeagleBone By Example Rating: 0 out of 5 stars0 ratingsBeagleBone Robotic Projects - Second Edition Rating: 0 out of 5 stars0 ratingsUsing Yocto Project with BeagleBone Black Rating: 0 out of 5 stars0 ratingsCommercial and Industrial Internet of Things Applications with the Raspberry Pi: Prototyping IoT Solutions Rating: 0 out of 5 stars0 ratingsBeagleBone Essentials Rating: 0 out of 5 stars0 ratingsBeagleBone Home Automation Blueprints Rating: 0 out of 5 stars0 ratingsMastering BeagleBone Robotics Rating: 5 out of 5 stars5/5Learning BeagleBone Rating: 0 out of 5 stars0 ratingsIntel Galileo Essentials Rating: 0 out of 5 stars0 ratingsProgramming the BeagleBone Rating: 0 out of 5 stars0 ratingsProgramming the BeagleBone Black: Getting Started with JavaScript and BoneScript Rating: 0 out of 5 stars0 ratingsRaspberry Pi 3 Projects for Java Programmers Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotics Essentials Rating: 0 out of 5 stars0 ratingsPractical Django 2 and Channels 2: Building Projects and Applications with Real-Time Capabilities Rating: 0 out of 5 stars0 ratingsBuilding a Home Security System with Raspberry Pi Rating: 0 out of 5 stars0 ratingsAndroid Things Projects Rating: 0 out of 5 stars0 ratingsLearn Electronics with Raspberry Pi: Physical Computing with Circuits, Sensors, Outputs, and Projects Rating: 0 out of 5 stars0 ratingsPython for Google App Engine Rating: 0 out of 5 stars0 ratingsBuilding a Home Security System with BeagleBone Rating: 4 out of 5 stars4/5Building Smart Homes with Raspberry Pi Zero Rating: 0 out of 5 stars0 ratingsArduino BLINK Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotic Projects - Third Edition Rating: 0 out of 5 stars0 ratingsBeginning Sensor Networks with XBee, Raspberry Pi, and Arduino: Sensing the World with Python and MicroPython Rating: 0 out of 5 stars0 ratingsData Science with Raspberry Pi: Real-Time Applications Using a Localized Cloud Rating: 0 out of 5 stars0 ratingsDevOps in Python: Infrastructure as Python Rating: 0 out of 5 stars0 ratingsIoT Data Architecture A Complete Guide Rating: 0 out of 5 stars0 ratingsBuilding Networks and Servers Using BeagleBone Rating: 0 out of 5 stars0 ratingsThe Art of Designing Embedded Systems Rating: 0 out of 5 stars0 ratingsGoogle Home User Manual: Beginner's Guide to Start Using Google Home Like a Pro! Rating: 0 out of 5 stars0 ratings
Hardware For You
50 Android Hacks Rating: 5 out of 5 stars5/5Dancing with Qubits: How quantum computing works and how it can change the world Rating: 5 out of 5 stars5/5MacBook For Dummies Rating: 4 out of 5 stars4/5macOS Big Sur For Dummies Rating: 0 out of 5 stars0 ratingsTI-84 Plus CE Graphing Calculator For Dummies Rating: 0 out of 5 stars0 ratingsElectrical Engineering | Step by Step Rating: 0 out of 5 stars0 ratingsSamsung Galaxy S23 Ultra User Guide for Beginners and Seniors Rating: 3 out of 5 stars3/5Computer Science: A Concise Introduction Rating: 4 out of 5 stars4/5Upgrading and Fixing Computers Do-it-Yourself For Dummies Rating: 4 out of 5 stars4/5Mastering ChatGPT Rating: 0 out of 5 stars0 ratingsCompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5iPhone For Seniors For Dummies: Updated for iPhone 12 models and iOS 14 Rating: 4 out of 5 stars4/5Raspberry Pi for Secret Agents - Third Edition Rating: 0 out of 5 stars0 ratingsCompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5Build Your Own PC Do-It-Yourself For Dummies Rating: 4 out of 5 stars4/5Getting Started With MacBook Air (2020 Model): A Guide For New MacOS Users Rating: 0 out of 5 stars0 ratingsiPhone 12, iPhone Pro, and iPhone Pro Max For Senirs: A Ridiculously Simple Guide to the Next Generation of iPhone and iOS 14 Rating: 0 out of 5 stars0 ratingsCreative Selection: Inside Apple's Design Process During the Golden Age of Steve Jobs Rating: 5 out of 5 stars5/53D Printing For Dummies Rating: 4 out of 5 stars4/5iPhone X Hacks, Tips and Tricks: Discover 101 Awesome Tips and Tricks for iPhone XS, XS Max and iPhone X Rating: 3 out of 5 stars3/5Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems Rating: 4 out of 5 stars4/5Raspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5USB Complete: The Developer's Guide Rating: 4 out of 5 stars4/5Brilliant S-Pen Apps for Your Galaxy Note Rating: 5 out of 5 stars5/5Going iPad (Third Edition): Making the iPad Your Only Computer Rating: 5 out of 5 stars5/5Arduino: A Quick-Start Beginner's Guide Rating: 4 out of 5 stars4/5Raspberry Pi for Secret Agents - Second Edition Rating: 3 out of 5 stars3/5Computer Organization and Design: The Hardware / Software Interface Rating: 4 out of 5 stars4/5iPhone 14 Pro Max User Guide for Beginners and Seniors Rating: 0 out of 5 stars0 ratings
Reviews for Learning BeagleBone Python Programming
0 ratings0 reviews
Book preview
Learning BeagleBone Python Programming - Alexander Hiam
Table of Contents
Learning BeagleBone Python Programming
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
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Before We Begin
An overview of BeagleBone
General purpose input/output
Analog-to-digital converter
Pulse width modulation
Universal asynchronous receiver/transmitter
Serial peripheral interface
Inter-Integrated Circuit
Tools and additional hardware
The BeagleBone design
Board comparison
Helpful resources
Summary
2. Getting Started
Initial setup
Updating your Debian image
Connecting to your BeagleBone
The Cloud9 IDE
SSH
Connecting to the Internet
Ethernet
Network forwarding
Using the serial console
Updating your software
The PyBBIO library
The Adafruit_BBIO library
Summary
3. Digital Outputs
GPIO modules
Kernel drivers
Pin multiplexing
Interactive GPIO
Calculating resistor values for LEDs
Driving higher currents from GPIO pins
Blink
Taking advantage of the OS
Multiprocessing
Running at startup
Summary
4. PWM and ADC Subsystems
PWM
Fading an LED
Servo motors
ADC
Voltage divider
Voltage follower
Your first robot
Summary
5. User Input
Buttons
Pull-up/pull-down resistors
Polling
Interrupts
Potentiometers
Summary
6. Program Output
LED displays
LED bar graphs
7-segment displays
The LED matrix
SMTP
Character LCD
Summary
7. Serial Communication
Serial communication
UART
I2C
SPI
Summary
8. Interfacing with External Devices
Accelerometers
Hooking it up
Reading data
Writing a module
Using interrupts
Summary
9. Using the Network
TCP/IP
HTTP
IoT Services
Phant
dweet.io
Freeboard
Summary
10. A Practical Example
Weather station
Connecting to the Internet
Weather alerts
Summary
A. The BeagleBone Black Pinout
B. Disabling HDMI
Index
Learning BeagleBone Python Programming
Learning BeagleBone Python Programming
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
Credits
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
About the Author
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.
About the Reviewers
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 <hardik@hardik.org>.
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
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 Packt
Copy and paste, print, and bookmark content
On 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
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.
What this book covers
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.
What you need for this book
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.
Who this book is for
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.
Conventions
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:
def loop():
print switch state:
, digitalRead(SW_PIN)
delay(250)
run(setup, loop)
Any command-line input or output is written as follows:
root@beaglebone:/var/lib/cloud9# ping -c 3 graycat.io PING graycat.io (198.100.47.208) 56(84) bytes of data.
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.
Note
Warnings or important notes appear in a box like this.
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 <feedback@packtpub.com>, 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