You've successfully subscribed to ilikecalculus
Great! Next, complete checkout for full access to ilikecalculus
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Raspberry Pi Zero W Headless Tutorial

Raspberry Pi Zero W Headless Tutorial

. 4 min read

In this post, we'll go over how to set up a Raspberry Pi Zero Wireless through the terminal. When I was setting this up, I ran into numerous issues and there wasn't a single tutorial that worked for me end to end. I've documented the steps I took, hopefully it helps someone out there with setting up.

For the past two months, I've been running a bot to scrape data on social media platforms. First, I ran the bot on my Digital Ocean server (the same server that hosts this blog), but I quickly got shadow banned. I figured Digital Ocean IPs were easily recognized and mass blocked. As such, I started running it locally on my home laptop, and it's been performing quite well.

After running this for a couple of months, I've been experiencing a couple of inconveniences. For one, I need to leave my laptop on 24/7 just for the bot to run (which is a waste of electricity). The bot is also susceptible to accidentally turning off (moving mouse away from the hot corner) without me noticing, since I dim the screen to total black.

As such, I decided I would get a single board computer. I figured I didn't need a lot of processing power since I'm running mostly a network bound bot. Thus I got the Raspberry Pi Zero W (with wireless). I bought the Pi from Ada Fruit, a case and micro SD card from Amazon.

Bonus circuit photo. On a side note, I've been playing around with macro photography more and randomly took pictures of the circuit board of the Pi.

Since I didn't have extra monitor, mouse or keyboard, I wanted to set up the Raspberry Bi through ssh. Unfortunately, there are no official guides on how to set up a Raspberry Pi without this way. Fortunately, plenty of people have experienced this problem in the past and there are online guides. Even with numerous guides available, it still took me a few hours to set it up completely. Now, I will walk through the steps I took and the troubles I encountered while setting up the Pi. Initially, I followed this guide on github:

  1. Download the operating system image from this link:
  2. Formatted the micro SD card using your choice of tool. This can be used in the built in diskutil tool on Mac:
    diskutil eraseDisk ExFat <name you give to card> <disk number>, example:
    diskutil eraseDisk ExFat temp disk2
  3. Unzip the Raspbian image from the download, mount the image to the SD card:
    sudo dd if=<path to image> of=<disk path>, example:
    sudo dd if=~/Download/2018-11-13-raspbian-stretch-lite.img of=/dev/disk2

After mounting the image, the guide tells us to set up the wifi. I tried the steps, but no matter what I couldn't get my Mac to ssh into the Pi. I encourage people to try setting up the wifi using the steps outlined in the GitHub gist to see if it works for them. However, if it doesn't work, one can try the following steps for an alternative method to ssh into the Pi:

  1. Edit the config.txt file at the root of the mounted drive and add dtoverlay=dwc2 at the bottom of the file
  2. Edit the cmdline.txt file at the root of the mountied drive. Add modules-load=dwc2,g_ether parameter at the end of rootwait parameter.
  3. The Pi by default doesn't enable ssh, so run touch ssh to create an empty ssh file.
  4. After setting up the image, plug the Pi into a computer via the USB port. It's the middle port, it also says "USB" above the port in small white text
  5. ssh into the Pi by executing ssh [email protected]. The default password is raspberry
  6. Once ssh-ed inside the Pi, configure the wifi file, which is located at /etc/wpa_supplicant/wpa_supplicant.conf with your wifi settings:

  1. Test wifi connection by running sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf and see if any errors show up
  2. Configure Pi to permanently allow ssh access by using the raspi-config - sudo raspi-config. Select Interfacing Options, then select SSH, then select YES to enable ssh.
  3. Disconnect Pi from computer, and connect to another power source. Try ssh-ing into the Pi using the ssh [email protected] and it should work.
  4. Update all modules by running sudo apt-get update && sudo apt-get upgrade -y

With the above steps, I was able to successfully set up the Raspberry Pi Zero W with the above steps. I've also included some references on guides and tutorials I followed.