April 7, 2021

Headless Set-up: Raspberry Pi Zero W

This is to document what works for me when setting up a Raspberry Pi headless.  This is by no means the product of my techie know-it-all mind, but rather a mash-up of the resources I gathered in the internet as I explored & struggled the first few times I set up a Raspberry Pi.  There are a lot of mistakes/misinformation out there which threw me off a few times, what I’ve done is merely to filter out the garbage to come up with this mainly for my own guidance & reference.  I’m using a macbook pro with Big Sur & setting up a Raspberry  Pi Zero W (but this guide worked just as well for my RPi 2 & RPi3 model B). 

Format the microSD card with the SD Formatter app (it’s free, & can be found on the SD Association’s website). The app is very straightforward to use.  I prefer the “Overwrite Format” option— “This deletes file/directory entries by initializing file system parameters of the card & erase all data by overwriting the user data area completely.” This option is more thorough, but it’s also much slower.

Download your choice of the official Raspberry Pi OS zipped image from their website— I prefer the Lite version.   There are several ways to flash the RPi OS onto a MicroSD card, you could go all out poser unix-show off & go all the way DD= but if you’re lazy like me—  perhaps the simplest in my experience is to do so by using Balena Etcher.   Following a three-step process, the RPi OS image is easily loaded in 5 minutes tops.  You need not even unzip the file, the app will conveniently do it for you.

Next, we’ll set up the network interface so we can ssh onto the RPi via wireless connection.


$ touch /Volumes/boot/ssh


We also need to define a wpa_supplicant.conf file for our

particular wireless network. Put this file in the boot folder, so

when the RPi first boots, it will copy that file into the correct 

location & use those settings to start up wireless networking.

Open the Terminal & create/edit:


$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


Add the following at the bottom of the file:


country=PH

ctrl interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1


network={

ssid=“your-internet-ssid-name”*

psk=“your-network-password”*

}


SSH is built into the MacOSX so no additional software need to be installed.

On startup, the RPi OS checks the contents of the boot directory, if it detects a wpa_supplicant.conf file, the RPi OS will copy the file into

/etc/wpa_supplicant, replacing any existing wpa_supplicant.conf file that may be there. The file on the boot directory is then deleted.  Likewise, if an ssh file is detected, the RPi OS will adjust it’s settings to accept SSH connections. The ssh file is likewise thereafter deleted. (This means that if something goes wrong we can always get the RPi back onto a wifi network by repeating the steps we’ve taken.)

Specific to the Raspberry Pi Zero W, put the edited SD card into the RPi0w SD slot, plug a Micro-USB power cable into the power port (the one closest to the end of the board). 

Run the following commands on the Terminal:


$ ssh-keygen -R raspberry.local

$ ssh pi@raspberrypi-local


The first command clears out any previous references to raspberrypi.local.  If the RPi did not respond, press Ctrl-C & try the last command again. When the connection works you will see a security/authenticity warning. Type yes to continue. You will see this warning only on the first time you connect.  Next, you will be prompted for the password for the RPi login: the default password is "raspberry". You should now be able to see the RPi prompt.

Proceed to configure the RPi by sudo-ing into raspi-config, then update the RPi OS. Your RPi should be good to go.

No comments:

Post a Comment