Learning BeagleBone Python Programming - Sample Chapter
Learning BeagleBone Python Programming - Sample Chapter
$ 39.99 US
26.99 UK
"Community
Experience
Distilled"
Alexander Hiam
Learning BeagleBone
Python Programming
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
Learning BeagleBone
Python Programming
Unleash the potential of BeagleBone using Python
Alexander Hiam
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.
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.
Preface
Before We Begin
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:
Some additional hardware and tools that you will need if you want to
duplicate the examples given throughout the book, and where you can
buy them
An overview of BeagleBone
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.
[1]
Before We Begin
[2]
Chapter 1
Analog-to-digital converter
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.
[3]
Before We Begin
[4]
Chapter 1
[5]
Before We Begin
Inter-Integrated Circuit
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.
SparkFun: https://www.sparkfun.com/
Digi-Key: http://www.digikey.com/
Mouser: http://www.mouser.com/
Chapter 1
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:
Breadboard: http://www.adafruit.com/products/239
That should provide enough breadboard space and jumper wires to assemble most,
if not all, of the demo circuits in this book.
[7]
Before We Begin
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.
[8]
Chapter 1
Board comparison
There are a number of low-cost single-board GNU/Linux computers on the market
these days, so let's take a look at how the BeagleBone Black stacks up against a
couple of its most popular competitors.
BeagleBone Black
Intel Edison
Raspberry Pi 2 B
CPU
1 GHz single-core
ARM Cortex-A8
Flash
4 GB eMMC,
expandable with uSD
4 GB eMMC
uSD card
RAM
512 MB
1 GB
1 GB
Video
microHDMI
N/A
HDMI, Composite
Network
Dual-band a/b/g/n
Wi-Fi, Bluetooth 4.0
GPIO pins
65
20
40
ADC channels
N/A
PWM channels
UARTs
SPI ports
I2C ports
Coprocessor
N/A
Price (USD)
$49
$49.95
$39.95
The BeagleBone Black offers great performance and far more hardware expansion
capabilities at about the same cost as the Edison and Raspberry Pi 2 B. That
combined with its active open source community makes it a great choice for
a huge variety of projects.
Another important feature of the BeagleBone is the two built-in PRU (programmable
real-time unit) microcontrollers. These are built right into the AM335x CPU and are
on the ARM interconnect, so they can share memory with the ARM processor as
well as provide direct access to the peripherals. This means high-speed, real-time
tasks can be executed on the PRUs asynchronously without any interruption from
the Linux kernel. With growing kernel driver support and documentation to compile
and load firmware to PRUs, and for communicating with the code running on them
from GNU/Linux user space, they really set the BeagleBone apart from much of its
competition. The PRUs are outside the scope of this book, but there are plenty of
tutorials and examples to be found on the Web.
[9]
Before We Begin
Helpful resources
One of the BeagleBone Black's strong suits is the large community surrounding it.
The official site at http://beagleboard.org/ has lots of great information.
The main source for help with BeagleBone-related issues is the mailing list at
https://groups.google.com/forum/#!forum/beagleboard.
There are also plenty of helpful people on the #beagle IRC channel at
http://beagleboard.org/Community/Live%20Chat.
There are also many resources online that can help fill the gaps this book leaves on the
electrical side. For instance, the Element14 community at http://www.element14.
com/community/welcome and the EEVBlog at http://www.eevblog.com/, both
contain a wealth of great material, as well as very active electronics forums.
Summary
You should now have a better understanding of what the BeagleBone has to offer,
and maybe even some insight into the types of devices we will be interfacing with
in later chapters.
In the next chapter, you will be plugging in your BeagleBone Black and learning how
to log in and get everything we need installed and up to date.
[ 10 ]
www.PacktPub.com
Stay Connected: