Getting Started with Python for the Internet of Things
eBook - ePub

Getting Started with Python for the Internet of Things

Leverage the full potential of Python to prototype and build IoT projects using the Raspberry Pi

  1. 732 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Getting Started with Python for the Internet of Things

Leverage the full potential of Python to prototype and build IoT projects using the Raspberry Pi

About this book

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 AIBook DescriptionThis 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 VaishWhat 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 BluetoothWho this book is forThis 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.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Getting Started with a Raspberry Pi 3 Computer

In this chapter, we will cover the following topics:
  • Connecting peripherals to Raspberry Pi
  • Using NOOBS to set up your Raspberry Pi SD card
  • Networking and connecting your Raspberry Pi to the internet via the LAN connector
  • Using built-in Wi-Fi and Bluetooth on Raspberry Pi
  • Configuring your network manually
  • Networking directly to a laptop or computer
  • Networking and connecting your Raspberry Pi to the internet via a USB Wi-Fi dongle
  • Connecting to the internet through a proxy server
  • Connecting remotely to Raspberry Pi over the network using VNC
  • Connecting remotely to Raspberry Pi over the network using SSH (and X11 forwarding)
  • Sharing the home folder of Raspberry Pi with SMB
  • Keeping Raspberry Pi up to date

Introduction

This chapter introduces Raspberry Pi 3 and the process of setting it up for the first time. We will connect Raspberry Pi to a suitable display, power, and peripherals. We will install an operating system on an SD card. This is required for the system to boot. Next, we will ensure that we can connect successfully to the internet through a local network.
Finally, we will make use of the network to provide ways to remotely connect to and/or control Raspberry Pi from other computers and devices, as well as to ensure that the system is kept up to date.
Once you have completed the steps within this chapter, your Raspberry Pi will be ready for you to use for programming. If you already have your Raspberry Pi set up and running, ensure that you take a look through the following sections, as there are many helpful tips.

Introducing Raspberry Pi

The Raspberry Pi is a single-board computer created by the Raspberry Pi Foundation, a charity formed with the primary purpose of re-introducing low-level computer skills to children in the UK. The aim was to rekindle the microcomputer revolution of the 1980s, which produced a whole generation of skilled programmers.
Even before the computer was released at the end of February 2012, it was clear that Raspberry Pi had gained a huge following worldwide and, at the time of writing this book, has sold over 10 million units. The following image shows several different Raspberry Pi models:
The Raspberry Pi Model 3B, Model A+, and Pi Zero

What's with the name?

The name, Raspberry Pi, was a combination of the desire to create an alternative computer with a fruit-based name (such as Apple, BlackBerry, and Apricot) and a nod to the original concept of a simple computer that could be programmed using Python (shortened to Pi).
In this book, we will take this little computer, find out how to set it up, and then explore its capabilities chapter by chapter, using the Python programming language.

Why Python?

It is often asked, "Why has Python been selected as the language to use on Raspberry Pi?" The fact is that Python is just one of the many programming languages that can be used on Raspberry Pi.
There are many programming languages that you can choose, from high-level graphical block programming, such as Scratch, to traditional C, right down to BASIC, and even the raw machine code assembler. A good programmer often has to be code multilingual to be able to play to the strengths and weaknesses of each language to best meet the needs of their desired application. It is useful to understand how different languages (and programming techniques) try to overcome the challenge of converting what you want into what you get, as this is what you are trying to do as well while you program.
Python has been selected as a good place to start when learning about programming, as it provides a rich set of coding tools while still allowing simple programs to be written without fuss. This allows beginners to gradually be introduced to the concepts and methods on which modern programming languages are based without requiring them to know it all from the start. It is very modular with lots of additional libraries that can be imported to quickly extend the functionality. You will find that, over time, this encourages you to do the same, and you will want to create your own modules that you can plug into your own programs, thus taking your first steps into structured programming.
Python addresses formatting and presentation concerns. As indentation will add better readability, indents matter a lot in Python. They define how blocks of code are grouped together. Generally, Python is slow; since it is interpreted, it takes time to create a module while it is running the program. This can be a problem if you need to respond to time-critical events. However, you can precompile Python or use modules written in other languages to overcome this.
It hides the details; this is both an advantage and a disadvantage. It is excellent for beginners but can be difficult when you have to second-guess aspects such as datatypes. However, this in turn forces you to consider all the possibilities, which can be a good thing.

Python 2 and Python 3

A massive source of confusion for beginners is that there are two versions of Python on Raspberry Pi (Version 2.7 and Version 3.6), which are not compatible with each other, so code written for Python 2.7 may not run with Python 3.6 (and vice versa).
The Python Software Foundation is continuously working to improve and move forward with the language, which sometimes means they have to sacrifice backward compatibility to embrace new improvements (and, importantly, remove redundant and legacy ways of doing things).
Supporting Python 2 and Python 3
There are many tools that will ease the transition from Python 2 to Python 3, including converters such as 2to3, which will parse and update your code to use Python 3 methods. This process is not perfect, and in some cases you'll need to manually rewrite sections and fully retest everything. You can write the code and libraries that will support both. The import __future__ statement allows you to import the friendly methods of Python 3 and run them using Python 2.7.

Which version of Python should you use?

Essentially, the selection of which version to use will depend on what you intend to do. For instance, you may require Python 2.7 libraries, which are not yet available for Python 3.6. Python 3 has been available since 2008, so these tend to be older or larger libraries that have not been translated. In many cases, there are new alternatives to legacy libraries; however, their support can vary.
In this book, we have used Python 3.6, which is also compatible with Python 3.5 and 3.3.

The Raspberry Pi family – a brief history of Pi

Since its release, Raspberry Pi has come in various iterations, featuring both small and large updates and improvements to the original Raspberry Pi Model B u...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Getting Started with a Raspberry Pi 3 Computer
  7. Dividing Text Data and Building Text Classifiers
  8. Using Python for Automation and Productivity
  9. Predicting Sentiments in Words
  10. Detecting Edges and Contours in Images
  11. Building Face Detector and Face Recognition Applications
  12. Using Python to Drive Hardware
  13. Sensing and Displaying Real-World Data
  14. Building Neural Network Modules for Optical Character Recognition
  15. Arithmetic Operations, Loops, and Blinky Lights
  16. Conditional Statements, Functions, and Lists
  17. Communication Interfaces
  18. Data Types and Object-Oriented Programming in Python
  19. File I/O and Python Utilities
  20. Requests and Web Frameworks
  21. Awesome Things You Could Develop Using Python
  22. Robotics 101
  23. Using GPIOs as Input
  24. Making a Gardener Robot
  25. Basics of Motors
  26. Bluetooth-Controlled Robotic Car
  27. Sensor Interface for Obstacle Avoidance
  28. Making Your Own Area Scanner
  29. Basic Switching
  30. Recognizing Humans with Jarvis
  31. Making Jarvis IoT Enabled
  32. Giving Voice to Jarvis
  33. Gesture Recognition
  34. Machine Learning
  35. Making a Robotic Arm
  36. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Getting Started with Python for the Internet of Things by Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. Diwakar Vaish in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Hardware. We have over one million books available in our catalogue for you to explore.