Cute little computer with Wifi access. Easy recipe for a headless install of raspbian lite, without screen and keyboard.
The raspberry pi zero W is certainly the cutest computer ever! It was released in February 2017, and boasts a very important feature with respect to the original raspberry pi zero: it can connect to wifi!
In this post, you will learn how to perform a headless install of the board, which means that you will never use the pi directly. Instead, you will connect remotely through ssh.
The reason why we want to do this is that this very small board only features a few connectors:
And, if you're like me, you don't have the cables needed to connect a screen and a keyboard to the board for a standard installation.
So that's what we are going to do:
But before we get started, here is a bit more information about this board.
The raspberry pi zero W comes in two flavours:
On the left, the pi zero WH has a pre-soldered GPIO header. And as you can see, mine is a standard pi zero W. This version is more suitable to the integration into an electronic circuit, but I'll have to solder the header myself if I want to experiment with a breadboard.
In France, I suggest to get them on kubii (10 euros for the W, 15 euros for the WH). I'm in no way affiliated with them, but they're reliable and have nice products, so they deserve a bit of advertizing!
One thing to keep in mind: the pi zero is just like a pi 3B+, but is much less powerful.
Pi 3 B+ | Pi Zero | |
CPU |
Quad Core
ARM Cortex-A53 |
Single Core
ARM1176JZF-S |
Clock frequency | 1.4 GHz | 1 GHz |
Number of cores | 4 | 1 |
RAM | 1 GB | 512 MB |
Price | 35 euros | 10 or 15 euros |
With its single core and its reduced memory, the pi zero should be dedicated to a single task, which is not too CPU intensive.
For example, I will use mine to monitor the power consumption of my house. Its small size is perfect to fit in the electrical panel, and it won't have much to do:
That being said, let's get started with the install.
This step is well explained in my tutorial about a Fast Minimal Install of a Raspberry Pi . Please follow these instructions and come back here after writing the raspbian lite image to the SD card.
By default, the ssh server is not enabled in rasbian lite, and we do need it to connect to the pi zero remotely later on.
In Fast Minimal Install of a Raspberry Pi, we enabled the ssh server with raspi-config, but this is not possible here as we cannot (or don't want to) connect a keyboard and a screen to the pi zero.
The solution is easy!
After writing the SD card, take it out of the reader and plug it back in so that the boot partition of the SD card is mounted on your computer. Here is what I see on my mac:
On MacOS or Linux, open a terminal and go to the root of the boot partition. Then, do:
touch ssh
This creates an empty file called ssh in this directory, and it's enough to enable the ssh server!
To set up the connection to the wireless network, we will create another file at the root of the boot partition.
Call this file wpa_supplicant.conf and put inside the following contents with your favourite text editor, e.g. nano or emacs:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=FR
network={
ssid="The name of your wifi network"
psk="Your password"
key_mgmt=WPA-PSK
}
Make sure to:
Now unmount (eject safely) the SD card, put it in the pi zero, and plug the power adapter. The pi zero led will start blinking. Give it a bit of time to start its ssh server.
After 30s or so, the pi zero should be connected to your wifi network. But we don't know its IP address! Let's find out.
If your router did its job properly, you should be able to perform a ping with the default raspberry pi host name, which is raspberrypi. I'm of course assuming that you don't already have a raspberrypi host on your network (remember to always give a unique name to your pis).
ping raspberrypi
PING raspberrypi.lan (192.168.86.72): 56 data bytes
64 bytes from 192.168.86.72: icmp_seq=0 ttl=64 time=9.043 ms
64 bytes from 192.168.86.72: icmp_seq=1 ttl=64 time=12.771 ms
64 bytes from 192.168.86.72: icmp_seq=2 ttl=64 time=8.236 ms
64 bytes from 192.168.86.72: icmp_seq=3 ttl=64 time=13.609 ms
64 bytes from 192.168.86.72: icmp_seq=4 ttl=64 time=13.310 ms
64 bytes from 192.168.86.72: icmp_seq=5 ttl=64 time=13.606 ms
64 bytes from 192.168.86.72: icmp_seq=6 ttl=64 time=7.753 ms
Now you know that you can use the default name for ssh, and you know the IP address.
If this does not work, you could go to the administration page of your router to see if a new machine is present. I can't really help you with this.
Finally, you can use nmap. Install this software , open a terminal, and type:
sudo nmap -sP 192.168.1.1/24
I'm assuming that your local network addresses start with 192.168.1, which is usually the case. In my case, they start by 192.168.86, so I typed: nmap -sP 192.168.86.1/24. The /24 means that nmap will scan all addresses, from 192.168.1.0 to 192.168.1.255.
Starting Nmap 7.70 ( https://nmap.org ) at 2019-09-06 08:14 CEST
Nmap scan report for rasphome.lan (192.168.86.58)
Host is up (0.013s latency).
MAC Address: B8:27:EB:DF:23:16 (Raspberry Pi Foundation)
Nmap scan report for raspower.lan (192.168.86.122)
Host is up (0.13s latency).
MAC Address: B8:27:EB:A5:18:1E (Raspberry Pi Foundation)
Nmap scan report for 192.168.86.123
Host is up (0.13s latency).
...
Nmap scan report for raspberrypi.lan (192.168.86.131)
Host is up (0.14s latency).
MAC Address: B8:27:EB:9C:A5:84 (Raspberry Pi Foundation)
Nmap scan report for lyocms23.lan (192.168.86.124)
Host is up.
Nmap done: 256 IP addresses (12 hosts up) scanned in 5.15 seconds
With this information, you should be able to find the IP address of your pi zero.
Connect to the pi via SSH:
ssh pi@<raspberrypi, or IP address>
Use the default raspberry pi password, which is raspberry .
We will configure the machine with raspi-config:
sudo raspi-config
In Localisation Options:
Go back and go to Network Options:
Go back and change the User password. That's important, you don't want to use the same password as everybody else!
You can now exit raspi-config and reboot. After reboot, you'll have to reconnect with ssh, using the new hostname.
Finally, let's upgrade the system
sudo apt update
sudo apt upgrade
And, if you want, you can install the packages you need, e.g. :
sudo apt install xterm emacs git dbus-x11
In this post, you have learnt:
Get ready for more IOT tutorials :-)
Please let me know what you think in the comments! I’ll try and answer all questions.
And if you liked this article, you can subscribe to my mailing list to be notified of new posts (no more than one mail per week I promise.)
You can join my mailing list for new posts and exclusive content: