Book Image

Python Programming with Raspberry Pi

By : Sai Yamanoor, Srihari Yamanoor
Book Image

Python Programming with Raspberry Pi

By: Sai Yamanoor, Srihari Yamanoor

Overview of this book

Raspberry Pi Zero is a super-small and super-affordable product from Raspberry Pi that is packed with a plethora of features and has grabbed the notice of programmers, especially those who use Python. This step-by-step guide will get you developing practical applications in Python using a Raspberry Pi Zero. It will become a valuable resource as you learn the essential details of interfacing sensors and actuators to a Raspberry Pi, as well as acquiring and displaying data. You will get started by writing a Python program that blinks an LED at 1-second intervals. Then you will learn to write simple logic to execute tasks based upon sensor data (for example, to control a motor) and retrieve data from the web (such as to check e-mails to provide a visual alert). Finally, you will learn to build a home automation system with Python where different appliances are controlled using the Raspberry Pi. The examples discussed in each chapter of this book culminate in a project that help improve the quality of people’s lives.
Table of Contents (17 chapters)
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Let's get started!


In the first chapter, we will learn about the Raspberry Pi Zero, set things up for learning Python with this book, and write our first piece of code in Python.

Things needed for this book

The following items are needed for this book. The sources provided are just a suggestion. The reader is welcome to buy them from an equivalent alternative source:

Name

Link

Cost (in USD)

Raspberry Pi Zero (v1.3 or higher)

(The purchase of the Raspberry Pi would be discussed separately)

$5.00

USB hub

http://amzn.com/B003M0NURK

$7.00 approx

USB OTG cable

https://www.adafruit.com/products/1099

$2.50

Micro HDMI to HDMI adapter cable

https://www.adafruit.com/products/1358

$6.95

USB Wi-Fi adapter

http://amzn.com/B00LWE14TO

$9.45

Micro USB power supply

http://amzn.com/B00DZLSEVI

$3.50

Electronics starter kit (or similar)

http://amzn.com/B00IT6AYJO

$25.00

2x20 headers

https://www.adafruit.com/products/2822

$0.95

NOOBS micro SD card or a blank 8 GB micro SD card

http://amzn.com/B00ENPQ1GK

$13.00

Raspberry Pi camera module (optional)

http://a.co/6qWiJe6

$25.00

Raspberry Pi camera adapter (optional)

https://www.adafruit.com/product/3170

$5.95

 

The other items needed for this include a USB mouse, USB keyboard, and a monitor with the HDMI output or DVI output. We will also need an HDMI cable (or DVI to HDMI cable if the monitor has an DVI output). Some vendors such as the Pi Hut sell the Raspberry Pi Zero accessories as a kit (for example, https://thepihut.com/collections/raspberry-pi-accessories/products/raspberry-pi-zero-essential-kit).

Note

Apart from the components mentioned in this section, we will also discuss certain features of the Raspberry Pi Zero and Python programming using additional components such as sensors and GPIO expanders. These components are optional but definitely useful while learning the different aspects of Python programming.

The electronics starter kit mentioned in the bill of materials is just an example. Feel free to order any beginners electronics kit (that contains a similar mix of electronic components).

Buying the Raspberry Pi Zero

The Raspberry Pi Zero is sold by distributors such as the Newark element14, Pi Hut, and Adafruit. At the time of writing this book, we encountered difficulties in buying a Raspberry Pi Zero. We recommend monitoring websites such as www.whereismypizero.com to find out when the Raspberry Pi Zero becomes available. We believe that it is rare to locate the Pi Zero because of its popularity. We are not aware if there might be an abundant stock of the Raspberry Pi Zero in the future. The examples discussed in this book are also compatible with the other flavors of the Raspberry Pi (for example, Raspberry Pi 3).

Pi Zero availability information provided by www.whereismypizero.com

While purchasing the Raspberry Pi Zero, make sure that the board version is 1.3 or higher. The board version is printed on the backside of the board (the example of this is shown in the following picture). Verify that the board version using the seller's product description before purchase:

Raspberry Pi board version