Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical Python Programming for IoT

You're reading from   Practical Python Programming for IoT Build advanced IoT projects using a Raspberry Pi 4, MQTT, RESTful APIs, WebSockets, and Python 3

Arrow left icon
Product type Paperback
Published in Nov 2020
Publisher Packt
ISBN-13 9781838982461
Length 516 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Gary Smart Gary Smart
Author Profile Icon Gary Smart
Gary Smart
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Section 1: Programming with Python and the Raspberry Pi
2. Setting Up your Development Environment FREE CHAPTER 3. Getting Started with Python and IoT 4. Networking with RESTful APIs and Web Sockets Using Flask 5. Networking with MQTT, Python, and the Mosquitto MQTT Broker 6. Section 2: Practical Electronics for Interacting with the Physical World
7. Connecting Your Raspberry Pi to the Physical World 8. Electronics 101 for the Software Engineer 9. Section 3: IoT Playground - Practical Examples to Interact with the Physical World
10. Turning Things On and Off 11. Lights, Indicators, and Displaying Information 12. Measuring Temperature, Humidity, and Light Levels 13. Movement with Servos, Motors, and Steppers 14. Measuring Distance and Detecting Movement 15. Advanced IoT Programming Concepts - Threads, AsyncIO, and Event Loops 16. IoT Visualization and Automation Platforms 17. Tying It All Together - An IoT Christmas Tree 18. Assessments 19. Other Books You May Enjoy

To get the most out of this book

The following headings provide an overview of the hardware, software, electronics, and peripherals you will require to successfully work through and complete the exercises found in this book.

  • Hardware and software: All of the exercises and code in this book were built and tested on the following hardware and software versions:
    • Raspberry Pi 4 Model B
    • Raspberry Pi OS Buster (with desktop and recommended software)
    • Python version 3.5

It will be my assumption that you will be using an equivalent setup; however, it is reasonable to expect that the code examples should work without modification on a Raspberry Pi 3 Model B or a different version of Raspbian OS or Raspberry Pi OS as long as your Python version is 3.5 or higher.

If you are not too sure about your Python version, don't worry. One of our first tasks in Chapter 1, Setting Up Your Development Environment, will be understanding Python on your Raspberry Pi and working out which versions are available.

  • Electronic Parts and Equipment: We will be using many electronic parts throughout this book. At the start of each chapter, I list the specific parts and quantities you will require for the chapter's examples. In addition to the parts listed, an electronic breadboard and a mixture of jumper/dupont cables will also be required.

For your convenience, a table cataloging all the electronic parts used throughout the book, the chapters where they are used, plus the minimum quantities you will require follows. If you are new to buying electronic parts, you'll also find tips to help get you started after the table:

Part Name Minimum Quantity Description / Notes Used in Chapter(s)
Red LED 2 * 5mm red LED. Different-colored LEDs can have different electrical characters. Most of our examples in the book will assume a red LED. 2, 3, 4, 5, 6, 7, 9, 12, 13
15Ω Resistor * Color bands (4-band resistor) will be brown, green, black, silver/gold 8
200Ω Resistor * Color bands (4-band resistor) will be red, black brown, silver/gold 2, 3, 4, 5, 6, 8, 9, 12, 13
1kΩ Resistor 2 * Color bands (4-band resistor) will be brown, brown, red, silver/gold 6, 7, 9, 8, 11
2kΩ Resistor 2 * Color bands (4-band resistor) will be red, black, red, silver/gold 6, 11
10kΩ Resistor 1 * Color bands (4-band resistor) will be brown, black, orange, silver/gold 9, 13
51kΩ Resistor 1 *

Color bands (4-band resistor) will be green, brown, orange, silver/gold

6
100kΩ Resistor 1 * Color bands (4-band resistor) will be brown, black, yellow, silver/gold 7, 8, 9
Momentary Push-Button Switch 1 To source a push-button switch that is breadboard friendly, try searching for a large tactile switch. 1, 6, 12
10kΩ Linear Potentiometers 2 Larger potentiometers that you can adjust with your fingers will be easier to work with in the book's examples than small potentiometers that will require a screwdriver to adjust. Make sure you have linear potentiometers (not logarithmic). 5, 6, 12
2N7000 MOSFET 1 * This is a logic-level compatible MOSFET transistor. 7, 8
FQP30N06L Power MOSFET 1 * Optional. When purchasing, make sure the part number ends with L, indicating that it is a logic-level compatible MOSFET (otherwise, it will not reliably work your Raspberry Pi). 7
PC817 Opto-Coupler 1 * Also known as an opto-isolator. 7
SDR-5VDC-SL-C Relay 1 These relays are very popular and easy to come by; however, they are not breadboard friendly. You will need to solder terminals or wires to them so you can plug them into your breadboard. 7
1N4001 Diode 1 * We will be using a diode in the role of a fly-back suppression diode to protect other electrical components from voltage spikes. 7, 8
Size R130  5-volt DC Hobby Motor 2 Size R130 is just a suggestion. What we need are 5-volt compatible DC motors with a stall current (ideally) less than 800 mA. While these motors are easy to come by on auction sites, their current and operating currents can be poorly documented so it can be a gamble as to what you get. Chapter 7Turning Things On and Off, will take you through an exercise to measure the operating currents of your motors. 7, 10
RGBLED, Common Cathode type 1 * This is an LED that is capable of making different colors. 8
Passive Buzzer 1 A passive buzzer that will work with 5 volts. 8
SSD1306 OLED Display 1 This is a small monochrome pixel-based display. 8
APA102 RGBLED Strip 1 This is a strip of addressable APA102 RGBLEDs. You will just need the LED strip, not a power supply or a remote control for our exercises. Be careful to make sure it is the APA102 LEDs that you are purchasing as there are different (and incompatible) types of addressable LEDs available. 8, 14
DHT11 or DHT22 Temperature/Humidity Sensor 1 The DHT11 and DHT22 are interchangeable. The DHT22 is slightly more expensive but offers more accuracy and can measure sub-zero temperatures. 9, 13
LDR 1 * Light-Dependent-Resistor 9
MG90S Hobby Servo 1 This is a suggestion. Any 5-volt hobby servo with 3 wires (+, GND, Signal) should be suitable. 10, 14
L293D H-Bridge IC 1 * Make sure the part number you purchase ends in D, meaning the IC includes embedded fly-back suppression diodes. 10
28BYJ-48 Stepper Motor 1 Make sure you purchase the 5-volt stepper motor variety, with a 1:64 gearing ratio. 10
HC-SR501 PIR Sensor 1 A PIR sensor detects movement. It works on heat, so it can detect the presence of people and animals. 11
HC-SR04 Ultrasonic Distance Sensor 1 An Ultrasonic Distance Sensor estimates distances using sound waves. 11
A3144 Hall-Effect Sensor 1 * This is a non-latching switch-type Hall-effect sensor that turns on in the presence of a magnetic field. 11
AH3503 Hall-Effect Sensor 1 * This is a ratiometric-type Hall-effect sensor that can detect how close (relatively) it is to a magnetic field. 11
Magnet 1 A small magnet is required for use with the Hall-effect sensors. 11
ADS1115 Analog-to-Digital (ADC) Converter Breakout Module 1 This module will allow us to interface analog components with our Raspberry Pi. 5, 9, 12
Logic Level Shifter/Converter Breakout Module 1 This module will allow us to interface 5-volt electrical components with our Raspberry Pi. Search for a Logic Level Shifter/Converter Breakout Module and look for a bi-directional (preferred) module when 4 or 8 channels. 6, 8, 14
Breadboard 1 All our electronic examples will be built on a breadboard. I recommend purchasing two full-size breadboards and joining them together – more breadboard working areas will make building circuits easier. 2 - 14
Dupont / Jumper Cables 3 sets * These cables are used to wire components together on your breadboard. I recommend purchasing sets of male-to-male, male-to-female, and female-to-female types. 2 - 14
Raspberry Pi GPIO Breadboard Breakout 1 This is optional, however, it will make it easier to interface your Raspberry Pi GPIO pins with your breadboard. 2 - 14
Digital Multimeter 1 As a guide, a digital multimeter in the price range of $30-50 USD should be more than suitable. Avoid the very-low and cheapest multi-meters. 6, 7
External Power Supply 2 Some of the circuits in this book will require more power than we can expect our Raspberry Pi to provide. As a minimum source, a 3.3/5-volt breadboard-compatible power supply capable of outputting 1 amp will be suitable. You might also like to research lab power supplies as a more capable and general alternative. 7, 8, 9, 10, 14
Soldering Iron and Solder 1 There will be cases where you need to solder wires and terminals onto components – for example, it is highly likely that you will need to solder terminal legs on to the ADS1115 and logic level converter/shifter modules that you purchase. You will also need to solder terminals or wires onto your SDR-5VDC-SL-C relay so you can plug it into your breadboard.

*  Spares recommended. These are components that can be damaged if incorrectly connected or powered or can physically break with use (for example, legs breaking off).

These parts have been selected due to their low price points, and their general availability on websites such as eBay.com, Bangood.com, AliExpress.com, and electronics retailers.

Before making your purchases, please consider the following:

  • The Minimum Quantity column is what you will need for the exercises in this book, however, it's highly recommended that you purchase spares, especially of LEDs, resistors, and MOSFETs as these components are easily damaged.
  • You will find that many components will need to be purchased in bulk lots.
  • Search around for Electronic Component Starter Kits and compare what they include against the parts listed in the table. You may be able to purchase many of the parts together in a single (and discounted) transaction.
  • The many available plug-and-play Sensor Module Starter Kits that are available will, for the most part, not be compatible with the circuit and code exercises presented throughout this book. The depth of our electronic and code examples means we will need to work with core electrical components. After completing this book, however, you will be in a great position to understand how these plug-and-play sensor modules are built and work!

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

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 $19.99/month. Cancel anytime
Banner background image