The Raspberry Pi Zero’s small size isn’t the only thing that makes it an awesome single board computer. Thanks to its ability to be recognized as a USB/Ethernet gadget, you can connect to your Pi from another computer via USB. Power is provided over USB, and your computer’s internet connection is shared over USB too. You no longer need to use a power cord and ethernet cable or WiFi adapter to access your Pi. All that’s needed is a micro USB to USB adapter.
In the past, a serial debugging adapter was needed to configure the Pi as a USB/Ethernet gadget, but with Raspbian Jessie 5-10-16 or later, all you need to do is edit a couple files on the SD card.
This tutorial is based in Windows. You’ll need to install a program called Bonjour on your computer before you can connect to the Pi over USB. Bonjour allows your computer to automatically recognize USB and ethernet devices like printers, scanners, and in this case the Raspberry Pi. Bonjour is packaged with iTunes and Adobe CS software, so it might already be installed on your computer. If it’s not though, you can download and install the stand-alone software here.
This tutorial assumes that you have the SSH client PuTTY already installed on your computer.
Here’s the video version of the tutorial:
Edit the config.txt and cmdline.txt Files
To get started, burn a fresh image of Raspbian Jessie Full or Lite (version 5-10-16 or later) to a micro SD card on your laptop/desktop (see our tutorial How to Set Up a Raspberry Pi Without a Monitor or Keyboard if you need help with this step):
Once that’s finished, navigate to the root directory of the micro SD card (i.e. boot(E:)) and open the file config.txt with Wordpad. Using Notepad to edit the file will make it hard to tell where the line breaks are, and this file uses line breaks to separate the commands. Scroll down to the bottom of the file and add dtoverlay=dwc2 to a new line:
Save and exit the config.txt file.
Now open the cmdline.txt file with Notepad. Make sure “Word Wrap” is off to view the file as a single line. You don’t want to add any line breaks to this file. All of the commands need to be in a single line. If you use Wordpad to edit this file, you may create unintentional line breaks, so using Notepad is best. Scroll across the line and find the command rootwait. After the rootwait command, add modules-load=dwc2,g_ether:
Save and exit the cmdline.txt file.
Now you can eject the SD card from your computer.
Insert your SD card into the Pi Zero, and plug your micro USB to USB adapter (or cable) into the Pi’s micro USB port (not the power connection), and the other end into your computer:
You’ll see that Windows recognizes the Pi, and will attempt to setup the device:
At this point, open PuTTY and try SSHing into the Pi with the address raspberrypi.local:
If you can log in to your Pi at this point, that’s good. You can skip the next section, “Install the RNDIS Drivers” and go to the “Setting Up Shared Internet Access” further below.
If you do get an error message saying something like “Unable to open connection to raspberrypi.local. Host does not exist”, you’ll just need to install the RNDIS drivers on your computer. I’ll explain how to do this in the next section:
Install the RNDIS Drivers
With your Pi Zero still connect to your computer, navigate to the Windows Device Manager. Under “Other devices” find “RNDIS/Ethernet Gadget”, and right click on it. Then click “Update driver software” from the menu:
In the next window, select “Browse my computer for driver software”:
Now click “Let me pick from a list of device drivers on my computer”:
Scroll down the list and select “Network adapters”, then click Next:
Now scroll down the “Manufacturers” list in the window on the left, and select “Microsoft”. Then scroll down the “Network Adapters” list on the right side window until you find a line that says “Remote NDIS Compatible Device”. Select that, then click Next:
A warning will pop up about Windows not being able to verify the driver, but just click “Yes” to get past it:
After the driver is finished installing, you should see something like this:
Now try to log into your Pi with PuTTY using the address raspberrypi.local. You should be able to get in:
At this point, you should run sudo raspi-config to expand the file system. When that’s done, reboot the Pi with sudo reboot.
After the reboot, if you log back in with PuTTY you can check to see if it has internet access by entering sudo ping www.google.com at the command prompt. You will probably get an error that says “ping: unknown host www.google.com” or something similar. In the next section, I’ll show you how to give the Pi access to your computer’s internet connection.
Setting Up Shared Internet Access
To share your computer’s internet connection with the Pi, we need to allow network sharing on one of your computer’s network connections.
With your Pi Zero plugged in and powered on, navigate to the “Network Connections” window:
Your Pi will show up as a separate network connection. It will say “RNDIS/Ethernet Gadget” under the connection name. In my case, it’s “Ethernet 2”.
Now you should decide which connection you want your Pi to access the Internet over (i.e. WiFi or Ethernet). I want my Pi to access the internet over my computer’s WiFi connection, so I’ll need to enable my WiFi connection to allow sharing. Right click on the connection you want to use, then select “Properties”:
In the WiFi Properties window, click on the “Sharing” tab:
Click the box that says “Allow other network users to connect through this computer’s Internet connection”, then click the drop down menu below that. Find the network connection given to your Pi (Ethernet 2 in my case), select it, then click OK:
The network you chose to share access with your Pi will show the name of your WiFi network, followed by “Shared” in the “Network Connections” window :
Now reboot your Pi and log back into it with PuTTY.
Enter ifconfig at the command prompt, and you should see a usb0 connection showing TX and RX packets being sent and received:
Enter sudo ping www.google.com to test the connection further, and you should see that your Pi has internet access!
If you want to access the Raspbian Desktop, you’ll need to install an RDP (remote desktop protocol) client first. I like XRDP, but there are several others you can use depending on your preference. To install XRDP, enter sudo apt-get install xrdp at the command prompt. After the installation is finished, reboot the Pi.
Now you should be able to access the Raspbian Desktop with the Windows “Remote Desktop Connection” utility by logging in with the address raspberrypi.local:
Setting up your Raspberry Pi Zero as a USB/Ethernet gadget will let you get internet access and power over a single USB connection. Just plug it into your computer and you’re ready to go. It makes the Pi extremely portable, as there’s no need to carry around a power cord and ethernet cable or WiFi adapter. This is by far the easiest and most convenient way to access your Pi!
I hope you found this article helpful and were able to set it up! Let us know in the comments if you have any questions or problems, and be sure to subscribe to Circuit Basics if you want to get more articles like this!
Free Circuit Design Software: Start to Design your own PCB Easily Cheapest PCB Prototype: Only $2 for 10pcs 100mm×100mm PCBs
Components: Shipping with PCB & Low Minimum Order & Save 50% on Cost