Raspberry Pi Zero Headless Setup

01 Dec 2015


Update Mar 2017: Works with the new Pi Zero W!

So last Thursday (26th Nov 2015) the Raspberry Pi Zero was announced and made available that very day. Basically the Zero is a small and ultra cheap (£4) fully functioning Raspberry Pi, but it doesn't have any native networking and has only one USB port (which you need an OTG adapter to use).

In the UK I was lucky enough to be able to order two Pi Zero's and have them delivered the next day. The only problem was I didn't have an HDMI monitor or a USB hub to connect a keyboard and a WiFi adapter at the same time. My intended use for the Zero's is for them to be little headless Linux boxes that I can put into various electronic projects and program them over WiFi (Think IoT), so I didn't want to mess around with HDMI and GUI interfaces.

So here is a little guide showing you how to setup a Raspberry Pi Zero without an HDMI monitor or a keyboard / mouse. We will just use a USB WiFi adapter (connected to the OTG USB port) and a Linux machine to do the setup. If you don't have a Linux machine available, you could even use another Rasberry Pi with a card reader to set this up.

This should be possible to do on other platforms as well but you will need to be able to mount an Ext4 partition natively.

Step One - Install the Linux image

First you will need to install a copy of Raspbian Jessie onto your micro SD card. You can find the downloads here and the installation guides are on the same page as well. For Linux I will be using this guide.

Step Two - Mounting it locally

After you have copied the Raspbian image onto the SD card you will need to mount it to your system. The easiest way to do this is just unplug your card reader and plug it back in.

Once the drive has mounted to your system you will need to find where it has mounted. An easy way to do this is using the command df -h. For me it returns:

Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/fedora_dhcppc8-root   25G  9.8G   14G  43% /
/dev/sda1                        477M  258M  190M  58% /boot
/dev/mapper/fedora_dhcppc8-home   85G   24G   58G  29% /home
/dev/sdc1                         60M   20M   41M  34% /run/media/davidmaitland/boot
/dev/sdc2                         59G  3.4G   53G   6% /run/media/davidmaitland/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202

I can see from this my 64GB SD card is the device /dev/sdc and the boot and main partition are mounted under /run/media/davidmaitland/. Change directory into the main partition as root ready to edit the files. This is likely to be the same drive that was referenced during the image installation earlier.

[user@linux ~]# sudo su
[root@linux ~]# cd /run/media/davidmaitland/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202
[root@linux ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202]# ls
bin  boot  boot.bak  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

Step Three - Configure your WiFi

Next we're going to configure the network interface. Edit the interfaces file etc/network/interfaces. Pay attention to the path in the files I reference, there is no leading slash as you want to edit the files on your SD card and not the ones on your host system!

If you're not sure how to edit files on Linux, try nano etc/network/interfaces then Ctrl + x to save when done.

Find this block in the file:

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then change it to this:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

If you want to have a static IP instead of using DHCP (easier to find once the Pi has come up on your network) then change it to this instead:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address # IP for the Zero
    gateway # Your router IP
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

As pointed out by someone on Reddit, if you're using static networking you will want to setup your DNS servers as well. Edit etc/resolv.conf and add the following:

# Google's public DNS servers

Now let's setup the WiFi connection and passkey. Edit the file etc/wpa_supplicant/wpa_supplicant.conf.

Add this to the end:

  ssid="my network name"
  psk="my network password"

Update (16/02/17)

@stevegraken in the comments pointed out that in newer versions of Raspbian SSH is disabled by default, which is something we will need.

You can read more about this here.

To make it work again you need to create an empty file named ssh in the boot mount. This is a completely different mount point, so you will have to change directories to get there. (Thanks to Chris T for pointing out what I had overlooked)

Here are the results of the command df -h which we ran earlier, you can see the sdc partitions and their corresponding mount points at the bottom:

Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/fedora_dhcppc8-root   25G  9.8G   14G  43% /
/dev/sda1                        477M  258M  190M  58% /boot
/dev/mapper/fedora_dhcppc8-home   85G   24G   58G  29% /home
/dev/sdc1                         60M   20M   41M  34% /run/media/davidmaitland/boot
/dev/sdc2                         59G  3.4G   53G   6% /run/media/davidmaitland/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202

On my system I'm currently on partition 2 (/dev/sdc2) which is mounted at /run/media/davidmaitland/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202 (my current directory). We need to change to partition 1 (/dev/sdc1) by running cd /run/media/davidmaitland/boot.

Now all you have to do is add an empty file named ssh:

touch ssh

Remember to change the default password (use passwd) after you have setup your Pi!

Finally remove the SD card from your computer (you may wish to unmount it first) and place into your Zero.

Step Four - Boot the Pi Zero!

Now it's time to boot the Raspberry Pi Zero. Make sure you have your WiFi adapter plugged into the Zero and give it some power. For me it takes about 45 seconds to boot and connect to my WiFi network.

Now you can SSH directly into your Raspberry Pi Zero!

If you configured your Zero to use DHCP you will need to find it's IP address. There are a few ways you can do this:

  • Most routers will tell you somewhere in their web interfaces what IP allocations they have assigned to devices.
  • You could use nmap to scan the local network for devices running with port 22 open sudo nmap -p22 -sV
  • From the comments Coder-256 pointed out the default hostname for a Raspberry Pi is raspberrypi and on most networks you can SSH directly to this instead of the IP address ssh pi@raspberrypi.local.

The default password is raspberry.

[user@linux ~]# ssh pi@
pi@raspberrypi:~ $


After a new install there are a few things you're probably going to want to do.

First I would update the software running on your Zero:

sudo apt-get update -y
sudo apt-get upgrade -y

If you're going to be using your Zero completely headlessly like me there are various things you can do to save energy and speed up the device.

Boot up into multi-user mode (disable GUI on boot) sudo systemctl set-default multi-user.target.

To disable HDMI edit /etc/rc.local and add the following line at the bottom above exit 0 line:

/usr/bin/tvservice -o

You may want to run sudo raspi-config to change other common Raspberry Pi settings as well.

Let me know below if this guide was useful or if you have any suggestions!

See full post

Simple Arduino LED grow lamp

11 May 2014


I have always loved Arduino’s, but never really had the time to actually do anything useful with them. If you don’t already know what Arduino is:

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. it's intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments.

But I explain them to people as a microcontroller that lets you write code to interact with electronics.

Recently I moved into a new house where we have limited garden space but wanted to be able to grow herbs and various other plants to brighten up the house. The only issue where we had decided to use was a slight lack of light, due to the angles of the building the natural light was only strong enough during mid day.

The only electronics I had was my Arduino Uno, a Luxeonstar Rebel Tri-Star LED and a externally dimmable driver (specifically a Luxeonstar 3023-D-E-700). I’m not going to go into too much detail on the actual setup as I will probably post about this in the future.

Currently you can only specify an on and off time which will dim the LED in/out at these times. Eventually you will be able to specify your location (lon/lat) to which it will calculate the sunrise / sunset times automatically.

You will need both Time.h & TimeAlarms.h libraries for this to work.

But basically you will need to connect pin 11 (or any PWM pin) to the Ctrl wire on the LED driver and the Ref wire to the Gnd on the Arduino.

I have no RTC (real time clock) for my Arduino so the time is set in the code of the Arduino, this means you will have to reprogram it each time you restart the device which is a pain! You may want to look at getting one of these Sparkfun RTC modules.

You will see this line in the code for setting the date & time.

// Set time to start the clock here

The format is (hr, min, sec, day, month, yr).

Latest code can be found over on my GitHub, this will allow me to update it and add more features over time.

Let me know if you have any suggestions!

See full post

Hello World

22 Apr 2014

Hey there! Welcome to my new website & blog that I'm going to be using for the foreseeable future (Until I decide to change it all again).

I used to use Wordpress for my previous blog, but due to the slowness and the security concerns I decided to go with something else, and as nowadays static sites are all the rage that's what I wanted to use.

My new site is built using Jekyll, Bootstrap for the framework and my own theme to make it my own.

It's likely I will put the theme up on my GitHub for anyone to use and copy, but first I need to tidy it up a little. I'm also going to write about how I got Jekyll to do most of the things I needed.

BTW: You may find more posts pop up going back over time as I bring them over from my old blog (Don't worry it's not time travel).

See full post