Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Python Programming for Arduino

You're reading from   Python Programming for Arduino Develop practical Internet of Things prototypes and applications with Arduino and Python

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781783285938
Length 400 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Pratik Desai Pratik Desai
Author Profile Icon Pratik Desai
Pratik Desai
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Python Programming for Arduino
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Python and Arduino FREE CHAPTER 2. Working with the Firmata Protocol and the pySerial Library 3. The First Project – Motion-triggered LEDs 4. Diving into Python-Arduino Prototyping 5. Working with the Python GUI 6. Storing and Plotting Arduino Data 7. The Midterm Project – a Portable DIY Thermostat 8. Introduction to Arduino Networking 9. Arduino and the Internet of Things 10. The Final Project – a Remote Home Monitoring System 11. Tweet-a-PowerStrip Index

Preface

In the era of the Internet of Things (IoT), it has become very important to rapidly develop and test prototypes of your hardware products while also augmenting them using software features. The Arduino movement has been the front-runner in this hardware revolution, and through its simple board designs it has made it convenient for anyone to develop DIY hardware projects. The great amount of support that is available through the open source community has made the difficulties that are associated with the development of a hardware prototype a thing of the past. On the software front, Python has been the crown jewel of the open source software community for a significant amount of time. Python is supported by a huge amount of libraries to develop various features, such as graphical user interfaces, plots, messaging, and cloud applications.

This book tries to bring you the best of both hardware and software worlds to help you develop exciting projects using Arduino and Python. The main goal of the book is to assist the reader to solve the difficult problem of interfacing Arduino hardware with Python libraries. Meanwhile, as a secondary goal, the book also provides you with exercises and projects that can be used as blueprints for your future IoT projects.

The book has been designed in such a way that every successive chapter has increasing complexity in terms of material that is covered and also more practical value. The book has three conceptual sections (getting started, implementing Python features, and network connectivity) and each section concludes with a practical project that integrates the concepts that you learned in that section.

The theoretical concepts and exercises covered in the book are meant to give you hands-on experience with Python-Arduino programming, while the projects are designed to teach you hardware prototyping methodologies for your future projects. However, you will still need extensive expertise in each domain to develop a commercial product. In the end, I hope to provide you with sufficient knowledge to jump-start your journey in this novel domain of the IoT.

What this book covers

Chapter 1, Getting Started with Python and Arduino, introduces the fundamentals of the Arduino and Python platforms. It also provides comprehensive installation and configuration steps to set up the necessary software tools.

Chapter 2, Working with the Firmata Protocol and the pySerial Library, discusses the interfacing of the Arduino hardware with the Python program by explaining the Firmata protocol and the serial interfacing library.

Chapter 3, The First Project – Motion-triggered LEDs, provides comprehensive guidelines to create your first Python-Arduino project, which controls different LEDs according to the detected motion.

Chapter 4, Diving into Python-Arduino Prototyping, takes you beyond the basic prototyping that we performed in the previous project and provides an in-depth description of prototyping methods, with appropriate examples.

Chapter 5, Working with the Python GUI, begins our two-chapter journey into developing graphical interfaces using Python. The chapter introduces the Tkinter library, which provides the graphical frontend for the Arduino hardware.

Chapter 6, Storing and Plotting Arduino Data, covers Python libraries, CSV and matplotlib that are used to store and plot the sensor data respectively.

Chapter 7, The Midterm Project – a Portable DIY Thermostat, contains a practical and deployable project that utilizes the material that we covered in previous chapters such as serial interfacing, a graphical frontend, and a plot of the sensor data.

Chapter 8, Introduction to Arduino Networking, introduces computer networking for Arduino while utilizing various protocols to establish Ethernet communication between the Python program and Arduino. This chapter also explores a messaging protocol called MQTT, with basic examples. This protocol is specifically designed for resource-constrained hardware devices such as Arduino.

Chapter 9, Arduino and the Internet of Things, discusses the domain of the IoT while providing step-by-step guidelines to develop cloud-based IoT applications.

Chapter 10, The Final Project – a Remote Home Monitoring System, teaches a design methodology for the hardware product, followed by a comprehensive project that interfaces the cloud platform with Arduino and Python.

Chapter 11, Tweet-a-PowerStrip, contains another IoT project that is based on everything that we learned in the book. The project explores a unique approach to integrate a social network, Twitter, with the Python-Arduino application.

What you need for this book

To begin with, you will just need a computer with one of the supported operating systems, Windows, Mac OS X, or Linux. The book requires various additional hardware components and software tools to implement programming exercises and projects. A list of required hardware components and locations to obtain these components are included in each chapter.

In terms of software, the book itself provides step-by-step guidelines to install and configure all the necessary software packages and dependent libraries that are utilized throughout the book. Note that the exercises and projects included in the book are designed for Python 2.7 and they have not been tested against Python 3+.

Who this book is for

If you are a student, a hobbyist, a developer, or a designer with little or no programming and hardware prototyping experience and you want to develop IoT applications, then this book is for you.

If you are a software developer and interested in gaining experience with hardware domain, this book will help you to get started. If you are a hardware engineer who wants to learn advance software features, this book can help you to begin with.

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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "While assigning the value to the weight variable, we didn't specify the data type, but the Python interpreter assigned it as an integer type, int."

A block of code is set as follows:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Any command-line input or output is written as follows:

$ sudo easy_install pip

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: "In the System window, click on the Advanced system settings in the left navigation bar to open a window called System Properties."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear 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 , 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 to help you to get the most from your purchase.

Downloading the example code

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.

Downloading the color images of this book

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: http://www.packtpub.com/sites/default/files/downloads/5938OS_ColoredImages.pdf.

Errata

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

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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime
Visually different images