Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Raspberry Pi Zero Cookbook
Raspberry Pi Zero Cookbook

Raspberry Pi Zero Cookbook: Delve into the practical world of the Raspberry Pi Zero

eBook
₹799.99 ₹2621.99
Paperback
₹3276.99
Subscription
Free Trial
Renews at ₹800p/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

Raspberry Pi Zero Cookbook

Chapter 2. Setting Up Physical and Wireless Connections

In this chapter, we will cover the following recipes:

  • Controlling the RPZ from the UART GPIO port using the console cable
  • Adding a Wi-Fi dongle over USB OTG
  • Hacking RPZ hardware to add a permanent Wi-Fi dongle
  • Setting up dynamic and static IP addresses for the RPZ
  • Pinging from another computer over same network
  • SSHing your RPZ from your desktop computer
  • Sharing a screen on your desktop computer
  • Copying different files to and from your home network
  • Adding USB functions to Raspbian Jessie
  • Using a virtual serial adapter on USB OTG
  • Programming over a virtual Ethernet modem on USB OTG
  • Making your RPZ a USB mass storage device

Introduction

Now that we have our operating system running, we can really start to thinking about the portability advantages this Raspberry Pi Zero can bring. We'll start talking to the Raspberry Pi Zero, get it on the network, and look at the unique features and modes you get with the Zero's small form factor.

Controlling the RPZ from the UART GPIO port using the console cable

If you already have a computer that you use at home, the Raspberry Pi Zero will probably not be serving as a replacement. Wouldn't it be nice if you could work with the Zero through your own home computer? Then you only need one mouse, one keyboard, and one monitor. This recipe will show you how to use the Raspberry Pi Zero's UART GPIO to communicate with a USB-to-serial interface. Becoming familiar with this interface is great for troubleshooting (for example, when USB isn't working or you don't have a monitor nearby) and is one many different ways you can interact with your Zero.

Note

What is a UART and a GPIO? UART stands for Universal Asynchronous Receiver/Transmitter. Basically, that means it is a communication device understood by a lot of different devices, and it talks back and forth and doesn't wait for an acknowledgement. GPIO stands for General Purpose Input/Output and is the set of communication...

Adding Wi-Fi dongle over USB OTG

An easy way to communicate with your Pi and get your little computer connected to the Internet is connecting it to a USB Wi-Fi adapter. Once you have your Raspberry Pi Zero connected to Wi-Fi, we can get it to interact with pretty much anything that lives on your home network.

Getting ready

For this recipe, you will need your Raspberry Pi Zero, a USB OTG adapter, and a USB Wi-Fi device. Most of this equipment comes with any starter kit and is inexpensive to buy individually-the OTG adapters can be found for less than $5 and Wi-Fi dongles are $10-$15. It is still amazing that a lot of these accessories cost at least as much as the computer they are needed for!

A small USB OTG dongle and Wi-Fi adapter make for a pretty small setup:

Getting ready

You do need to add power, but even with that, you maintain a very small footprint for what will be an Internet-enabled computer.

The embedded Linux site ( elinux.org ) has a comprehensive listing of tested and compatible Wi-Fi cards...

Hacking RPZ hardware to add up permanent Wi-Fi dongle

The USB dongle solder hack is considered one of the very first hacks shared in the community after the release of the Raspberry Pi Zero. With such a small form factor and USB OTG connectors, many hackers didn't like the idea of adding to the size of the board with an adapter and then tacking on a USB dongle. This recipe shows you how to attach an uncased Wi-Fi adapter to the Raspberry Pi Zero to keep your footprint still small enough to fit a mints tin.

Getting ready

This is another soldering hack, and not necessarily for the faint of heart. You'll need a compatible USB Wi-Fi dongle, but it is important to make sure to check the compatibility list on https://www.elinux.org to ensure that your dongle is both compatible and does not require additional power. Since we will be soldering this one right to the Zero, it will need to be able to get all of the power it needs from the incoming USB 5V port.

A great way to test whether you...

Setting Up dynamic and static IP address for RPZ

Now that we have our Raspberry Pi Zero on the network, let's look a little closer at what we can do with the networking. Everything should have connected to your Wi-Fi network thanks to DHCP (Dynamic Host Allocation Protocol). DHCP takes incoming requests from devices to be added to the network. It has a pool of IP addresses on the network that it will "lease" to the device for a period of time. After the lease expires, the device may renew (and, depending on the DHCP server rules, will get a new or the same address), or the address will be returned to the available pool. This makes it easy to add machines to a network without keeping track of individual addresses assigned to devices. When your Raspberry Pi Zero connected to your Wi-Fi network, by default, it would have been assigned at least one IP address: an IPv4 address (four sets of numbers between 0 and 255, as in 192.168.17.250), and/or a newer IPv6 address (8 sets of...

Introduction


Now that we have our operating system running, we can really start to thinking about the portability advantages this Raspberry Pi Zero can bring. We'll start talking to the Raspberry Pi Zero, get it on the network, and look at the unique features and modes you get with the Zero's small form factor.

Controlling the RPZ from the UART GPIO port using the console cable


If you already have a computer that you use at home, the Raspberry Pi Zero will probably not be serving as a replacement. Wouldn't it be nice if you could work with the Zero through your own home computer? Then you only need one mouse, one keyboard, and one monitor. This recipe will show you how to use the Raspberry Pi Zero's UART GPIO to communicate with a USB-to-serial interface. Becoming familiar with this interface is great for troubleshooting (for example, when USB isn't working or you don't have a monitor nearby) and is one many different ways you can interact with your Zero.

Note

What is a UART and a GPIO? UART stands for Universal Asynchronous Receiver/Transmitter. Basically, that means it is a communication device understood by a lot of different devices, and it talks back and forth and doesn't wait for an acknowledgement. GPIO stands for General Purpose Input/Output and is the set of communication connections that...

Adding Wi-Fi dongle over USB OTG


An easy way to communicate with your Pi and get your little computer connected to the Internet is connecting it to a USB Wi-Fi adapter. Once you have your Raspberry Pi Zero connected to Wi-Fi, we can get it to interact with pretty much anything that lives on your home network.

Getting ready

For this recipe, you will need your Raspberry Pi Zero, a USB OTG adapter, and a USB Wi-Fi device. Most of this equipment comes with any starter kit and is inexpensive to buy individually-the OTG adapters can be found for less than $5 and Wi-Fi dongles are $10-$15. It is still amazing that a lot of these accessories cost at least as much as the computer they are needed for!

A small USB OTG dongle and Wi-Fi adapter make for a pretty small setup:

You do need to add power, but even with that, you maintain a very small footprint for what will be an Internet-enabled computer.

The embedded Linux site ( elinux.org ) has a comprehensive listing of tested and compatible Wi-Fi cards...

Hacking RPZ hardware to add up permanent Wi-Fi dongle


The USB dongle solder hack is considered one of the very first hacks shared in the community after the release of the Raspberry Pi Zero. With such a small form factor and USB OTG connectors, many hackers didn't like the idea of adding to the size of the board with an adapter and then tacking on a USB dongle. This recipe shows you how to attach an uncased Wi-Fi adapter to the Raspberry Pi Zero to keep your footprint still small enough to fit a mints tin.

Getting ready

This is another soldering hack, and not necessarily for the faint of heart. You'll need a compatible USB Wi-Fi dongle, but it is important to make sure to check the compatibility list on https://www.elinux.org to ensure that your dongle is both compatible and does not require additional power. Since we will be soldering this one right to the Zero, it will need to be able to get all of the power it needs from the incoming USB 5V port.

A great way to test whether you have the...

Setting Up dynamic and static IP address for RPZ


Now that we have our Raspberry Pi Zero on the network, let's look a little closer at what we can do with the networking. Everything should have connected to your Wi-Fi network thanks to DHCP (Dynamic Host Allocation Protocol). DHCP takes incoming requests from devices to be added to the network. It has a pool of IP addresses on the network that it will "lease" to the device for a period of time. After the lease expires, the device may renew (and, depending on the DHCP server rules, will get a new or the same address), or the address will be returned to the available pool. This makes it easy to add machines to a network without keeping track of individual addresses assigned to devices. When your Raspberry Pi Zero connected to your Wi-Fi network, by default, it would have been assigned at least one IP address: an IPv4 address (four sets of numbers between 0 and 255, as in 192.168.17.250), and/or a newer IPv6 address (8 sets of hexadecimal numbers...

Pinging from another computer over same network


Now that we have our computer on the network, we want to make sure other computers are able to contact it. The ping command is one of the first tests to tell whether your computer can be contacted. The command sends a small test packet of data to another computer's IP address or hostname and waits to hear a response. If it does, it tells you how long it took for the response to come back. If it doesn't, it tells you it is not receiving a response.

Note

Some computer systems have firewalls that do not allow ICMP ECHO attempts. This means that even though the computer is available on the network, attempts to ping it will fail. On the default configuration of Raspbian, ping commands are allowed, so attempts to ping your Pi should succeed.

Getting ready

As long you as you know your IP address (whether it was dynamically assigned using DHCP or you assigned a static IP from the previous recipe), you should be able to contact it from your network. The...

SSHing your RPZ from your desktop computer


The ideal way to talk to your Raspberry Pi Zero is using Secure SHell (SSH). This gives you a secure, encrypted channel to talk to your Pi from anywhere on the network. For example, let's say you want your Pi to collect temperature information from your attic and make it available on your home network. You don't want to drag a monitor, mouse, and keyboard up to your attic every time you want to make a change-you want to do it from your regular home computer! If you have your RPZ using Wi-Fi, on the network, and ping-able, the next step is to work with it remotely over SSH. Here's how.

Getting ready

If you are using a Windows machine, PuTTY is the way to go, just like a serial connection. If you are on OSX or Linux, SSH should be installed and available using any terminal window. You'll also need the IP address of your Raspberry Pi Zero.

If you ran through the earlier recipe to enable SSH using the rasp-config utility covered in Chapter 1, Kick-Start...

Sharing a screen on your desktop computer


While it is inevitable that you will use the command line a lot when using Linux, a lot of people enjoy Raspbian's GUI. But you still want to keep your Zero in the attic! No problem at all: the Virtual Network Computing (VNC) service makes the GUI available from anywhere you able to connect.

Getting ready

Stay connected to your Raspberry Pi Zero with your SSH terminal. On your home computer, you will need a VNC viewer application. I love the VNC Viewer Chrome extension, and it is available on any platform.

How to do it...

  1. First, you need to install a VNC server on your Raspberry Pi Zero. To install it on Raspbian, type the following:

            sudo apt-get install tightvncserver
    

  2. Once it's installed, starting it is as simple as typing vncserver:

            $ vncserver
            New 'X' desktop is rpz14101:1
            Starting applications specified in 
            /home/pi/.vnc/xstartup
            Log file is /home/pi/.vnc/rpz14101:1.log 
    

  3. The first...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Deep dive into the components of the small yet powerful Raspberry Pi Zero
  • Get into grips with integrating various hardware, programming, and networking concepts with the so-called “cheapest computer”
  • Explore the functionalities of this $5 chip through practical recipes

Description

The Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running. In this book, you will learn how to prepare your own circuits rather than buying the expensive add–ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.

Who is this book for?

This book is for programmers and hobbyists who are eager to dive deep into the Raspberry Pi Zero. If you have basic or zero knowledge of the Raspberry Pi Zero, or if you looking for examples of ways to utilize the Raspberry Pi’s GPIO interface, then this book is ideal for you. Basic knowledge of Python will be beneficial, and experience with circuitry and electronics will be needed for the later chapters in the book.

What you will learn

  • Set up your Raspberry Pi Zero with the operating system, networking, and different interfaces
  • Get a hands-on introduction to Linux, Python, and shell scripts with the Raspberry Pi Zero
  • Become a master at driving GPIOs and controlling relays, motors, transistors, buzzers, audio, read switches, and interrupts with the Raspberry Pi Zero
  • Control GPIOs using the web interface and Node.js
  • Connect displays, LED matrixes, analog sensors, and digital sensors
  • Hack the Ethernet on the Raspberry Pi Zero
  • Make your Raspberry Pi Zero an IoT-based sensor node and remotely monitor your data

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 24, 2017
Length: 422 pages
Edition : 1st
Language : English
ISBN-13 : 9781786466471
Vendor :
Raspberry Pi
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 : Mar 24, 2017
Length: 422 pages
Edition : 1st
Language : English
ISBN-13 : 9781786466471
Vendor :
Raspberry Pi
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 9,086.97
Python Programming with Raspberry Pi
₹2904.99
Raspberry Pi Zero W Wireless Projects
₹2904.99
Raspberry Pi Zero Cookbook
₹3276.99
Total 9,086.97 Stars icon

Table of Contents

10 Chapters
1. Kick-Start Your Raspberry Pi Zero Chevron down icon Chevron up icon
2. Setting Up Physical and Wireless Connections Chevron down icon Chevron up icon
3. Programming with Linux Chevron down icon Chevron up icon
4. Programming with Python Chevron down icon Chevron up icon
5. Getting Your Hands Dirty Using the GPIO Header Chevron down icon Chevron up icon
6. Controlling the LEDs and Displays Chevron down icon Chevron up icon
7. Controlling the Hardware Chevron down icon Chevron up icon
8. Taking Digital Inputs to the Raspberry Pi Zero Chevron down icon Chevron up icon
9. Interfacing Sensors with the Raspberry Pi Zero Chevron down icon Chevron up icon
10. Cooking up Projects to Amaze the World! Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Ivan Rivera Feb 04, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The is great and have good examples of use. I would like to have additional sections that explain common problems when it is used specific sensor. Thank you.
Amazon Verified review Amazon
Ken Shim Jun 14, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book
Amazon Verified review Amazon
Federico Rasman Jul 25, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Un ottimo libro capace di spiegare il funzionamento della Raspberry Pi Zero in maniera esaustiva.E' un vero ricettario di idee e problemi risolti.Un buon punto di partenza per i programmatori Python RPZ.Esige la conoscenza dell'inglese, ma in ambiente elettronico/informatico questo è scontato.
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.