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

Hello LED


We will jump right into the code:

  1. Create a new file in Thonny, and call it Hello LED.py or something similar.
  2. Type in the following code and run it:
from gpiozero import LED

led = LED(18)
led.blink(1,1,10)

Blink LED using gpiozero

If we wired up our circuit and typed in our code correctly, we should see our LED blink for 10 seconds in 1 second intervals. The blink function in the gpiozero LED object allows us to set on_time (the length of time in seconds that the LED stays on), off_time (the length of time in seconds that the LED is turned off for), n or the number of times the LED blinks, and background (set to True to allow other code to run while the LED is flashing).

The blink function call with its default parameters looks like this:

blink(on_time=1, off_time=1, n=none, background=True)

Without parameters passed into the function, the LED will blink non-stop at 1 second intervals. Notice how we do not need to import the time library like we did when we used the RPi.GPIO package for...