Getting Started with Python and Raspberry Pi
eBook - ePub

Getting Started with Python and Raspberry Pi

Dan Nixon

Share book
  1. 200 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Getting Started with Python and Raspberry Pi

Dan Nixon

Book details
Book preview
Table of contents
Citations

About This Book

Learn to design and implement reliable Python applications on the Raspberry Pi using a range of external libraries, the Raspberry Pis GPIO port, and the camera moduleAbout This Book• Learn the fundamentals of Python scripting and application programming• Design user-friendly command-line and graphical user interfaces• A step-by-step guide to learning Python programming with the PiWho This Book Is ForThis book is designed for those who are unfamiliar with the art of Python development and want to get to know their way round the language and the many additional libraries that allow you to get a full application up and running in no time.What You Will Learn• Fundamentals of Python applications• Designing applications for multi-threading• Interacting with electronics and physical devices• Debugging applications when they go wrong• Packaging and installing Python modules• User interface design using Qt• Building easy to use command-line interfaces• Connecting applications to the InternetIn DetailThe Raspberry Pi is one of the smallest and most affordable single board computers that has taken over the world of hobby electronics and programming, and the Python programming language makes this the perfect platform to start coding with.The book will start with a brief introduction to Raspberry Pi and Python. We will direct you to the official documentation that helps you set up your Raspberry Pi with the necessary equipment such as the monitor, keyboard, mouse, power supply, and so on. It will then dive right into the basics of Python programming. Later, it will focus on other Python tasks, for instance, interfacing with hardware, GUI programming, and more. Once you get well versed with the basic programming, the book will then teach you to develop Python/Raspberry Pi applications.By the end of this book, you will be able to develop Raspberry Pi applications with Python and will have good understanding of Python programming for Raspberry Pi.Style and approachAn easy-to-follow introduction to Python scripting and application development through clear conceptual explanations backed up by real-world examples on the Raspberry Pi.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Getting Started with Python and Raspberry Pi an online PDF/ePUB?
Yes, you can access Getting Started with Python and Raspberry Pi by Dan Nixon in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Lenguajes de programación. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785285837

Getting Started with Python and Raspberry Pi


Table of Contents

Getting Started with Python and Raspberry Pi
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
Downloading the example code
Errata
Piracy
Questions
1. Your First Steps with Python on the Pi
Installing and setting up Raspbian
Writing to the SD card
Windows
Linux and Mac
Booting the Pi for the first time
The Python development tools
Python 2 versus Python 3
Running some simple Python scripts
Summary
2. Understanding Control Flow and Data Types
Data in Python
Numerical types
Operations on numerical types
String manipulation
String functions
String formatting
String templates
Control flow operators
Using functions
Summary
3. Working with Data Structures and I/O
Data structures
Lists
Creating lists
List operations
Dictionaries
Creating dictionaries
Dictionary operations
Sets
Set operations
Frozen sets
Tuples
Input/output
The os.path module
Reading and writing files
Summary
4. Understanding Object-oriented Programming and Threading
Object-oriented programming
Classes in Python
Operation.py
Calculator.py
Using the module
Inheritance
Threading
Locks
Summary
5. Packaging Code with setuptools
Using packages in your Python code
Importing modules
Installing modules manually
Installing modules using pip
Installing modules using apt
Packaging your own Python modules
Packaging a library
Adding an entry point
Summary
6. Accessing the GPIO Pins
Digital electronics
The GPIO library
Single LED output
PWM output
Multiple outputs
Basic switch
Switch using interrupt
Universal Asynchronous Receiver/Transmitter (UART)
Setting up the serial port
Using pySerial
Additional libraries
Summary
7. Using the Camera Module
Setting up the camera module
Installing and testing the Python library
Writing applications for the camera
A time lapse recorder
A point-and-shoot camera
An image effect randomizer
Summary
8. Extracting Data from the Internet
Using urllib2 to download data
Parsing JSON APIs
Parsing XML APIs
The DOM method
The SAX method
Parsing a web page using BeautifulSoup
Summary
9. Creating Command-line Interfaces
Unit conversion application
Command-line interface
Summary
10. Debugging Applications with PDB and Log Files
The Python debugger
Writing log files
Unit testing
Summary
11. Designing Your GUI with Qt
Setting up the codebase
Building the UI with Qt Designer
Writing the UI code
Launching the UI
Packaging the code
Summary
Index

Getting Started with Python and Raspberry Pi

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: September 2015
Production reference: 1210915
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-159-0
www.packtpub.com

Credits

Author
Dan Nixon
Reviewers
Ankit Aggarwal
Neil Broers
Yash Gajera
Bhavyanshu Parasher
David Whale
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Indrajit Das
Content Development Editor
Zeeyan Pinheiro
Technical Editor
Namrata Patil
Copy Editor
Alpha Singh
Project Coordinator
Suzanne Coutinho
Proofreader
Safis Editing
Indexer
Tejal Soni
Graphics
Jason Monteiro
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph

About the Author

Dan Nixon is a software and electronics engineer living in the north of England. He has past experience of creating software for data analysis, process control, and business intelligence applications. In most of these projects, Python was one of the main languages used.
Dan previously authored another book on the uses of the Raspberry Pi, called Raspberry Pi Blueprints, and has worked on many personal projects that use both Python and the Raspberry Pi.

Table of contents