Skip to content

Instantly share code, notes, and snippets.

@gbaman
Last active May 1, 2024 08:26
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.

@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 pi@raspberrypi.local, 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