Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Internet of Things Programming Projects
Internet of Things Programming Projects

Internet of Things Programming Projects: Build modern IoT solutions with the Raspberry Pi 3 and Python

eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Internet of Things Programming Projects

Installing Raspbian on the Raspberry Pi

The Raspberry Pi is marketed as a small and affordable computer that you can use to learn programming. At least that was its initial goal. As we will see in this book, it is much more than that.

The following topics will be covered in this chapter:

  • A brief history of the Raspberry Pi
  • A look at operating systems for the Raspberry Pi
  • Installing the Raspbian OS
  • A quick overview of the Raspbian OS

A brief history of the Raspberry Pi

First released in 2012, the first Raspberry Pi featured a 700 MHz single core processor and 256 MB of RAM. The Raspberry Pi 2 was released in February of 2015 with a 900 MHz quad core processor and 1 GB of RAM. Released in February of 2016, the Raspberry Pi 3 increased the processor speed to 1.2 GHz. This model was also the first one to include wireless LAN and Bluetooth.

Here is an image of a Raspberry Pi 3 B (2015):

This version of the Raspberry Pi features the following parts:

  • Four USB 2 ports
  • A LAN port
  • A 3.5 mm composite video and audio jack
  • An HDMI port for video and audio
  • An OTG USB port (which we will use to connect the power)
  • A microSD slot (to hold our operating system)
  • A DSI display port for the Raspberry Pi touchscreen
  • A General Purpose Input Output (GPIO) pins
  • A camera port for a special Raspberry Pi camera

The Raspberry Pi Zero was released in November of 2015. Here is an image of it:

Although not as powerful as the previous Raspberry Pis, the Zero featured a smaller size (65 mm X 30 mm), perfect for projects with limited physical space (namely, wearable projects). Plus, the Raspberry Pi zero was priced at $5 USD, making it very affordable. The Raspberry Pi zero W was released on February 28, 2017 at double the price ($10 USD) with built-in Wi-Fi and Bluetooth capabilities.

The latest model, as of the time of writing, is the Raspberry Pi 3 B+, which was released on March 14, 2018. The processor speed has been upgraded to 1.4 GHz as well as the wireless LAN now supporting both 2.4 GHz and 5 GHz bands. Another upgrade is the addition of Bluetooth low energy, a technology built for applications that do not require large amounts of data to be exchanged but are required to have a long battery life.

Creators of the Raspberry Pi initially believed that they would sell at most 1,000 units. Little did they know that their invention would explode in popularity. As of March 2018, sales of Raspberry Pi computers has passed the 19 million mark.

A look at operating systems for the Raspberry Pi

There are various operating systems (or system images) that may be installed on the Raspberry Pi. These range from application-specific operating systems, such as audio players, to various general purpose operating systems. The power behind Raspberry Pi is the way it can be used for various applications and projects.

The following is a list of just a few of the operating systems (system images) available for the Raspberry Pi:

  • Volumio: Do you have a desire to set up a networked audio system where you access your music list using a computer or cell phone? Volumio may be what you are looking for. Installing it on a Raspberry Pi creates a headless audio player (a system that does not require a keyboard and mouse) that connects to your audio files either over USB or a network. A special audio Hardware Added on Top (HAT) may be added to your Pi to provide a pristine audio connection to an amplifier and speakers. There is even a plugin to add Spotify so that you can set up your Raspberry Pi to access this service and play music over your sound system.
  • PiFM radio transmitter: The PiFM radio transmitter turns your Raspberry Pi into an FM transmitter, which you can use to send audio files over the air to a standard FM radio receiver. Using a simple wire connected to one of the GPIO pins (we will learn more about GPIO later), you can create an antenna for the transmitted FM signal, which is surprisingly strong.
  • Stratux: ADS-B is the new standard in aviation where geo-location and weather information are shared with ground controllers and pilots. The Stratux image with additional hardware turns the Raspberry Pi into an ADS-B receiver of this information.
  • RetroPie: RetroPie turns your Raspberry Pi into a retro game console by emulating gaming consoles and computers from the past. Some of the emulations include Amiga, Apple II, Atari 2600, and the Nintendo Entertainment System of the early 1980s.
  • OctoPi: OctoPi turns your Raspberry Pi into a server for your 3D printer. Through OctoPi, you may control your 3D printer over the network, including viewing the status of your 3D printer using a webcam.
  • NOOBS: This is arguably the easiest way to install an operating system on the Raspberry Pi. NOOBS stands for New Out-Of-the Box Software, and we will be using NOOBS to install Raspbian.

Project overview

In this project, we will install the Raspbian operating system onto our Raspberry Pi. After installation, we will take a quick tour of the operating system to familiarize ourselves with it. We will start by formatting a microSD card to store our installation files. We will then run the installation from the microSD card. After Raspbian has been installed, we will take a quick look at it in order to familiarize ourselves with it.

This project should take about two hours to complete, as we install the Raspbian operating system and take a quick look at it.

Getting started

The following is required to complete this project:

Installing the Raspbian OS

The Raspbian OS is considered the default or go-to operating system for the Raspberry Pi. In this section, we will install Raspbian using the NOOBS image.

Formatting a microSD card for Raspbian

Raspberry Pi uses a microSD card to store the operating system. This allows you to easily switch between different operating systems (system images) for your Raspberry Pi. We will be installing the default Raspbian OS for our projects using the NOOBS image.

Start by inserting the microSD card into a USB adapter and plug it into your computer:

You may need to format the microSD card. If so, use the utilities appropriate for your computer's operating system to format the card to FAT32. It is recommended that you use a card with a capacity of 8 GB or greater. For Windows OS and cards with 64 GB of capacity or greater, a third-party tool such as FAT32 format should be used for formatting.

Copying the NOOBS files to the microSD RAM

Unzip the NOOBS image that you downloaded. Open up the unzipped directory and drag the files over to the microSD card.

The files should look the same as in the following screenshot:

Running the installer

We will now install Raspbian on our Raspberry Pi. This step should be familiar to those that have previous experience installing operating systems such as Windows or macOS. The Raspbian operating system will be installed and will run off of our microSD card.

To install Raspbian onto our microSD card, do the following:

  1. Start by inserting the microSD card into the appropriate slot on the Raspberry Pi. Be sure to install it so that the label side (opposite side of the exposed contacts) is facing up. Insert it with the metal contacts facing the board. The microSD card should have a slight ridge at the top of the label side, which is good for easy removal using a fingernail.
  2. Insert a keyboard and mouse into the USB slots on the side, a monitor into the HDMI port, and lastly, a USB power cable into the power port. The Raspberry Pi does not have an on/off switch and will power up as soon as the power cable is connected:
  1. After an initial black screen with rolling white text, you should see the following dialog:
  1. In the previous screenshot, we clicked on the Language option. For our purposes, we will keep the default of English (UK). We will also keep the keyboard at the standard gb.
  2. As the Raspberry Pi 3 has wireless LAN, we can set up our Wi-Fi (for older boards, please plug a Wi-Fi dongle into a USB port or use the wired LAN port and skip the next step):
  1. Click on the Wifi networks (w) button. Choose the Authentication method using the radio buttons. Some routers are equipped with a WPS button that allows you to connect directly to the router. To use the password method, choose the Password authentication radio button and enter the password for your network. After connecting to your network, you will notice that there are now more operating system options to select from:
  1. We will go with the top option, Raspbian. Check the box beside Raspbian [RECOMMENDED] and then click on the Install (i) button at the top-left corner of the dialog. Raspbian will start installing on your Raspberry Pi. You will see a progress bar with previous graphics, describing various features of the Raspbian operating system:
  1. After the progress bar hits 100%, the computer will reboot and you will see a screen with text before the default desktop loads up:

A quick overview of the Raspbian OS

The Raspbian desktop is similar to the desktops of other operating systems such as Windows and macOS. Clicking the top-left button drops down the application menu where you may access the various pre-installed programs. We may also shut down the Raspberry Pi from this menu:

The Chromium web browser

The second button from the left loads the Google Chromium web browser for the Raspberry Pi:

The Chromium browser is a lightweight browser that runs remarkably well on the Raspberry Pi:

The home folder

The two-folders button opens up a window showing the home folder:

The home folder is a great place to start when looking for files on your Raspberry Pi. In fact, when you take screenshots using either the scrot command or the Print Screen button, the file is automatically stored in this folder:

The Terminal

The third button from the left opens up the Terminal. The Terminal permits command-line access to Raspberry Pi's files and programs:

It is from the command line where you may update the Raspberry Pi using the sudo apt-get update and sudo apt-get dist-upgrade commands.

apt-get updates the packages list, and apt-get dist-upgrade updates the packages:

It's a good idea to run both of these commands right after installing Raspbian using the sudo command. The default user for Raspbian on the Raspberry Pi is pi, which is part of the Super Users group in Raspbian, and thus must use the sudo command (the default password for the pi user is raspberry):

Mastering the command line is a virtue that many a programmer aspires to acquire. Being able to rapidly type command after command looks so cool that even movie makers have picked up on it (when was the last time you saw the computer wiz in a movie clicking around the screen with a mouse?). To assist you in becoming this uber cool computer wiz, here are some basic Raspbian commands for you to master using the Terminal:

ls: Command to see the contents of the current directory
cd: Command to change directories. For example, use cd to move up a directory from where you currently are
pwd: Command to display the directory you are currently in
sudo: Allows the user to perform a task as the super user
shutdown: Command that allows the user to shut down the computer from the Terminal command line

Mathematica

The third and fourth buttons are for Mathematica, and a terminal to access the Wolfram language, respectively:

Mathematica spans all areas of technical computing and uses the Wolfram language as the programming language. The areas in which Mathematica is used include machine learning, image processing, neural networks and data science:

Mathematica, a proprietary software first released in 1988, can be used free for individuals on the Raspberry Pi through a partnership that was announced in late 2013.

Now let’s take a look at some of the programs that are accessed from the main drop-down menu.

Sonic Pi

Sonic Pi is a live coding environment for creating electronic music. It is accessed from the Programming menu option. Sonic Pi is a creative way to create music as the user programs loops, arpeggios, and soundscapes in real time by cutting and pasting code from one part of the app to another. Synthesizers in Sonic Pi may be configured on a deep level, providing a customized experience for the music coder:

Geared toward an EDM style of music, Sonic Pi may also be used to compose classical and jazz styles of music.

Scratch and Scratch 2.0

Scratch and Scratch 2.0 are visual programming environments designed for teaching programming to children. Using Scratch, the programmer creates their own animations with looping and conditional statements.

Games may be created within the program. The first version of Scratch was released in 2003 by the Lifelong Kindergarten group at the MIT media lab. Scratch 2.0 was released in 2013, and development is currently underway with Scratch 3.0:

Scratch and Scratch 2.0 may be accessed under the Programming menu option.

LibreOffice

LibreOffice is a free and open source office suite that forked over from OpenOffice in 2010. The LibreOffice suite consists of a word processor, a spreadsheet program, a presentation program, a vector graphics editor, a program for creating and editing mathematical formulae, and a database management program. The LibreOffice suite of programs may be accessed through the LibreOffice menu option:

Summary

We started this chapter with a look at the history of the Raspberry Pi. What started as an initiative to promote programming to a new generation has grown into a global phenomenon. We then downloaded the NOOBS image and installed the Raspbian OS, the default operating system for the Raspberry Pi. This involved formatting and preparing a microSD card for the NOOBS files.

It's easiest to think that a computer as inexpensive and small as the Raspberry Pi is not all that powerful. We demonstrated that the Raspberry Pi is indeed a very capable computer, as we took a look at some of the applications that come pre-installed with the Raspbian OS.

In Chapter 2, Writing Python Programs Using Raspberry Pi, we will begin Python coding using the Raspberry Pi and some of the development tools available in Raspbian.

Questions

  1. What year did the first Raspberry Pi come out?
  2. What upgrades did the Raspberry Pi 3 Model B+ have over the previous version?
  3. What does NOOBS stand for?
  4. What is the name of the pre-installed application that allows for creating music with Python code?
  5. Where is the operating system stored for the Raspberry Pi?
  6. What is the name of the visual programming environment designed for children that comes pre-installed with Raspbian?
  7. What is the name of the language used in Mathematica?
  8. What is the default username and password for Raspbian?
  9. What does GPIO stand for?
  10. What is RetroPie?
  11. True or false? Clicking on the two-folders icon on the main bar loads the home folder.
  12. True or false? The microSD card slot is located at the bottom of the Raspberry Pi.
  13. True or false? To shutdown the Raspberry Pi, select Shutdown from the Application menu.
  14. True or false? You may only install the Raspbian OS with NOOBS.
  15. True or false? Bluetooth low energy refers to people that eat too many blueberries and have a hard time waking up in the morning.

Further reading

For more information on the Raspberry Pi, please consult the main Raspberry Pi website at www.raspberrypi.org.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Leverage the full potential of IoT with the combination of Raspberry Pi 3 and Python
  • Build complex Python-based applications with IoT
  • Work on various IoT projects and understand the basics of electronics

Description

The Internet of Things (IOT) has managed to attract the attention of researchers and tech enthusiasts, since it powerfully combines classical networks with instruments and devices. In Internet of Things Programming Projects, we unleash the power of Raspberry Pi and Python to create engaging projects. In the first part of the book, you’ll be introduced to the Raspberry Pi, learn how to set it up, and then jump right into Python programming. Then, you’ll dive into real-world computing by creating a“Hello World” app using flash LEDs. As you make your way through the chapters, you’ll go back to an age when analog needle meters ruled the world of data display. You’ll learn to retrieve weather data from a web service and display it on an analog needle meter, and build a home security system using the Raspberry Pi. The next project has a modern twist, where we employ the Raspberry Pi to send a signal to a web service that will send you a text when someone is at the door. In the final project, you take what you've learned from the previous two projects and create an IoT robot car that you can use to monitor what your pets are up to when you are away. By the end of this book, you will be well versed in almost every possible way to make your IoT projects stand out.

Who is this book for?

Internet of Things Programming Projects is for Python developers and programmers who are interested in building their own IoT applications and IoT-based projects. It is also targeted at IoT programmers and developers who are looking to build exciting projects with Python.

What you will learn

  • Install and set up a Raspberry Pi for IoT development
  • Learn how to use a servo motor as an analog needle meter to read data
  • Build a home security dashboard using an infrared motion detector
  • Communicate with a web service that sends you a message when the doorbell rings
  • Receive data and display it with an actuator connected to the Raspberry Pi
  • Build an IoT robot car that is controlled through the internet

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 31, 2018
Length: 436 pages
Edition : 1st
Language : English
ISBN-13 : 9781789131383
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 31, 2018
Length: 436 pages
Edition : 1st
Language : English
ISBN-13 : 9781789131383
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 107.97
Internet of Things Programming Projects
€32.99
Industrial Internet Application Development
€41.99
Mastering Arduino
€32.99
Total 107.97 Stars icon
Banner background image

Table of Contents

20 Chapters
Installing Raspbian on the Raspberry Pi Chevron down icon Chevron up icon
Writing Python Programs Using Raspberry Pi Chevron down icon Chevron up icon
Using the GPIO to Connect to the Outside World Chevron down icon Chevron up icon
Subscribing to Web Services Chevron down icon Chevron up icon
Controlling a Servo with Python Chevron down icon Chevron up icon
Working with the Servo Control Code to Control an Analog Device Chevron down icon Chevron up icon
Setting Up a Raspberry Pi Web Server Chevron down icon Chevron up icon
Reading Raspberry Pi GPIO Sensor Data Using Python Chevron down icon Chevron up icon
Building a Home Security Dashboard Chevron down icon Chevron up icon
Publishing to Web Services Chevron down icon Chevron up icon
Creating a Doorbell Button Using Bluetooth Chevron down icon Chevron up icon
Enhancing Our IoT Doorbell Chevron down icon Chevron up icon
Introducing the Raspberry Pi Robot Car Chevron down icon Chevron up icon
Controlling the Robot Car Using Python Chevron down icon Chevron up icon
Connecting Sensory Inputs from the Robot Car to the Web Chevron down icon Chevron up icon
Controlling the Robot Car with Web Service Calls Chevron down icon Chevron up icon
Building the JavaScript Client Chevron down icon Chevron up icon
Putting It All Together Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 0%
2 star 0%
1 star 33.3%
Peter Nov 21, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The best way to learn something is by doing! This book will show you real applications for internet enabled electro-mechanical devices and machines. This book was a great intro for me into the Raspberry Pi world and gave me an excellent foundation to implement my own inventions. This book will NOT teach you Python from scratch nor HTML/CSS from scratch but it does a damn good job of getting you coding these languages without a deep dive into code semantics/syntax. I learned heaps about the semantics/syntax just by working through the projects. Oh and yes, you'll have to buy all the sensors and actuators if you want to actually work these projects. Also, the "grand finale" is a robot car ... there's quite a few purchases required in order to implement this one. The author does a great job of informing you where to buy what you need though.
Amazon Verified review Amazon
Frostic7734 Jul 20, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am only on chapter 6 because I have been reading this book at my leisure. I wouldn't recommend this book as a first book for beginners but if you have a little experience with the Pi and Python then this book is great. It is easy to follow along and it has a lot of practical examples. I bought this book because the final chapters teach you how to build a robot car from scratch. I have not been disappointed so far. I would recommend this book to anyone who wants to learn to make their own projects because this book doesn't just teach you how to put together a few projects. Ultimately, it will teach you how to make some of your own projects from scratch.
Amazon Verified review Amazon
Kindle Customer Dec 11, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Did the author even test the code examples from his book? i.e. 'pip3 install weather-api' does not work. Module name is wrong. Unfortunately it seems it's too late to get my money back.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.