Headless Setup of the Raspberry Pi Zero W





The new Rapberry Pi Zero W released last month is a major step forward for so-called “headless” or standalone controllers. However, order to get a Zero W up and running is not quite as simple as it could be. This is because in order to activate the Wi-Fi connection, the simplest way is to use a keyboard, mouse and screen which potentially defeats the object of the Zero W!

This brief tutorial describes a completely headless setup that does not require the extra hardware and can be performed over the local Wi-Fi network.

The setup comprises 5 simple steps:

  1. Download the latest Raspian Image
  2. Flash the modified Raspian image to SDHC
  3. Modify the boot code (don’t worry – its not complicated!)
  4. Boot the Pi Zero W
  5. Connect to the Zero W using ssh over the local WiFi network

You will need a micro SDHC card with at least 8GByte capacity, we suggest a fast 16Gbyte card rated at Class 10 minimum.

Raspian Image Download

The instructions found in the MagPi magazine suggested downloading the full Raspian PIXEL image. This is not necessary as it assumes that you will use the graphical interface to perform setup. We suggest that for headless applications the latest Raspian JESSIE LITE zip image is sufficient, download it from HERE.

Expand the zip file into a separate folder, we suggest using 7zip but your favourite application should suffice.

Flash the image files to SDHC

The expanded image file should now be flashed into the micro-SDHC. for this we recommend Etcher which makes the job very easy and clear. Etcher can be downloaded HERE. Start Etcher and select the image file, in our case it was “2017-02-16-raspbian-jessie.img”. Select the SDHC card which Etcher should have identified for you – CAUTION: make sure that you select the correct card as it willbe completely over-written. Check all is correct then click “FLASH”. This process can take several minutes so go get a cup of tea. Etcher will flash and verify the file, reporting any errors encountered. Remove the SDHC card. Etcher should have unmounted (ejected) the SDHC, if it has not, make sure that you remove it safely.

Modify the Boot Code

In order to make the Pi start up and use ssh and WiFi, 2 additional files are necessary on the SDHC, “ssh” and “wpa_supplicant.conf”. The file “ssh” need be nothing more than a name, the conf file needs some additional information, though. The ssh file is a switch that tells the pi to setup to use ss at first boot, once set up the file is deleted and ssh is permanently enabled. These files should be written to the “/boot” partition on the SDHC in the following manner. Remount the SDHC card using file explorer, navigate to the root of the SDHC, you should see just one partition/folder (on a Windows PC) labelled “/boot” containing¬† several files and folders. right click on the folder list and select “new”, then “Text Document”. Simply change the name of the file to “ssh” (with no suffix) and leave it at that.

The “wpa-supplicant.conf” file needs to be copied from a working Raspberry Pi unit using WiFi. Typically its contents will look like:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="your-wifi-ssid-goes-here"
psk="your-wifi-password-goes-here"
key_mgmt=WPA-PSK
}

Replace the ssid, psk and country fields with the data appropriate to your Wifi network. You can attempt to generate this file yourself using a plain text editor if you wish but no guarantees that it will work. The best way is to copy a known working copy from /etc/wpa/wpa_supplicant/wpa_supplicant.conf on a known working Pi SDHC card. Again, save the file to the “/boot” folder on the SDHC card being prepared. Unmount the SDHC card and remove it to the target Raspberry Pi Zero W.

Boot your Pi Zero!

Once you have fitted your newly prepared SDHC card to your Pi, plug in a suitable USB power supply (5 Volts at minimum 1 Amp) and switch on! After about 30 – 45 seconds, your Raspberry Pi Zero W should be connected to the network and visible. IMPORTANT: make sure tha there are no other hosts on your network with the hostname “raspberrypi” as this will confuse the DHCP system. The pi should have acquired an IP address on the network using DHCP. In order to communicate with the Pi, we need to ascertain what this address is. In our case, our (Netgear) router has the facility to look at the DHCP allocation table. Yours should have a similar facility. Log into the router and find the allocation table, sometimes called “connected devices”. Your Pi should be listed with the hostname “raspberrypi”. Make a note of the IP address allocated, usually something like “192.168.0.XX”. If you cannot see it at first, wait a while and perform a refresh.

You should now be able to communicate with your Pi using an ssh client such as “PUTTY” for Windows or by using the ssh command from the command line in a Linux terminal. Log in using the username pi and the password raspberry.

Connect and Setup your Pi Zero!

Once you are connected, it is wise to change the password for user pi, particularly if it is to be visible on the internet. Choose a strong password and use the “passwd” command to effect this.

You may also want to perform other setup options using the raspi-config command. We usually change the hostname as well as we have several pi’s in our network oven at once.



Posted in raspberry pi, tutorial | Tagged , , | 1 Comment