Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Learning BeagleBone Python Programming
Learning BeagleBone Python Programming
Learning BeagleBone Python Programming
Ebook322 pages2 hours

Learning BeagleBone Python Programming

Rating: 0 out of 5 stars

()

Read preview

About this ebook

About This Book
  • 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
Who This Book Is For

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.

LanguageEnglish
Release dateJul 14, 2015
ISBN9781784390808
Learning BeagleBone Python Programming
Author

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

Related to Learning BeagleBone Python Programming

Related ebooks

Hardware For You

View More

Related articles

Reviews for Learning BeagleBone Python Programming

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

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

    Enjoying the preview?
    Page 1 of 1