Raspberry Pi Zero USB/Ethernet Gadget Tutorial -Posted by Circuit Basics | Raspberry Pi | 55

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.

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):
Raspberry Pi Zero Ethernet Gadget - Writing Raspbian to the SD Card

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:
Raspberry Pi Zero Ethernet Gadget - Using Wordpad to Edit the config.txt File
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:
Raspberry Pi Zero Ethernet Gadget - Use Notepad to Edit the cmdline.txt File
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:
Raspberry Pi Zero Ethernet Gadget - Pi Zero Plugged Into Micro USB Port
You’ll see that Windows recognizes the Pi, and will attempt to setup the device:
Raspberry Pi Zero Ethernet Gadget - Device Setup
At this point, open PuTTY and try SSHing into the Pi with the address raspberrypi.local:
Raspberry Pi Zero Ethernet Gadget - First Putty Attempt
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:
Raspberry Pi Zero Ethernet Gadget - Unable to Open Connection to Host PuTTY Error

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:
Raspberry Pi Zero Ethernet Gadget - Windows Device Manager
In the next window, select “Browse my computer for driver software”:
Raspberry Pi Zero Ethernet Gadget - Update Driver Software
Now click “Let me pick from a list of device drivers on my computer”:
Raspberry Pi Zero Ethernet Gadget - Pick From a List of Device Drivers on My Computer
Scroll down the list and select “Network adapters”, then click Next:
Raspberry Pi Zero Ethernet Gadget - List of device drivers on my computer
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:
Raspberry Pi Zero Ethernet Gadget - Find the Remote NDIS Compatible Devices Adapter
A warning will pop up about Windows not being able to verify the driver, but just click “Yes” to get past it:
Raspberry Pi Zero Ethernet Gadget - Update Driver Warning
After the driver is finished installing, you should see something like this:
Raspberry Pi Zero Ethernet Gadget - Driver Sucessfully Updated
Now try to log into your Pi with PuTTY using the address raspberrypi.local. You should be able to get in:
from: http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget/#
driver: https://www.driverscape.com/download/remote-ndis-compatible-device
software: https://support.apple.com/kb/DL999?locale=en_US