Getting Started with Python for the Internet of Things

Book Description

Build clever, collaborative, and powerful automation systems with the Raspberry Pi and Python.

Key Features

  • Create your own Pi-Rover or Pi-Hexipod robots
  • Develop practical applications in Python using Raspberry Pi
  • Build your own Jarvis, a highly advanced computerized AI

Book Description

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

What you will learn

  • Build text classifiers and predict sentiment in words with the Tkinter library
  • Develop human face detection and recognition systems
  • Create a neural network module for optical character recognition
  • Build a mobile robot using the Raspberry Pi as a controller
  • Understand how to interface sensors, actuators, and LED displays work
  • Apply machine learning techniques to your models
  • Interface your robots with Bluetooth

Who this book is for

This Learning Path is specially designed for Python developers who want to take their skills to the next level by creating robots that can enhance people's lives. Familiarity with Python and electronics will aid understanding the concepts in this Learning Path.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Getting Started with Python for the Internet of Things
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the authors
    2. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started with a Raspberry Pi 3 Computer
    1. Introduction
      1. Introducing Raspberry Pi
      2. What's with the name?
      3. Why Python?
        1. Python 2 and Python 3
        2. Which version of Python should you use?
        3. The Raspberry Pi family – a brief history of Pi
        4. Which Pi to choose?
    2. Connecting to Raspberry Pi
      1. Getting ready
      2. How to do it...
      3. There's more...
        1. Secondary hardware connections
    3. Using NOOBS to set up your Raspberry Pi SD card
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Changing the default user password
        2. Ensuring that you shut down safely
        3. Preparing an SD card manually
        4. Expanding the system to fit in your SD card
        5. Accessing the RECOVERY/BOOT partition
        6. Using the tools to back up your SD card in case of failure
    4. Networking and connecting your Raspberry Pi to the internet via an Ethernet port, using a CAT6 Ethernet cable
      1. Getting ready
      2. How to do it...
      3. There's more...
    5. Using built-in Wi-Fi and Bluetooth on Raspberry Pi
      1. Getting ready
      2. How to do it...
        1. Connecting to your Wi-Fi network
        2. Connecting to Bluetooth devices
    6. Configuring your network manually
      1. Getting ready
      2. How to do it...
      3. There's more...
    7. Networking directly to a laptop or computer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Direct network link
      5. See also
    8. Networking and connecting your Raspberry Pi to the internet via a USB Wi-Fi dongle
      1. Getting ready
      2. How to do it...
      3. There's more...
        1. Using USB wired network adapters
    9. Connecting to the internet through a proxy server
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Connecting remotely to Raspberry Pi over the network using VNC
      1. Getting ready
      2. How to do it...
      3. There's more...
    11. Connecting remotely to Raspberry Pi over the network using SSH (and X11 forwarding)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Running multiple programs with X11 forwarding
        2. Running as a desktop with X11 forwarding
        3. Running Pygame and Tkinter with X11 forwarding
    12. Sharing the home folder of Raspberry Pi with SMB
      1. Getting ready
      2. How to do it...
    13. Keeping Raspberry Pi up to date
      1. Getting ready
      2. How to do it...
      3. There's more...
  7. Dividing Text Data and Building Text Classifiers
    1. Introduction
    2. Building a text classifier
      1. How to do it...
      2. How it works...
      3. See also
    3. Pre-processing data using tokenization
      1. How to do it...
    4. Stemming text data
      1. How to do it...
    5. Dividing text using chunking
      1. How to do it...
    6. Building a bag-of-words model
      1. How to do it...
    7. Applications of text classifiers
  8. Using Python for Automation and Productivity
    1. Introduction
    2. Using Tkinter to create graphical user interfaces
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating a graphical application – Start menu
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Displaying photo information in an application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Organizing your photos automatically
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Predicting Sentiments in Words
    1. Building a Naive Bayes classifier
      1. How to do it...
      2. See also
    2. Logistic regression classifier
      1. How to do it...
    3. Splitting the dataset for training and testing
      1. How to do it...
    4. Evaluating the accuracy using cross-validation
      1. How to do it...
    5. Analyzing the sentiment of a sentence
      1. How to do it...
    6. Identifying patterns in text using topic modeling
      1. How to do it...
    7. Applications of sentiment analysis
  10. Detecting Edges and Contours in Images
    1. Introduction
    2. Loading, displaying, and saving images
      1. How to do it...
    3. Image flipping
      1. How to do it...
    4. Image scaling
      1. How to do it...
    5. Erosion and dilation
      1. How to do it...
    6. Image segmentation
      1. How to do it...
    7. Blurring and sharpening images
      1. How to do it...
    8. Detecting edges in images
      1. How to do it...
      2. How it works...
      3. See also
    9. Histogram equalization
      1. How to do it…
    10. Detecting corners in images
      1. How to do it...
  11. Building Face Detector and Face Recognition Applications
    1. Introduction
    2. Building a face detector application
      1. How to do it...
    3. Building a face recognition application
      1. How to do it...
      2. How it works...
      3. See also
    4. Applications of a face recognition system
  12. Using Python to Drive Hardware
    1. Introduction
    2. Controlling an LED
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Controlling the GPIO current
    3. Responding to a button
      1. Getting ready
        1. Trying a speaker or headphone with Raspberry Pi
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Safe voltages
        2. Pull-up and pull-down resistor circuits
        3. Protection resistors
    4. A controlled shutdown button
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Resetting and rebooting Raspberry Pi
        2. Adding extra functions
    5. The GPIO keypad input
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Generating other key combinations
        2. Emulating mouse events
    6. Multiplexed color LEDs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Hardware multiplexing
        2. Displaying random patterns
        3. Mixing multiple colors
    7. Writing messages using persistence of vision
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Sensing and Displaying Real-World Data
    1. Introduction
    2. Using devices with the I2C bus
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using multiple I2C devices
        2. I2C bus and level shifting
        3. Using just the PCF8591 chip or adding alternative sensors
    3. Reading analog data using an analog-to-digital converter
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Gathering analog data without hardware
    4. Logging and plotting data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Plotting live data
        2. Scaling and calibrating data
    5. Extending the Raspberry Pi GPIO with an I/O expander
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. I/O expander voltages and limits
        2. Using your own I/O expander module
        3. Directly controlling an LCD alphanumeric display
    6. Capturing data in an SQLite database
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. The CREATE TABLE command
        2. The INSERT command
        3. The SELECT command
        4. The WHERE command
        5. The UPDATE command
        6. The DELETE command
        7. The DROP command
    7. Viewing data from your own webserver
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Security
        2. Using MySQL instead
    8. Sensing and sending data to online services
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  14. Building Neural Network Modules for Optical Character Recognition
    1. Introduction
    2. Visualizing optical characters
      1. How to do it...
    3. Building an optical character recognizer using neural networks
      1. How to do it...
      2. How it works...
      3. See also
    4. Applications of an OCR system
  15. Arithmetic Operations, Loops, and Blinky Lights
    1. Hardware required for this chapter
    2. Arithmetic operations
    3. Bitwise operators in Python
    4. Logical operators
    5. Data types and variables in Python
    6. Reading inputs from the user
      1. The formatted string output
        1. The str.format() method
        2. An exercise for the reader
        3. Another exercise for the reader
      2. Concatenating strings
    7. Loops in Python
      1. A for loop
        1. Indentation
          1. Nested loops
      2. A while loop
    8. Raspberry Pi's GPIO
      1. Blinky lights
        1. Code
      2. The applications of GPIO control
    9. Summary
  16. Conditional Statements, Functions, and Lists
    1. Conditional statements
      1. An if-else statement
      2. if-elif-else statement
        1. Breaking out of loops
      3. The applications of conditional statements: executing tasks using GPIO
        1. Breaking out a loop by counting button presses
    2. Functions in Python
      1. Passing arguments to a function:
      2. Returning values from a function
      3. The scope of variables in a function
      4. GPIO callback functions
        1. DC motor control in Python
    3. Some mini-project challenges for the reader
    4. Summary
  17. Communication Interfaces
    1. UART – serial port
      1. Raspberry Pi Zero's UART port
        1. Setting up the Raspberry Pi Zero serial port
      2. Example 1 – interfacing a carbon dioxide sensor to the Raspberry Pi
      3. Python code for serial port communication
      4. I2C communication
      5. Example 2 – PiGlow
      6. Installing libraries
        1. Example
      7. Example 3 – Sensorian add-on hardware for the Raspberry Pi
        1. I2C drivers for the lux sensor
          1. Challenge
    2. The SPI interface
      1. Example 4 – writing to external memory chip
        1. Challenge to the reader
    3. Summary
  18. Data Types and Object-Oriented Programming in Python
    1. Lists
      1. Operations that could be performed on a list
        1. Append element to list:
        2. Remove element from list:
        3. Retrieving the index of an element
        4. Popping an element from the list
        5. Counting the instances of an element:
        6. Inserting element at a specific position:
          1. Challenge to the reader
        7. Extending a list
        8. Clearing the elements of a list
        9. Sorting the elements of a list
        10. Reverse the order of elements in list
        11. Create copies of a list
        12. Accessing list elements
          1. Accessing a set of elements within a list
        13. List membership
      2. Let's build a simple game!
    2. Dictionaries
    3. Tuples
    4. Sets
    5. OOP in Python
      1. Revisiting the student ID card example
        1. Class
        2. Adding methods to a class
        3. Doc strings in Python
        4. self
    6. Speaker controller
      1. Light control daemon
    7. Summary
  19. File I/O and Python Utilities
    1. File I/O
      1. Reading from a file
        1. Reading lines
      2. Writing to a file
      3. Appending to a file
        1. seek
        2. Read n bytes
        3. r+
          1. Challenge to the reader
      4. The with keyword
      5. configparser
        1. Challenge to the reader
      6. Reading/writing to CSV files
        1. Writing to CSV files
        2. Reading from CSV files
    2. Python utilities
      1. The os module
        1. Checking a file's existence
        2. Checking for a folder's existence
        3. Deleting files
        4. Killing a process
        5. Monitoring a process
      2. The glob module
        1. Challenge to the reader
      3. The shutil module
      4. The subprocess module
      5. The sys module
    3. Summary
  20. Requests and Web Frameworks
    1. The try/except keywords
      1. try...except...else
      2. try...except...else...finally
    2. Connecting to the Internet – web requests
      1. The application of requests – retrieving weather information
      2. The application of requests – publishing events to the Internet
    3. Flask web framework
      1. Installing Flask
      2. Building our first example
      3. Controlling appliances using the Flask framework
    4. Summary
  21. Awesome Things You Could Develop Using Python
    1. Image processing using a Raspberry Pi Zero
      1. OpenCV
        1. The verification of the installation
          1. A challenge to the reader
      2. Installing the camera to the Raspberry Zero
    2. Speech recognition
    3. Automating routing tasks
    4. Improving daily commute
      1. A challenge to the reader
      2. Project challenge
    5. Improving your vocabulary
      1. A challenge to the reader
      2. Project challenge
    6. Logging
    7. Threading in Python
    8. PEP8 style guide for Python
      1. Verifying PEP8 guidelines
    9. Summary
  22. Robotics 101
    1. The hardware arsenal
    2. Setting up Raspberry Pi
    3. Let's program
    4. Playing with voltage
    5. Summary
  23. Using GPIOs as Input
    1. A deeper dive into GPIOs
      1. Interfacing the PIR sensor
      2. Interfacing the ultrasonic proximity sensor
    2. Interfacing through I2C
    3. Summary 
  24. Making a Gardener Robot
    1. Working with solenoids
    2. Making the robot
      1. Making it more intelligent
      2. Making it truly intelligent
    3. Summary
  25. Basics of Motors
    1. The basics
    2. Getting it rolling
    3. Changing the speed 
    4. Summary
  26. Bluetooth-Controlled Robotic Car
    1. Basics of the vehicle
    2. Getting the vehicle ready
    3. Controlling the vehicle by Bluetooth
    4. Summary
  27. Sensor Interface for Obstacle Avoidance
    1. Infrared proximity sensor
    2. Autonomous emergency braking
    3. Giving the car self-steering capabilities
    4. Making it fully autonomous
    5. Summary
  28. Making Your Own Area Scanner
    1. Servo motor
    2. Lists
    3. Looking around 
    4. LIDAR on an autonomous vehicle 
    5. Summary
  29. Basic Switching
    1. Making Jarvis wake you up 
      1. Working with relay and PIR sensor
      2. Making the alarm irritating
      3. Making it even more irritating
    2. Summary
  30. Recognizing Humans with Jarvis
    1. Turn on the light Jarvis
    2. Understanding motion
    3. Perfecting motion
      1. Controlling the intensity
      2. Intelligent temperature control
      3. Adding more 
    4. Summary
  31. Making Jarvis IoT Enabled
    1. Basics of IoT
    2. The MQTT protocol
    3. Setting up the MQTT broker
    4. Making an IoT-based intrusion detector
    5. Controlling the home
    6. Summary
  32. Giving Voice to Jarvis
    1. Basic installation
    2. Automatic delivery answering machine 
    3. Making an interactive door – answering robot
    4. Making Jarvis understand our voice
    5. Summary
  33. Gesture Recognition
    1. Electric field sensing
    2. Using the Flick HAT
    3. Gesture recognition-based automation
    4. Summary
  34. Machine Learning
    1. Making a dataset
    2. Predicting using a dataset
    3. Making your home learn
    4. Home learning and automation
    5. Summary
  35. Making a Robotic Arm
    1. Basics of a robotic arm
    2. Degrees of freedom
    3. Power house
      1. Voltage
      2. Capacity
      3. Power-to-weight ratio
      4. Maximum charge and discharge rate
      5. Chemical composition
    4. Finding the limits
    5. Making the robot safe
    6. Programming multiple frames
    7. Speed control
    8. Summary
  36. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Getting Started with Python for the Internet of Things
  • Author(s): Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. Diwakar Vaish
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781838555795