Preface
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.
This Learning Path includes content from the following Packt products:
- 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
Who this book is for
This book 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.
What this book covers
Chapter 1, Getting Started with a Raspberry Pi 3 Computer, introduces the Raspberry Pi and explores the various ways in which it can be set up and used.
Chapter 2, Dividing Text Data and Building Text Classifiers, guides us to build a text classifier; it can classify text using the bag-of-words model.
Chapter 3, Using Python for Automation and Productivity, explains how to use graphical user interfaces to create your own applications and utilities.
Chapter 4, Predicting Sentiments in Words, explains how Naive Bayes classifiers and logistic regression classifiers are constructed to analyze the sentiment in words
Chapter 5, Detecting Edges and Contours in Images, describes in detail how images are loaded, displayed, and saved. It provides detailed implementations of erosion and dilation, image segmentation, histogram equalization, edge detection, detecting corners in images, and more.
Chapter 6, Building Face Detector and Face Recognition Applications, explains how human faces can be detected from webcams and recognized using images stored in a database.
Chapter 7, Using Python to Drive Hardware, establishes the fact that to experience the Raspberry Pi at its best, we really have to use it with our own electronics. This chapter discusses how to create circuits with LEDs and switches, and how to use them to indicate the status of a system and provide control. Finally, it shows us how to create our own game controller, light display, and a persistence-of-vision text display.
Chapter 8, Sensing and Displaying Real-World Data, explains how to use an analog-todigital converter to provide sensor readings to the Raspberry Pi. We discover how to store and graph the data in real time, as well as display it on an LCD text display. Next, we record the data in a SQL database and display it in our own web server. Finally, we transfer the data to the internet, which will allow us to view and share the captured data anywhere in the world.
Chapter 9, Building a Neural Network Module for Optical Character Recognition, introduces neural network implementation on Raspberry Pi 3. Optical characters are detected, displayed, and recognized using neural networks
Chapter 10, Arithmetic Operations, Loops, and Blinky Lights, walks through the arithmetic operations in Python and loops in Python. In the second half of the chapter, we will discuss the Raspberry Pi Zero’s GPIO interface and then learn to blink an LED using a GPIO pin.
Chapter 11, Conditional Statements, Functions, and Lists, discusses the types of conditional statements, variables, and logical operators in Python. We will also discuss functions in Python. Then, we will learn to write a function that is used to control DC motors using the Raspberry Pi Zero.
Chapter 12, Communication Interfaces, covers all the communication interfaces available on the Raspberry Pi Zero. This includes the I2C, UART, and the SPI interface. These communication interfaces are widely used to interface sensors. Hence, we will demonstrate the operation of each interface using a sensor as an example.
Chapter 13, Data Types and Object-Oriented Programming in Python, discusses object-oriented programming in Python and the advantages of object-oriented programming. We will discuss this using a practical example.
Chapter 14, File I/O and Python Utilities, discusses reading and writing to files. We discuss creating and updating config files. We will also discuss some utilities available in Python.
Chapter 15, Requests and Web Frameworks, discusses libraries and frameworks that enable retrieving data from the Web. We will discuss an example, fetching local weather information. We will also discuss running a web server on the Raspberry Pi Zero.
Chapter 16, Awesome Things You Could Develop Using Python, discusses libraries and frameworks that enable retrieving data from the web. We will discuss examples such as fetching the local weather information. We will also discuss running a web server on the Raspberry Pi Zero
Chapter 17, Robotics 101, will make you understand the basics of our hardware and Python. Using simple LEDs, we will start to make simple programs in Python.
Chapter 18, Using GPIOs as Input, will discuss how to connect various sensors, starting with interfacing a switch through an ultrasonic range finder and finally to a light sensor (LDR) using an analog-to-digital converter.
Chapter 19, Making a Gardener Robot, will use various sensors, such as a soil humidity sensor, and a temperature sensor to sense the climate, and using a solenoid valve controlled by a relay, we will be making a robot that waters the garden whenever required.
Chapter 20, Basics of Motors, will discuss the working of motor and how it can be driven by a motor driver, how a full H bridge motor driver works, and also how the speed control mechanism works in the motor driver. While doing all this, we will control a motor and make it move in a different direction at different speeds.
Chapter 21, Bluetooth-Controlled Robotic Car, will teach more about steering and controlling a robotic vehicle, and the concepts of a skid-steer mechanism will be implemented. You will also learn how to use the Bluetooth onboard our Raspberry Pi and connect it to your mobile phone. Finally, using an app, we will control our robotic vehicle using our mobile phone.
Chapter 22, Sensor Interface for Obstacle Avoidance, will provide an insight into how we can use IR proximity sensors to determine distances. Also, we will make smart algorithms to sense distance on all sides and then move in the direction where the distance is greatest.
Chapter 23, Making Your Own Area Scanner, will teach you the basics of servo motors and how they can be controlled. Using servo motor, we will make an area scanner, in other words, a homemade LIDAR. Using this home-built sensor, we would make a self navigating car.
Chapter 24, Basic Switching, will control the equipment at your home with simple logic. Finally, we will make an alarm that will wake you up in the natural way by lights. This will have a smart automatic snooze.
Chapter 25, Recognizing Humans with Jarvis, will teach you how to control devices at your home with a room occupancy sensor that we will build at home using an IR proximity sensor. We will then make this occupancy sensor smart and ready to count the number of people in the room and only switch off the lights or other equipment once no one is left in the room.
Chapter 26, Making Jarvis IoT Enabled, will provide you with insights into the concepts of IoT and MQTT server through which we will be able to monitor our home based on events. Also, you will learn how to control the devices in our home while sitting anywhere in the world.
Chapter 27, Giving Voice to Jarvis, will teach you how the system can be made capable of synthesizing speech. Also, you will learn how you can make the system recognize our speech, and based on it, everything in the home can be controlled.
Chapter 28, Gesture Recognition, will make you identify the gestures made on the board using electric waves, and based on those gestures, the smart home will be controlled.
Chapter 29, Machine Learning, will make you understand the concepts of machine learning and especially the k-nearest algorithm. Using this algorithm, you will understand how data can be given to the system and predictions can be made based on it . Finally, you will execute a program to generate its own data by the inputs of the users over the course of time, and based on that data, it will start automatically controlling the home without any human intervention.
Chapter 30, Making a Robotic Arm, will help you make a robotic hand. You will understand how to set the physical limits of the servos for protection purposes, and we will then make a program in which you will control the robot will be controlled based on different frames. Finally, you will go ahead and understand how to control speed of motion of the robot.
To get the most out of this book
To start using this book, Readers are expected to know the basics of Python programming. It would be beneficial for readers to have a basic understanding of machine learning, computer vision, and neural networks.The following hardware is recommended as well:
- A laptop computer, with any OS
- Raspberry Pi
- A microSD card, either 8 GB or 16 GB
- A USB keyboard, mouse and a WiFi card
- A display with HDMI input
- Power supply, minimum 500 mA
- Display cables and other accessories
Readers will have to download and install RASPBIAN STRETCH WITH DESKTOP; this will give us the GUI interface for Raspberry Pi
Download the example code files
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
- Log in or register at www.packt.com.
- Select the
SUPPORT
tab. - Click on
Code Downloads & Errata
. - Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
- WinRAR/7-Zip for Windows
- Zipeg/iZip/UnRarX for Mac
- 7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/GettingStartedwithPythonfortheInternetofThings.In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalogue of books and videos available at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The input()
method is used to get an input from the user."
A block of code is set as follows:
try: input_value = int(value) except ValueError as error: print("The value is invalid %s" % error)
Any command-line input or output is written as follows:
sudo pip3 install schedule
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "If you need something different, click on the DOWNLOADS link in the header for all possible downloads:"
Note
Warnings or important notes appear like this.
Note
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com
.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com
with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.