Stewart Watkiss

Learn Electronics with Raspberry Pi

Physical Computing with Circuits, Sensors, Outputs, and Projects

2nd ed.
Stewart Watkiss
Redditch, UK
ISBN 978-1-4842-6347-1e-ISBN 978-1-4842-6348-8
© Stewart Watkiss 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY Plaza, New York, NY 10014. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For my wife Sarah.

Thank you for all the support you have given me whilst writing.

Introduction

Learning computer programming is fun in itself, but when the computer is connected to external sensors and outputs, then your computer programs can interact with the real world. This is known as physical computing, and it opens up the opportunity to create some fun projects.

I am a big fan of learning by doing. It’s much easier to learn when you get to make the projects rather than just reading about what other people have done. It’s even better when those projects are fun. This book covers simple projects that you can make at home to make games, control toys, create your own films, or just have fun.

The Raspberry Pi computer is great for learning physical computing thanks to special pins that provide access to ports on the processor itself. These 40 pins (or 26 on earlier versions) provide a simple way to extend computing into the physical world. The circuits in this book are adding sensors, outputs, and electronic circuits to a Raspberry Pi. With a little bit of programming, these can be made to do some pretty amazing things.

We will start with some simple circuits which can be controlled from Scratch, but then move up to Python and some more complicated circuits. By the end of the book, we will have covered enough so you can start designing your own circuits.

Most of the circuits can be created by plugging wires into a solderless breadboard, but there are tips on how to solder, which opens the possibilities further. It then goes on to explain how to design custom circuit boards and looking at how we can use some of the common Raspberry Pi add-on boards and HATs.

Updates to the Second Edition

The electronic theory that you will learn in this book is something that will stay consistent for many years, but there have been some changes to the implementation and interaction with the Raspberry Pi.

Since the first edition of the book, there have been several changes to the Raspberry Pi. These include new hardware including the new Raspberry Pi 4, software updates to Raspberry Pi OS and Scratch, and changes to some of the libraries used. The new edition has provided an opportunity to update those and bring the book up to date.

Reviewing the book also gave me an opportunity to think about other electronics that I’d like to include. I have therefore added an extra chapter looking at digital logic circuits. Although creating circuits out of the standard logic integrated circuits is less prevalent these days, it is an important step in understanding how digital computers work. I have added a related practical project in driving 7-segment LED displays which is related to this topic to provide a practical application.

Who Is This Book For?

This book is for anyone who wants to learn about electronics and have fun in the process. This book focuses on fun projects, so it’s great for older children and young adults. My eight-year-old son helped with some of the easier projects, so young children could have a go with adult help. While the fun aspect appeals to younger adults, there’s no maximum age for having fun, so this is just as useful for adults of any age who want to learn about electronic circuits and connecting to the Raspberry Pi.

You don’t need to know anything about electronic circuits before you start. Having a basic knowledge about computers and computer programming will be useful but is not required as it will be explained as we go. We’ll be using Scratch and Python as they are good programming languages for those learning programming, but the electronic circuits can be controlled using any programming language that can communicate with the GPIO ports.

Making the Circuits

As with many books, you can read this book from cover to cover, or you can jump straight to the project that you find most interesting. The book introduces new concepts and components in each chapter. The first few chapters start with simple circuits and work through to more complicated circuits. There is an explanation of each circuit as we go, so for the first few chapters, you will find it most useful to follow in order, making the circuits as you go. Most of the circuits in these first few chapters are based around low-cost components, which should be within the reach of most readers.

Most of the projects are contained within a single chapter, but some are based on concepts explained in later chapters and so are split between the chapters. The notes explain which chapter you will need to refer to for the rest of the project.

Some of the later projects do use more expensive components or add-on boards for the Raspberry Pi or are designed to interact with more expensive toys. Where possible boards have been chosen to keep costs as low as possible, you may want to just read about how the circuit works or look for the suggestions on how these can be adapted for use with cheaper components or items you may already own.

Creating the examples in this book should not be considered the end. I hope that the information in this book will provide the inspiration and knowledge for you to go on to learn more about electronics and design your own circuits.

After working through the projects, it’s useful to have a summary of the components so that you can refer to the book when designing your own circuits. To make it easier to refer to, I’ve added a summary of some of the components in the appendix along with some extra technical details which are useful when designing your own circuits.

Is Soldering Required?

When talking to teachers and students about electronic projects, I am often asked the question whether soldering is required. Unfortunately, I think that this is something that puts some people off from learning electronics, and I don’t think it should.

Firstly, there is a lot that can be learned through creating circuits that don’t need any soldering. Many of the projects in the first few chapters, and in some of the subsequent chapters, are designed to be made without any soldering. These are usually using solderless breadboards, but some can also be made using crocodile clips or with an inexpensive crimp tool. There are however some components that are not suitable for use on a breadboard or that need a small amount of soldering so that they can be used with a breadboard. In fact, many “breadboard-friendly” components may need headers to be soldered on to them first.

The second point I’d like to make is that soldering is not as hard, expensive, or dangerous as some people have been led to believe. Chapter 12 explains about soldering and will hopefully dispel some of the myths about soldering. If you are still uncertain, then see if you have a local maker club or Hackspace where you can speak to someone experienced in soldering.

Buying a Raspberry Pi

If you are reading this book, then there is a good chance that you have already got a Raspberry Pi. Since the Raspberry Pi was first released in 2012 there have been several different versions, some have had only minor changes, but one of the bigger changes was increasing the size of the GPIO connectors from 26 to 40. This was introduced with the Raspberry Pi B+ and the larger connector has been used on all new models since, including the Pi Zero and Raspberry Pi 2, 3 and 4 models. If you don’t have a Raspberry Pi or only have an original version with 26 pins on the connector then, I recommend buying a Raspberry Pi 3 or later with the 64-bit processor and built-in Wi-Fi and Bluetooth. You don’t need the extra processor power for the projects in this book, but it does make it possible to use the computer for other things. After all, nobody ever says, “This computer is too fast!” The exception is where low power is important such as when running on batteries, where the Pi Zero uses less power.

The official Raspberry Pi suppliers are listed on the Raspberry Pi website, but they are also widely stocked by various electronics and hobbyist suppliers so you shouldn’t have a problem finding a supplier.

Buying the Components

Obviously for a book about making electronic circuits to follow the instructions will need some electronic components. There is no single kit that will provide all the items required, which will depend upon which circuits you decide to make as well as the suggested variations. Details of the main components required for each project are listed in Appendix A. One thing that is worth stocking up on is a variety of different resistors; you may want to say buy either an E6 or E12 series resistor multipack (see Appendix C for an explanation of the resistor series).

Most of the components are common and can be bought from any good electronics retailer. There are several retailers that are specifically geared toward makers; in the United States, there are companies such as Adafruit and SparkFun, or in the United Kingdom, two popular suppliers are CPC Farnell and Cool Components. You may also want to look at Raspberry Pi retailers, many of whom have an increasing range of electronic sensors and other components. Pimoroni has created several add-on boards and HATs specifically for the Raspberry Pi, and for those fortunate to live near Cambridge, there is an official Raspberry Pi store. There are also international electronic retailers such as RS and Farnell or many smaller independent suppliers located around the world.

One thing about electronic components is that a device with an almost identical name may work differently. It may be possible to substitute a similar product, but where a specific component is required, I’ve tried to list the specific part number to help find the correct one. Watch out for codes that are almost the same but may have different electrical properties.

Installing Raspberry Pi OS

The official operating system for the Raspberry Pi is Raspberry Pi OS. It is based upon Debian Linux, but has been customized for the Raspberry Pi and comes with some additional software. The operating system needs to be loaded onto an SD card before it can run. The easiest way to install the Raspberry Pi OS is through the Raspberry Pi imager which is available at: https://www.raspberrypi.org/downloads/ . When running the imager, it defaults to a recommended version with only certain software installed. To follow the projects in this book you will need some additional software which is included in the full install which is under Raspberry Pi OS (other). Alternatively, the additional software can be installed through either the recommended software application or the command line apt program.

It is usually a good idea to update to the latest version. In the event of minor updates to the operating system then it is normally sufficient to run an upgrade to update to the latest version of the installed software. To do this, launch the terminal which is under the accessories category of the start menu. Once you are in the terminal shell, enter the following commands:
sudo apt update
sudo apt upgrade

If the version is much older, or it has been a long time since your last update then it is recommended that you download a new version of using the imager. The new image can then be installed onto the SD card.

Software Required

All the software required in this book is available for free and mostly available as open source software. This does include some libraries that have been created by others where links have been provided to the original location.

The source code used within the book can be typed in manually or downloaded from the Internet. For most short examples, I believe you can learn more through typing and experimentation, although downloads can be useful when trying to get a circuit working or when the amount of typing is enough to make your fingers ache. You can download the source code and media files from github at https://github.com/Apress/Learn-Electronics-with-Raspberry-Pi . When you download the file, it will be called Learn-Electronics-with-Raspberry-Pi-master.zip. This is quite lengthy so after unzipping you may want to rename it to something shorter. This can be unzipped using the following commands:
unzip Learn-Electronics-with-Raspberry-Pi-master.zip
mv Learn-Electronics-with-Raspberry-Pi-master learnelectronics

The first command unzips the file, and the second command renames the directory to learnelectronics. The files are then contained in the relevant subdirectories for each chapter.

You are free to use the software source code and circuit designs that I have provided in your own projects, but some of the accompanying files or suggested downloads may come under a different license.

Safety Information

All the circuits in this book are designed to run at a low voltage and as long as an appropriate power supply is used in terms of personal safety they will be safe to touch them, although you could damage sensitive components. To make these projects permanent then it may involve the use of power tools where the safety information related to the power tools need to be followed.

Some of the projects use bright LED lights which can be used to flash on and off. Some people may be sensitive to high-frequency flashing lights which in some circumstances may cause seizures. This is more likely if the flash rate is increased beyond that used in the supplied code. Please take this into consideration when modifying the source code especially if using the lights in a public space. You should also avoid looking directly into any bright light including the LED lights used.

More Electronics

The projects in this book should be considered a starting point when learning electronics and the Raspberry Pi. At the end of each chapter, there is a section which gives a summary of the key points in the chapter and provides suggestions on how the projects could be improved or ideas for related projects. These have been left as an exercise for the reader. I hope that this will result in future projects inspired from this book, and I look forward to seeing some on the Internet in the future.

Acknowledgments

My family have been very supportive during the writing of this book. Thank you to my wife Sarah for her support and especially to my children Amelia and Oliver who have been both a source of inspiration and enthusiastic testers of the games and activities.

I’d also like to thank the team behind the Raspberry Pi including the Raspberry Pi foundation and the community that has grown around it. The Raspberry Pi has reinvigorated my love of electronics making it possible to interact with hobby electronics projects in a way that I’d only dreamed about before. Raspberry Jams and community events have been a great way to meet the team behind the Raspberry Pi as well as other members of the community which has encouraged me to pursue this further.

My thanks those that have bought the previous version and particularly those that have left useful comments through reviews and social media.

There have been many other people have helped in the making of this book. Special thanks to the technical reviewer Sai Yamanoor who tested the projects, and all the team at Apress.

Table of Contents
Diode 357
TRIAC 359
Index 371
About the Author
Stewart Watkiss
../images/417997_2_En_BookFrontmatter_Figb_HTML.jpg
has been a keen electronics hobbyist and maker since the early 1990s. He has a master’s degree in electronic engineering from the University of Hull and a master’s degree in Computer Science from Georgia Institute of Technology.

His interest in electronics was revitalized thanks in part to the Raspberry Pi and Stewart has created several projects some of which have been featured on the Raspberry Pi blog and The MagPi magazine. He particularly enjoys creating physical computing projects and projects which involve his two children including their current garden railway project.

He has created numerous projects many of which are explained on his website www.penguintutor.com or on the PenguinTutor YouTube channel.

Stewart also volunteers as a STEM ambassador, going into local schools to help support teachers and teach programming and physical computing to teachers and children.

 
About the Technical Reviewer
Sai Yamanoor

is an embedded systems engineer working for an industrial gases company in Buffalo, NY. His interests, deeply rooted in DIY and Open Source Hardware, include developing gadgets that aid behavior modification. He has published two books with his brother, and in his spare time, he likes to contribute to build things that improve quality of life. You can find his project portfolio at http://saiyamanoor.com .

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.64.226