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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Programming with Raspberry Pi

You're reading from   Python Programming with Raspberry Pi Build small yet powerful robots and automation systems with Raspberry Pi Zero

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781786467577
Length 312 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Sai Yamanoor Sai Yamanoor
Author Profile Icon Sai Yamanoor
Sai Yamanoor
Srihari Yamanoor Srihari Yamanoor
Author Profile Icon Srihari Yamanoor
Srihari Yamanoor
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Python and the Raspberry Pi Zero FREE CHAPTER 2. Arithmetic Operations, Loops, and Blinky Lights 3. Conditional Statements, Functions, and Lists 4. Communication Interfaces 5. Data Types and Object-Oriented Programming in Python 6. File I/O and Python Utilities 7. Requests and Web Frameworks 8. Awesome Things You Could Develop Using Python 9. Lets Build a Robot! 10. Home Automation Using the Raspberry Pi Zero 11. Tips and Tricks

The setup of the Raspberry Pi Zero

In this section, we will solder some headers onto the Raspberry Pi, load the OS onto a micro SD card, and fire the Raspberry Pi Zero for the first example.

Soldering the GPIO headers

In this book, we will discuss the different aspects of Python programming using the Raspberry Pi's GPIO pins. The Raspberry Pi Zero ships without the GPIO header pins. Let's go ahead and solder the GPIO pins. We have also uploaded a video tutorials to this book's website that demonstrates soldering the headers onto the Raspberry Pi Zero.

As mentioned before, the Raspberry Pi's GPIO section consists of 40 pins. This is arranged in two rows of 20 pins each. We will need either two sets of 20-pin male headers or a 20-pin double-row male header. These are available from vendors such as Digikey and Mouser. The headers for the Raspberry Pi are also sold as a kit by vendors like the Pi Hut (https://thepihut.com/collections/raspberry-pi-zero/products/raspberry-pi-zero-essential-kit).

2x20 headers for the Raspberry Pi Zero

In order to solder the headers onto the Raspberry Pi Zero, arrange the headers on a breadboard, as shown in the following figure:

Arranging the headers to solder onto the Raspberry Pi

Perform the following steps:

  1. Arrange the Raspberry Pi on top of the headers upside down.
  2. Gently hold the Raspberry Pi (to make sure that the headers are positioned correctly while soldering) and solder the headers onto the Raspberry Pi.
  1. Inspect the board to ensure that the headers are soldered properly and carefully remove the Raspberry Pi Zero off the breadboard.
Headers soldered onto the Raspberry Pi

We are all set to make use of the GPIO pins in this book! Let's move on to the next section.

Soldering the headers onto the Raspberry Pi using a breadboard might damage the breadboard if the right temperature setting isn't used. The metal contacts of the breadboard might permanently expand resulting in permanent damage. Training in basic soldering techniques is crucial, and there are plenty of tutorials on this topic.

Enclosure for the Raspberry Pi Zero

Setting up a Raspberry Pi zero inside an enclosure is completely optional but definitely useful while working on your projects. There are a plenty of enclosures sold by vendors. Alternatively, you may download an enclosure design from Thingiverse and 3D print them. We found this enclosure to suit our needs at http://www.thingiverse.com/thing:1203246 as it provides access to the GPIO headers. 3D printing services such as 3D Hubs (https://www.3dhubs.com/) would print the enclosure for a charge of $9 via a local printer. Alternately, you can also use predesigned project enclosures or design one that can be constructed using plexiglass or similar materials.

Raspberry Pi Zero in an enclosure

OS setup for the Raspberry Pi

Let's go ahead and prepare a micro SD card to set up the Raspberry Pi Zero. In this book, we will be working with the Raspbian OS. The Raspbian OS has a wide user base, and the OS is officially supported by the Raspberry Pi Foundation. Hence, it is easier to find support on forums while working on projects as more people are familiar with the OS.

micro SD card preparation

If you had purchased a micro SD card that comes pre-flashed with the Raspbian New Out of the Box Software (NOOBS) image, you may skip the micro SD card preparation:

  1. The first step is downloading the Raspbian NOOBS image. The image can be downloaded from https://www.raspberrypi.org/downloads/noobs/.
Downloads the Raspberry Pi NOOBS image
  1. Format your SD card using the SD Card Formatter tool. Make sure that the FORMAT SIZE ADJUSTMENT is ON as shown in the snapshot (available from https://www.sdcard.org/downloads/formatter_4/index.html):
Format the SD card
  1. Extract the downloaded ZIP file and copy the contents of the file to the formatted micro SD card.
  1. Set up the Raspberry Pi (not necessarily in the same order):
  • Interface the HDMI cable from the monitor via the mini HDMI interface
  • USB hub via the USB OTG interface of the Raspberry Pi Zero
  • Micro-USB cable to power the Raspberry Pi Zero
  • Plug in a Wi-Fi adapter, a keyboard, and a mouse to the Raspberry Pi Zero
Raspberry Pi Zero with the keyboard, the mouse, and the Wi-Fi adapter
  1. Power up the Raspberry Pi, and it should automatically flash the OS onto the SD card and launch the desktop at startup.
  2. The first step after startup is changing the Raspberry Pi's password. Go to menu (the Raspberry Pi symbol located at the top-left corner) and select Raspberry Pi Configuration under Preferences.
Launch Raspberry Pi configuration
  1. Under the System tab, change the password:
Change the password
  1. Under the Localisation tab, change the locale, time zone, and keyboard settings based upon your region.
  1. When the installation is complete, connect the Raspberry Pi Zero to the wireless network (using the wireless tab on the top right).
Raspberry Pi desktop upon launch
  1. Let's launch the command-line terminal of the Raspberry Pi to perform some software updates.
Launching the command-line terminal
  1. Run the following commands from the command-line terminal:
       sudo apt-get update
sudo apt-get upgrade

The OS upgrade should complete within a couple of minutes.

The Raspberry Pi Foundation hosts a video on its website that provides a visual aid to set up the Raspberry Pi. This video is available at https://vimeo.com/90518800.
You have been reading a chapter from
Python Programming with Raspberry Pi
Published in: Apr 2017
Publisher: Packt
ISBN-13: 9781786467577
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image