This tutorial was updated on July 4, 2019 to reflect the latest versions of the technologies mentioned.
As some of you may know, I have a hoarding problem. I am hoarding Raspberry Pi microcomputers. In my personal collection I have one from each generation, making four standard units. Well, I recently picked up another unit, but this time a Raspberry Pi Zero. These things are about the size of a nine volt battery, but pack some serious punch. The problem is they are incredibly rare because they retail for only $5.00.
Unlike the standard Raspberry Pi units, these do not have WiFi, ethernet, or standard sized USB ports. This changes things when it comes to connecting. We’re going to take a look at getting set up with one of these Pi Zero IoT devices and be on your way towards some cool hack projects.
Like with the standard Raspberry Pi units, it takes a micro SD card with the same flavors of Linux flashed to it. You’ll note in my other tutorials, I am using Raspbian, which is a flavor of Debian Linux. I am using the same for the Raspberry Pi Zero.
Flash the Pi Zero however you see fit. If you’re using a Mac or Linux computer, you might check out my previous tutorial on the subject.
This is where things get a little different. Before we get ahead of ourselves, a lot of the material that follows will be from a set of instructions that helped me. These instructions can be found on GitHub by Andrew Mulholland.
Our long term goal will be to use SSH over USB. This means that we have to configure Raspbian to treat the USB port like an ethernet port. Mount the micro SD card in a computer (not Pi Zero) and open it with Finder, or Windows Explorer, or whatever it is that you use.
The first thing that you want to do is open a file at the root of the mounted drive called config.txt. In this file you want to add the following line at the very bottom:
The above line will set us up for the next file that we alter. The next file we alter is cmdline.txt, but it is a bit different. Parameters in this file are not delimited by new lines or commas, they are delimited by space characters. In this file we want to add the following:
The above parameter should be added after the
rootwait parameter. Yes the above parameter is a single parameter, meaning don’t add a bunch of space characters to it. More information on networking over USB on Linux can be found here.
By default SSH access is disabled in Raspbian. To enable SSH, create a file called ssh and save it to the root directory of the boot mount on the SD card. The file can be blank, and it has no extensions. It should exist at the same location as the other files that were edited.
At this point the micro SD can be inserted into the Pi Zero.
To connect to the Raspberry Pi Zero over USB you’ll need Bonjour or similar installed on your host computer. I’m using a Mac so I was fortunate enough to already be in the clear. For Windows you should be fine installing iTunes or QuickTime and for Linux the Avahi Daemon. Many Linux distributions should have it already installed.
With it installed, power on the Pi Zero with the USB data cable. I made sure to use the port labeled USB, not PWR. This port allows you to power the Pi Zero and do data transfer. Once connected, give it some time because it will have to configure some things for the first time.
When you feel the Pi Zero is ready, enter the following from your Mac or Linux Terminal:
If you’re using Windows you’ll have to use PuTTY or similar. Notice in my SSH command I provided the pi user? If you’re using Raspbian, it is the only user on a fresh installation. The password will be raspberry until you change it or add a new user.
You should be connected! You won’t be able to install anything or run updates because you’re not connected to the internet, but at least you have full headless Linux control. If you want to be able to access the internet from the Pi Zero without a WiFi module or similar, check out my other tutorial titled, Share Internet Between macOS and a Raspberry Pi Zero Over USB.
Raspberry Pi and IoT is awesome. As a long time Raspberry Pi fanatic, the Pi Zero, if you can get a hold of one, is $5.00 well spent. You get a fast IoT device at the size of a pack of gum. Since the hardware doesn’t have WiFi or BLE, we had to configure Raspbian to allow ethernet emulation over USB. Once we did this we were able to SSH into the Pi Zero as if it was somewhere on our network. A perfect jumpstart for our Internet of Things adventure.
A video version of this article can be seen below.