Book Image

Getting Started with Python for the Internet of Things

By : Tim Cox, Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. Diwakar Vaish
Book Image

Getting Started with Python for the Internet of Things

By: Tim Cox, Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. Diwakar Vaish

Overview of this book

This Learning Path takes you on a journey in the world of robotics and teaches you all that you can achieve with Raspberry Pi and Python. It teaches you to harness the power of Python with the Raspberry Pi 3 and the Raspberry Pi zero to build superlative automation systems that can transform your business. You will learn to create text classifiers, predict sentiment in words, and develop applications with the Tkinter library. Things will get more interesting when you build a human face detection and recognition system and a home automation system in Python, where different appliances are controlled using the Raspberry Pi. With such diverse robotics projects, you'll grasp the basics of robotics and its functions, and understand the integration of robotics with the IoT environment. By the end of this Learning Path, you will have covered everything from configuring a robotic controller, to creating a self-driven robotic vehicle using Python. • Raspberry Pi 3 Cookbook for Python Programmers - Third Edition by Tim Cox, Dr. Steven Lawrence Fernandes • Python Programming with Raspberry Pi by Sai Yamanoor, Srihari Yamanoor • Python Robotics Projects by Prof. Diwakar Vaish
Table of Contents (37 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

Playing with voltage


So far so good! But did you notice one thing? We have been using Raspberry Pi as a switch—simply switching the various components on and off. But what if we need to vary the intensity of the LEDs that we have just programmed? Is it possible? The answer is no. But we can still get it done somehow!

Let's see how. Computers work in binary which means that they can represent either 0 or 1. This is because of the fact that the primary computing unit in any system is based on a transistor which can either be on or off representing 0 or 1. So, if we see this technically, computers are only capable of switching due to the binary architecture. However, there is a trick. This trick is called pulse width modulation (PWM).

Now, before I explain any of it in detail, let's go ahead plug in an LED on pin number 18, then copy this code into Raspberry Pi and run it:

import RPi.GPIO as GPIO
import time                             
GPIO.setmode(GPIO.BCM)       
GPIO.setup(18,GPIO.OUT)   ...