Skip to content

Instantly share code, notes, and snippets.

@gbaman
Last active October 31, 2024 23:33
Show Gist options
  • Save gbaman/975e2db164b3ca2b51ae11e45e8fd40a to your computer and use it in GitHub Desktop.
Save gbaman/975e2db164b3ca2b51ae11e45e8fd40a to your computer and use it in GitHub Desktop.
Simple guide for setting up OTG modes on the Raspberry Pi Zero, the fast way!

Setting up Pi Zero OTG - The quick way (No USB keyboard, mouse, HDMI monitor needed)

More details - http://blog.gbaman.info/?p=791

For this method, alongside your Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh in the SD card as well. By default SSH is now disabled so this is required to enable it. Remember - Make sure your file doesn't have an extension (like .txt etc)!
4. Finally, open up the cmdline.txt. Be careful with this file, it is very picky with its formatting! Each parameter is seperated by a single space (it does not use newlines). Insert modules-load=dwc2,g_ether after rootwait. To compare, an edited version of the cmdline.txt file at the time of writing, can be found here.
5. That's it, eject the SD card from your computer, put it in your Raspberry Pi Zero and connect it via USB to your computer. It will take up to 90s to boot up (shorter on subsequent boots). It should then appear as a USB Ethernet device. You can SSH into it using raspberrypi.local as the address.

@Reloecc
Copy link

Reloecc commented Jan 24, 2019

My Raspberry Pi Zero W was detected as "serial device", not a RNDIS Gadget adapter, got it fixed by installing the

Acer Incorporated. - Other hardware - USB Ethernet/RNDIS Gadget | Windows 7,Windows 8,Windows 8.1 and later drivers | Drivers (Other Hardware) | 13.01.2010 | 1.0.0.0 | 21 KB

from http://www.catalog.update.microsoft.com/Search.aspx?q=USB%20RNDIS%20Gadget

@leadVisionary
Copy link

(5)- From Linux computer:
Open the nm-connection-editor (from the panel).
Select Wired connection 2 (RasPi on USB) & click Edit.
Under 'IPv4 Setting' set 'Method' = 'Shared to other computers'. <<< IMPORTANT!

Just an update for anyone struggling with this for hours in 2019, like I just was, the Method = "Shared with other computers" is pretty important on Ubuntu. I watched guide after guide, but this was crucial.

@vpatron
Copy link

vpatron commented Apr 6, 2019

Actually, I found it better to set it to "Link-Local Only". In Linux go to the network connections editor and in the "IPv4 Settings" tab, set Method: to "Link-Local Only". This was the only setting that let me do ssh [email protected]. Once I was on the Pi Zero console, I could access the internet. This was on a Pi Zero (non-W) so it was getting internet of the PC over the USB.

@erichiggins
Copy link

As others have stated, I also could not get this working with Raspbian Stretch Lite on a Pi Zero W. Would love to get some help.

@scootergarrett
Copy link

I had this working with the pi zero W and stem. But now im getting the same 'Connection refused' after updating.

@scootergarrett
Copy link

scootergarrett commented May 5, 2019

I might be wrong but to access the pi the SSH using the pi stem (https://www.sparkfun.com/products/14526) should not require any internet, therefor the IP address is irrelevant?

@danieldiasm
Copy link

I have a solution for Windows 10 . the driver is on in my website : [http://domotique.caron.ws/cartes-microcontroleurs/raspberrypi/pi-zero-otg-ethernet/]

Sorry for my english :(.

Merci! Merci beaucoup!!

Le noveau link -->> [https://caron.ws/diy-cartes-microcontroleurs/raspberrypi/pi-zero-otg-ethernet/]

@t56k
Copy link

t56k commented Nov 7, 2019

Also Pi 4 has some different defaults, so comment out the preceeding block:

image

Delete/comment out those top two lines.

@uxhamby
Copy link

uxhamby commented Nov 29, 2019

@Graham6846
Copy link

Has anyone managed to get the Wifi &/or Blue Tooth working on the new RaspberryPi Zero W
I certainly haven't and have followed every piece of advice I can read - PiHut says Sorry don't know how??

@ChildishGiant
Copy link

I've tried all the drivers in the world but my pi zero keep showing up as a COM device and not as an ethernet device.

@jdoubleu
Copy link

I found a fix for the Windows 10 driver issue: https://gist.github.com/jdoubleu/048bd96971164ada3737e0964bb810f3

@freemansoft
Copy link

freemansoft commented Nov 27, 2020

Windows users should be able to use the powershell script here https://github.com/freemansoft/pi-ethernet-gadget to make the changes to a fresh SD card that can then be inserted into a Pi Zero W. I tested with the current latest Windows 10

@ieee488
Copy link

ieee488 commented Feb 19, 2021

I've tried all the drivers in the world but my pi zero keep showing up as a COM device and not as an ethernet device.

I am running latest Windows 10 v20H2.
The RNDIS driver was there when I clicked on Optional drivers when I ran Check for Updates. It is an Acer driver.
https://www.catalog.update.microsoft.com/Search.aspx?q=USB+RNDIS%20Gadget

.

@radavis
Copy link

radavis commented May 5, 2021

Hardware: Pi Zero w/o WiFi, Pi Zero USB Stem (Adafruit)
Pi OS: 2021-03-04-raspios-buster-armhf-lite.img
Host OS: Ubuntu v20.10 (Groovy Gorilla)

I needed to perform a few more steps to ssh into the Pi.

After waiting for the Pi to boot...

  1. run nm-connection-editor from the Host OS
  2. select the appropriate "Wired connection #" under Ethernet, then click the gear. (device name will be something like enxbed891078ed1)
  3. select "IPv4 Settings", then Method: "Link-Local Only"
  4. run ssh [email protected], password: raspberry

It still amazes me that its possible to get a Pi up and running without a keyboard and mouse.

@ieee488
Copy link

ieee488 commented May 5, 2021

Hardware: Pi Zero w/o WiFi, Pi Zero USB Stem (Adafruit)
Pi OS: 2021-03-04-raspios-buster-armhf-lite.img
Host OS: Ubuntu v20.10 (Groovy Gorilla)

I needed to perform a few more steps to ssh into the Pi.

After waiting for the Pi to boot...

  1. run nm-connection-editor from the Host OS
  2. select the appropriate "Wired connection #" under Ethernet, then click the gear. (device name will be something like enxbed891078ed1)
  3. select "IPv4 Settings", then Method: "Link-Local Only"
  4. run ssh [email protected], password: raspberry

It still amazes me that its possible to get a Pi up and running without a keyboard and mouse.

I am curious whether you are able to SSH into a 2nd Raspberry Pi Zero.
I found that if I connect two Pi Zero, only the first one is accessible using .local addressing.
I run Linux Mint 20.1

@radavis
Copy link

radavis commented May 11, 2021

I am curious whether you are able to SSH into a 2nd Raspberry Pi Zero.
I found that if I connect two Pi Zero, only the first one is accessible using .local addressing.

The default hostname for the pi is raspberrypi. If you plug in two devices without changing the defaults, you will have two devices with the same hostname. The Host OS will not be able to differentiate between them. Use IP addresses instead of the hostname, or change the hostname of each device through raspi-config.

@ieee488
Copy link

ieee488 commented May 11, 2021

I am curious whether you are able to SSH into a 2nd Raspberry Pi Zero.
I found that if I connect two Pi Zero, only the first one is accessible using .local addressing.

The default hostname for the pi is raspberrypi. If you plug in two devices without changing the defaults, you will have two devices with the same hostname. The Host OS will not be able to differentiate between them. Use IP addresses instead of the hostname, or change the hostname of each device through raspi-config.

I did change the hostname.
Whichever Pi is plugged in first is the only one with which the local addressing will work.
I am just wondering if anyone has run into this.

.

@keo
Copy link

keo commented Aug 28, 2021

Trying to do this on a Macbook Air with Apple Silicon. The RNDIS Gadget doesn't show up anywhere (tried in Network preferences and also in System Information).
Also tried g_serial - doesn't show up as well.
Any ideas?
Thank you.

@kid1412-net
Copy link

kid1412-net commented Nov 21, 2021

Hello everyone,

Somehow my Rasperry Pi Zero is messed up with my Fedora 34 running on my Dell Latitude laptop.

The error is like this

[liveuser@localhost-live ~]$ avahi-browse -art
+ enp0s20f0u1 IPv6 DE85DEC0B0C5@Kodi (retropie)                  _raop._tcp           local
+ enp0s20f0u1 IPv6 Kodi (retropie)                               _xbmc-jsonrpc._tcp   local
+ enp0s20f0u1 IPv6 Kodi (retropie)                               _xbmc-events._udp    local
+ enp0s20f0u1 IPv6 Kodi (retropie)                               _xbmc-jsonrpc-h._tcp local
+ enp0s20f0u1 IPv6 Kodi (retropie)                               _http._tcp           local
+ enp0s20f0u1 IPv6 RETROPIE                                      _device-info._tcp    local
+ enp0s20f0u1 IPv6 RETROPIE                                      _smb._tcp            local
Failed to resolve service 'DE85DEC0B0C5@Kodi (retropie)' of type '_raop._tcp' in domain 'local': Timeout reached
Failed to resolve service 'Kodi (retropie)' of type '_xbmc-jsonrpc._tcp' in domain 'local': Timeout reached
Failed to resolve service 'Kodi (retropie)' of type '_xbmc-events._udp' in domain 'local': Timeout reached
Failed to resolve service 'Kodi (retropie)' of type '_xbmc-jsonrpc-h._tcp' in domain 'local': Timeout reached
Failed to resolve service 'Kodi (retropie)' of type '_http._tcp' in domain 'local': Timeout reached
Failed to resolve service 'RETROPIE' of type '_device-info._tcp' in domain 'local': Timeout reached
Failed to resolve service 'RETROPIE' of type '_smb._tcp' in domain 'local': Timeout reached

You guy could try to reset the USB port and it worked again!!!

sudo ./usbreset /dev/bus/usb/001/044

usbreset program can be found at here

==================================================

Since above method uses "Link-Local Only" and I couldn't get Internet access from my Pi Zero v1.3 (2005), no Wi-Fi running on Debian 10 (Buster).

I found another method to use IPv4 only and finally got Internet access from Pi Zero!!!

Firstly, just add the following line after rootwait in /boot/cmdline.txt

modules-load=dwc2,g_ether ipv6.disable=1

Of course, the /boot/config.txt file should be updated as the first post.

Secondly, use option "Shared to other computers" in IPv4 tab of USB Ethernet setting. To get the IP address of Pi Zero, just use this command

arp -a

The result may be this

[liveuser@localhost-live ~]$ arp -a
.
? (10.42.0.229) at <incomplete> on enp0s20f0u1

Thirdly, on Linux machine, please use this command to enable Pi Zero Internet access

echo 1 > /proc/sys/net/ipv4/ip_forward

Finally, you can SSH to Pi Zero by using direct address

ssh pi@[PI_ZERO_IP]

Happy hacking!!!

Note: Actually, I'm not sure this whether arp command affects by avahi-tools or not, you guy could try to use "Link-Local Only" option first and then "Shared to other computers" option later!!!

References:

My retropie's information

pi@retropie:~ $ uname -a
Linux retropie 5.4.72+ #1356 Thu Oct 22 13:56:00 BST 2020 armv6l GNU/Linux

pi@retropie:~ $ cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

pi@retropie:~ $ cat /proc/cpuinfo 
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 997.08
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2835
Revision	: 900093
Serial		: 0000000033297549
Model		: Raspberry Pi Zero Rev 1.3

@kid1412-net
Copy link

@keo

You could try this way. I'm sorry I don't have M1 Macbook.

image

The reference link is

@theGOTOguy
Copy link

@radavis

run nm-connection-editor from the Host OS
select the appropriate "Wired connection #" under Ethernet, then click the gear. (device name will be something like enxbed891078ed1)
select "IPv4 Settings", then Method: "Link-Local Only"
run ssh [email protected], password: raspberry

Thank you! This is what needed to happen to get my pi to connect under Ubuntu.

@muenchris
Copy link

On Windows you have to install the "USB Gadget" driver to be able to see the PI in dwc2 mode.
But that driver is just mapping the USB VID/CID/Class to the already existing RNDIS driver preinstalled in Windows since Windows 7.
If the PI would expose the HW ID: USB\Class_EF&SubClass_04&Prot_01 there would be no need to any additional driver.
Does anybody have an idea how to change the USB Class on the PI to this?
One usecase is very simple: With this change the PI would work with the Hololens2 that does not allow installing any new driver - including the "Gadget" Mapper .INF

@quincy451
Copy link

quincy451 commented Oct 11, 2022 via email

@freemansoft
Copy link

My Raspberry Pi Zero W was detected as "serial device", not a RNDIS Gadget adapter, got it fixed by installing the

It looks like you can do this now using the windows optional updates which offer up the Acer driver. https://joe.blog.freemansoft.com/2022/11/installing-rndis-driver-on-windows-11.html

@mgmalheiros
Copy link

It is important to note that since the April 2022 update, there is no longer a default user and password on Raspberry Pi images.

So you must define the user and password prior to the first headless boot (either using the imager tool or by editing the boot files). Details on how to do this:

https://www.raspberrypi.com/news/raspberry-pi-bullseye-update-april-2022/

@Soily
Copy link

Soily commented Feb 5, 2023

I just tried it with a fresh image from today but for me it doesn't work. The windows host is not recognizing anything on the usb port where I stucked in the raspberrypi. Any ideas or has somebody observed the same issue?

@Soily
Copy link

Soily commented Feb 5, 2023

Hi again.
I found the issue (it's always in front of the PC ;-)).
The housing is not compatible. It has an own usb-c-power connection without datalines on it.

Sorry.

@therandomspoon
Copy link

i am having a error with my raspberry pi zero w where i am using Raspberry Pi OS lite and the pizero usb stem but it is not showing up in my device manager or anything

@greeneggsandmushrooms
Copy link

hit the windows key and type view optional updates. choose that and dropdown the menu and choose the one with RNDIS, install it, done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment