Book Image

Mastering IOT

By : Colin Dow, Perry Lea
Book Image

Mastering IOT

By: Colin Dow, Perry Lea

Overview of this book

The Internet of Things (IoT) is the fastest growing technology market. Industries are embracing IoT technologies to improve operational expenses, product life, and people's well-being. We’ll begin our journey with an introduction to Raspberry Pi and quickly jump right into Python programming. We’ll learn all concepts through multiple projects, and then reinforce our learnings by creating an IoT robot car. We’ll examine modern sensor systems and focus on what their power and functionality can bring to our system. We’ll also gain insight into cloud and fog architectures, including the OpenFog standards. The Learning Path will conclude by discussing three forms of prevalent attacks and ways to improve the security of our IoT infrastructure. By the end of this Learning Path, we will have traversed the entire spectrum of technologies needed to build a successful IoT system, and will have the confidence to build, secure, and monitor our IoT infrastructure. This Learning Path includes content from the following Packt products: Internet of Things Programming Projects by Colin Dow Internet of Things for Architects by Perry Lea
Table of Contents (34 chapters)
Title Page
Copyright
About Packt
Contributors
Preface
Free Chapter
1
The IoT Story
Index

Reading the state of a button


Button, from the GPIO Zero library, gives us an easy way to interact with a typical button connected to the GPIO. We will cover the following in this section:

  • Using GPIO Zero with a button
  • Using the Sense HAT emulator and GPIO Zero button together
  • Toggling an LED with a long button press

Using GPIO Zero with a button

Connecting a push-button is relatively easy with the GPIO. The following is the connection diagram showing the process:

Connect the push-button so that one end is connected to ground using a jumper. Connect the other end to GPIO 4 on the Raspberry Pi.

In Thonny, create a new file and call it button_press.py. Then, type following into the file and run it:

from gpiozero import Button
from time import sleep

button = Button(4)
while True:
    if button.is_pressed:
     print("The Button on GPIO 4 has been pressed")
     sleep(1)

You should now see the message "The Button on GPIO 4 has been pressed" in the shell whenever you push the button. The code will run...