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
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

Arrow left icon
Profile Icon Edward Snajder
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback Mar 2017 422 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Edward Snajder
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback Mar 2017 422 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781786463852
Vendor :
Raspberry Pi
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Mar 24, 2017
Length: 422 pages
Edition : 1st
Language : English
ISBN-13 : 9781786463852
Vendor :
Raspberry Pi
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 121.97
Python Programming with Raspberry Pi
$38.99
Raspberry Pi Zero W Wireless Projects
$38.99
Raspberry Pi Zero Cookbook
$43.99
Total $ 121.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.