Setting up a Pi Zero W

Intro

The Raspberry Pi Zero W is super good for a lot of projects and at $10 you can not do better than this mini Linux computer. However, it can be tricky to get things going due to the lack of Ethernet or full sized HDMI or USB port. You can get adapters, but we don’t need them anyway.

This tutorial will walk you through how to make an SD card boot disk and reconfigure it to connect over SSH using a regular micro USB cable just like the one your, non-iPhone, uses.

What You Need

1 x Micro SD card 8GB or larger

1 x Micro USB adapter for your computer

1 x Raspberry Pi Zero W

1 x Micro USB data cable

1 x Computer of some sort… to do all the work on.

1 x Wifi connection

Software:

Make Your Boot Disk

The Raspberry Pi uses an SD Card for the Hard Drive and even the Operating system runs off of it. We will be using a version of Linux for the OS that is very small and runs quite well for this kind of thing. A 16GB class 10 Micro SD card will work quite well, but you can always use one with more storage if you like.

First you will need to download the Raspbian Lite disk image for free from Rasperrypi.org. This tutorial used Raspbian 4.14 (Stretch) Lite as it was the latest version at the time.

Once downloaded, you will want to use Etcher to create a bootable Micro SD card. For help with this, check out this helpful guide.

Set Up the SSH connection

This is were things can get a bit tricky. The Pi Zero W has WiFi, but we need to connect to it in order to tell it how to connect to our WiFi. You may have noticed that there is no Ethernet or regular sized USB connectors. Well worry not because we don’t really need them. With just a few steps we can connect the Pi over USB using SSH.

Make some changes to the SD Card

Once your SD image is written to the SD card, you will have to make a few changes to the contents.

  1. First remove the SD card from your computer
  2. Now plug your SD card back into the computer
  3. The SD card should show up as a removable boot disk
  4. Open the SD card
  5. Scroll to and open config.txt using a code editor like Notepad++
  6. Add dtoverlay=dwc2 to the bottom of this file.

The result should look like this:

    # For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
dtoverlay=dwc2

Now we need to open cmdline.txt using the same code editor. Be very careful how you edit this one because it is very picky about extra spaces and new lines.

This is what it will look like:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4d3ee428-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh

We want to add modules-load=dwc2,g_ether after rootwait with a single space on either side.

This will end up looking like this:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4d3ee428-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh

If you have trouble, just replace the text in these files with the final examples of code given.

One last thing is to is create a new file named ssh in the main directory.

Just make a new file on the SD card and name it ssh with no extension.

ssh not ssh.txt

This will tell the Pi Zero to enable SSH witch is normally disabled by default.

Now just eject the SD card and place it into your Pi Zero.

Connecting to the Pi via USB

With the SD card installed, connect the Pi Zero W to your computer using a micro USB cable.

You will want to plug the small end into the port labelled USB. It may take 2 minutes to install drivers for the USB Ethernet device.

Now you can SSH into the Pi using a program like PuTTY.

  1. Select SSH as the Connection type and use raspberrypi.local as the Host Name.
  2. Click Open
    • The first time you do this it will ask you to generate a key, just click OK or Yes to do so.
  3. For login as: enter pi
  4. the password should be raspberry

Note: If you can not connect, make sure that the Micro USB cable is connected to the port labeled USB and not PWR. Also ensure that the other end of the USB cable is plugged into a USB port on your computer and NOT connected to a USB Hub. If you continue having trouble with a Windows computer, try installing Bonjour Print Services.

Let’s Get Some Internet

Before we can start installing stuff, we need to get the Pi onto the internet.

From the SSH window that you just opened, run the following command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

This will open the network configuration file so we can add our WiFi user name and password.

Add the following to the end of the file:

network={
    ssid="HomeOneSSID"
    psk="passwordOne"
    priority=1
    id_str="homeOne"
}

network={
    ssid="HomeTwoSSID"
    psk="passwordTwo"
    priority=2
    id_str="homeTwo"
}

Replace the quoted text with relevant information then save and close the file.

Run sudo reboot to restart the Pi and connect to the internet.

You will have to restart your SSH connection and login to the Pi like before.

Now run the command ping google.com in your reopened SSH window.

If all goes well you should get some Data that looks like this:

pi@raspberrypi:~ $ ping google.com
PING google.com(sea15s08-in-x0e.1e100.net (2607:f8b0:400a:804::200e)) 56 data by tes
64 bytes from sea09s17-in-x0e.1e100.net (2607:f8b0:400a:804::200e): icmp_seq=1 t tl=54 time=13.4 ms
64 bytes from sea09s17-in-x0e.1e100.net (2607:f8b0:400a:804::200e): icmp_seq=2 t tl=54 time=14.1 ms
64 bytes from sea09s17-in-x0e.1e100.net (2607:f8b0:400a:804::200e): icmp_seq=3 t tl=54 time=13.4 ms
64 bytes from sea09s17-in-x0e.1e100.net (2607:f8b0:400a:804::200e): icmp_seq=4 t tl=54 time=17.4 ms

This means that the Pi is connected to the internet now and we can start installing stuff. If you do not have connectivity, check the wpa_supplicant.conf settings and ensure that they are correct. Then check your WiFi for network issues.

Time For Some Updates

As always let us start by doing some updating on the Pi. All of this will be done through the SSH window that we are now using to remotely connect to the Pi. It is easy to just copy the commands from this tutorial and right click your mouse in the SSH window to past it there and press the Enter key. Otherwise I hope you are good at typing…

First let us run these two commands:

sudo apt-get update
sudo apt-get upgrade

This will take a few moments depending on how fast your network is. Once the first is finished, press the Enter key to run the next command. You will have to type Yes at the beginning of this one, then go get some coffee or a snack.

Now you are all set to do all kinds of fun stuff with your new $10 computer.