Book Image

Raspberry Pi Zero Cookbook

Book Image

Raspberry Pi Zero Cookbook

Overview of this book

The Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running. In this book, you will learn how to prepare your own circuits rather than buying the expensive add–ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.
Table of Contents (17 chapters)
Raspberry Pi Zero Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Creating our first Python program and running loops


Loops are one the most common programming functions, and very useful when doing things such as collecting readings over and over and reading through log files or sensor data. In this recipe, we will look at the different ways in which Python handles loops.

Getting ready

We're going to work with Raspbian's built-in Geany IDE:

  1. Create a new Python program with File | New (With template) | main.py. Then, save it as rpz_log_analysis.py. We will use add to this program throughout the chapter.

  2. If you haven't been logging your own temperature data or Raspberry Pi restarts, it is included in the source code for this book, which you can pull with Git. Make a note of where rpz_temp.log and rpz_startup.log are (hint: use find!), or copy them into the /var/logs/ directory of your Raspberry Pi Zero.

  3. If you want to start with the completed code for this recipe, it is named rpz_log_analysis_loops.py in the /ch4/ directory.

How to do it...

  1. Replace the default...