Вы находитесь на странице: 1из 72

3/1/2018 Raspberry Pi Zero – Programming over USB!

(Part 2) | Andrew's blog

Andrew's blog

RASPBERRY PI, UNCATEGORISED

RASPBERRY PI ZERO – PROGRAMMING OVER


USB! (PART 2)
19TH MAY 2016 | GBAMAN | 258 COMMENTS

This is a follow on post from the older, more detailed documentation in an earlier post.

Summary
An extremely simple new way to setup Raspberry Pi Zero as a USB virtual network gadget, allowing
SSH, SFTP, VNC etc over a single USB cable. All without need of a keyboard, mouse, screen etc to
setup!
To make it clear though, this can only work with the Raspberry Pi Zero.

Quick history lesson


https://blog.gbaman.info/?p=791 1/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

So back over Christmas 2015, I had worked on getting the Raspberry Pi Zero OTG/Slave USB mode
working and documented. My work was based off the excelent work done by awesome volunteers from
the Raspberry Pi community here and here.
Back then, it required you have a screen, keyboard, mouse and internet connection to set everything up
from a stock Raspbian image. This was a bit of a pain if all you had was your normal Windows/Mac/Linux
computer with downloaded Raspbian, an SD card, Pi Zero and a USB cable.

Then, with the  2016-05-10 release of Raspbian, the required modules and kernel version were included
on the stock Raspbian images, but they still required con guring. At least all this could be done with a
screen and keyboard plugged into the Pi Zero (no internet required).

Now, after a heck of a lot of Linux Kernel documentation digging/hunting around, I have stumbled
across what seems to be a very little known kernel cmdline parameter. This parameter allows us to do all
the con guration on the /boot partition, which is formatted FAT32 and readable on
Windows/Mac/Linux (vs normal root partition only being readable with Linux).

What does this mean?


You can now set up a virtual network connection between your Raspberry Pi Zero and normal PC using
a single USB cable in a matter of seconds, without the need for any extra hardware!
No need for an HDMI screen, keyboard, mouse etc, all with stock Raspbian Jessie lite or full.
You can then SSH into the Raspberry Pi Zero, copy les with SFTP or use VNC (extra installation
required).

How do I set it up?


Setup is super simple! Once you have ashed your Raspbian image, should take only a few minutes to
set it up! See guide below.

###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 -

https://blog.gbaman.info/?p=791 2/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

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.

HowToOTGFast.md hosted with by GitHub view raw

G_ETHER G_MASS_STORAGE G_SERIAL OTG PI RASPBERRY USB ZERO

258 THOUGHTS ON “RASPBERRY PI ZERO – PROGRAMMING OVER USB! (PART 2)”

Vincent Willcox
19TH MAY 2016 AT 8:33 PM

Nice work.I’ll be playing with this later.

David Ferguson
19TH MAY 2016 AT 11:43 PM

This looks really great! Just one question – you used the g_ether module in your guide above; could
other modules (such as g_serial or g_mass_storage) be implemented in this way?

Graham Toal
20TH MAY 2016 AT 4:53 PM

Does this only work on the zero or can it work with any Pi?

Connecting over USB networking ‘out of the box’ was always the big advantage that the Beaglebone
had over the Pi…

 gbaman
21ST MAY 2016 AT 12:17 PM

https://blog.gbaman.info/?p=791 3/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

This can only work with the Raspberry Pi Zero, given USB is directly connected to the processor,
where as the larger Pis it goes via the LAN hub chip. A and A+ are missing the ID pin so can’t
dynamically detect USB master or slave, so defaults to master.

Pablo Rogina
20TH MAY 2016 AT 6:01 PM

Great work!
Is it possible to use this same approach with RPi 2/3?

 gbaman
21ST MAY 2016 AT 12:18 PM

Nope, see http://blog.gbaman.info/?p=791#comment-136188

Greg Zoll
20TH MAY 2016 AT 7:02 PM

I wonder if this will work with the other Pi units. It would be really handy when working with Micro-
Controllers and cannot get to the board easily. It would make mass setup of a bunch of units easier.

 gbaman
21ST MAY 2016 AT 12:19 PM

Nope, see http://blog.gbaman.info/?p=791#comment-136188

Ted
20TH MAY 2016 AT 7:58 PM

I seem to be having a senior moment here, which, due to my age is appropriate.

My main computer runs Windows 10. I’ve got the PiZero plugged into one of the USB ports using a
micro usb male to normal usb male plug. I put the micro end into the non-power port, the one
closest to the HDMI plug.

The lights are on … but nobody seems to be home.

When I use putty (port 22) to connect to raspberrypi.local it doesn’t nd anything.

Obviously user error. Any ideas?

https://blog.gbaman.info/?p=791 4/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

tia,
Ted

 gbaman
21ST MAY 2016 AT 12:19 PM

Did you make sure to install Bonjour? Is required for using raspberrypi.local.

Ted
23RD MAY 2016 AT 8:31 PM

I checked out the task manager and Bonjour Services are running. I rebooted the box and still
no joy.

I am going to try some different cabling combinations.

I hope to nd a direct USB OTG male (connect to PIZero non-power port) to USB male (connect
to a usb port on my PC).

Thanks for trying to help me out.


Ted

Adam Kurowski
24TH MAY 2016 AT 10:09 AM

Same problem here.


Windows 10. Image ashed ,con g and commandline updated, after start no connection.
Ipcon g on windows don’t show anything :/

It seems I’ll have to buy mini hdmi cable after all ( or wi dongle)

Neil Wallace
3RD JUNE 2016 AT 12:02 PM

Ted
I also spent quite some time on trying to set this up!
Problem 1 – just could not see the using boot directory, con g,txt or cmdline.txt les in my Win
10 File Explorer; so I had to set up the keyboard/TV again so that I could access the Zero boot
directory, and then alter the two les using the terminal and “sudo nano con g.txt”. Save, reboot,
and dismantle, then back to the USB plugin on my Win 10 laptop

https://blog.gbaman.info/?p=791 5/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Problem 2 – ddling around with Device Manager to work out which update to give the “yellow
triangled Ethernet device” but eventually, it came up as a working USB.
And then the Zero worked as a plug in USB over PuTTy.

So maybe not quite the ‘super simple’ setup young Andrew writes about !! But hey! got there!

 gbaman
3RD JUNE 2016 AT 8:14 PM

I am not sure what is up here, but I have had no issues with Windows 10 and it appearing? The
Raspbian SD card image includes a FAT32 partition and an ext3 partition. Windows will be
unable to read the ext3 partition, but FAT32 is a standard partition format that Windows will
happily accept, as the many other people trying this out have found without any issues.
Windows 10 also should include the USB Gadget ethernet device driver, given it is actually just
emulating a standard USB ethernet device, nothing special about it.

Could perhaps there be something weird with your Windows 10 setup? Perhaps a machine
connected to an enterprise network (and in turn locked down with Group Policy) or have
something like an antivirus software that doesn’t like external devices?
I am certainly not able to reproduce any of the issues you have brought up and is rst anyone
has reported them?

Neil Wallace
4TH JUNE 2016 AT 10:04 AM

Andrew – my apologies for being a bit snarky – you certainly do know what you are talking
about [ and your extremely impressive “About Me” makes that point very convincingly]

I retraced my steps and have identi ed my problem.

1. Root cause – I had not enabled the “hidden/disabled” administrator account on Windows
10. [I was under the impression that Win10 accounts had administrator rights.]
2 Yesterday, when working through raspberrypi.org, I downloaded Jessie and the
Win32DiskImager, but Win32DiskImager wouldn’t run because it needed elevated rights. I
backed off from sorting that out, and headed for the NOOB download and the
raspberrypi.org method for copying les to the SD – and amending the con g.txt and
cmdline.txt les on my Zero. That worked – but a bit tedious on setting up the
TV/keyboard/mouse front.
3 This morning, I enabled the Win10 administrator account; ran the Win32DiskImager; and
with the Jessie image on SD was able to quickly and simply amend the con g.txt and

https://blog.gbaman.info/?p=791 6/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

cmdline.txt les.
4 Simples!!

Apologies again –
YOU WERE RIGHT – this IS a “super simple” way to set up access to the Zero [though older
folk like me might need to be gently reminded to work as an administrator]

Tom
6TH SEPTEMBER 2016 AT 1:48 AM

I had exactly the same problem. After plugging the USB cable between the Pi and the PC, in
Device Manager, I get a Network adapter: USB Ethernet/RNDIS Gadget but with a yellow
triangle. After I right clicked on the entry, then clicked “properties”->”advanced” I entered an IP
address. This xed the yellow triangle. Everything started working and I could log into the Pi zero.

Hope this helps.

Vincent
19TH APRIL 2017 AT 8:15 PM

Yes. I had the same problem. But then I tried accessing the Raspi with the IP address I entered
which does not work. It still needs raspberrypi.local in putty then it worked. =)

rosak
18TH MAY 2017 AT 12:18 AM

And same here. Windows 10 I followed your instructions, edited con g.txt and cmdline.txt, added
ssh le onto sd, installed Bonjour on my Windows machine, connected through decent USB cable.
Raspberry booted up I believe, green LED became solid but I have no connection on SSH using
Putty to raspberrypi.local. There is no ethernet device in device manager but there is a serial
device instead.

JasonP
20TH MAY 2016 AT 9:22 PM

Nice write up. Thank you. I will be trying this when I receive my rpiZ.
Any idea if this works on other versions of RPI?

 gbaman

https://blog.gbaman.info/?p=791 7/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

21ST MAY 2016 AT 12:20 PM

Nope, only Pi Zero – http://blog.gbaman.info/?p=791#comment-136188

Michael Vartan
20TH MAY 2016 AT 10:50 PM

Is this limited only to the pi zero or is the hardware connected correctly in other revisions of
raspberry pi?

imadaily
20TH MAY 2016 AT 11:15 PM

For those that want to have internet access on the pi after doing this and are using windows:
On the windows pc enable internet connection sharing (Control Panel > Network and sharing
center > Adaptor settings > Properties > Sharing) .
Don’t use a static IP address on the pi as internet connection sharing is not compatible with static
IPs! (took me a while to gure out)
With static IP disabled, To connect to the Pi use its host name. For windows to nd devices by host
name you will need to install bonjour or (samba?) or similar.

Dewi
21ST MAY 2016 AT 9:36 PM

The icing on the cake!

Kyle
22ND MAY 2016 AT 5:17 AM

I cant seem to gure this out. I am getting a 169.254 address on my pi and virtual interface which
tells me it cant reach a dhcp server(my router). I cant update my pi because it cant resolve the
domain names to grab the les because it seems that dns isnt working. I have network sharing
enabled. Am I doing something wrong?

imadaily
27TH MAY 2016 AT 12:41 AM

I’m fairly certain that the windows pc acts as the dhcp server for the device that the internet
connection is shared to. (PC = DHCP server for pi)

https://blog.gbaman.info/?p=791 8/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

For me the pc uses the addresses:


192.168.137.1 on the (USB Ethernet/ RNDIS Gadget) 192.168.1.7 for the ethernet connection
provided by my routers DHCP server.

The Pi Zero reports an address 192.168.137.*

where * changes each time it is booted. So far I have not found a way to stop the pi’s address
changing while still maintaining connection.

I don’t understand the process well enough to know what the problem you’re having is caused
by, but as a quick suggestion, make sure that internet connection sharing is enabled on the
network adaptor that has your current internet connection on. Secondly try testing with any
other networks disabled. (i.e. only enable the network with internet access and the Pi Zero
connection.

Kyle
28TH MAY 2016 AT 4:44 AM

I managed to gure it out. I statically assigned a 192.168.137 address to the pi and everything
started working.

TAGWARE
31ST MARCH 2017 AT 3:15 PM

Hi

169.254.x.x means that it can’t pick up an IP from the DHCP server which will be the local WIN
10 PC.

Ensure that the Raspberry PI is connected to the USB cable and is powered. Second, if you
didn’t add a le call “ssh” with no extension in the root of the MicroSD then you probably will
need to do this rst anyway. As the chaps decided to turn off the SSH service as a security point.

On the Windows 10 PC.

Ensure that you allow it to share the network of the PC. Via Right-hand mouse click over the
WiFi/Network ICON on the task bar – “Network and Sharing Center” Select “Change Adapter
Settings” on the left of the page. Normally second line down. Select the current network that is
connected to the internet. Either a WiFi or Ethernet. Select the connection. Select righthand
mouse. Then, select “Properties”, then Select Tab “Sharing” on the righthand side of the panel.

https://blog.gbaman.info/?p=791 9/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Then, select under the “Internet Connection Sharing” the Tick box ” Allow others users to
connect through this computer’s Internet connection”. Under this line, there will be a drop
down box “Select a Private Network Connection” Select this and select the Network which is
normally Network 4. (May be different). Then, apply. This will make Windows 10 setup the
rules. Now, check on the Putty session to see if you can ping http://www.google.com. If not you
probably have got the wrong Network connection. Go back and choose another. You will get
there in the end.

It does work as I have one running without issue. :o)

Romy
10TH JANUARY 2017 AT 4:18 PM

Hi, I did connect my host computer to my PiZero through SSH, and the internet is shared as you
mention, no STATIC IP, but I still have problems to connect the PiZero to internet. I think, the
problem is that the dynamic ip that my computer gives to the PiZero is not in the same ip address
192.168.1.*/24, instead, the PiZero ip adddress is 169.254.*.* . What I am missing?

Vincent Marfaing
20TH MARCH 2017 AT 9:08 PM

That sound great. Didn’t know this is possible. Thanks for posting this. 8)

Simon Lambourn
21ST MAY 2016 AT 11:01 AM

This is a great time-saver – thank you. Could it also be used for a regular Pi 2 or 3?

m
22ND MAY 2016 AT 9:54 AM

Wow, excellent write ups! Any chance this might work on the other models?

ONLY KIDDING, LOL!!! You might need to change the font to luminous and ashing border….

AndrewS
22ND MAY 2016 AT 10:42 PM

Great work Andrew! Will hopefully get a chance to play with this soon.

https://blog.gbaman.info/?p=791 10/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

It’s a shame so few people bother to read the existing comments, before posting theirs

rena2019
23RD MAY 2016 AT 6:14 PM

I tried it under Linux Mint 17.3 without luck. dmesg shows the connected device but it’s not possible
to connect to the RPi0 with ssh:

[ 3782.623984] usb 2-2: new high-speed USB device number 2 using ehci-pci
[ 3783.019595] usb 5-2: new full-speed USB device number 2 using ohci-pci
[ 3783.487144] usb 2-2: new high-speed USB device number 3 using ehci-pci
[ 3784.162493] usb 5-2: new full-speed USB device number 3 using ohci-pci
[ 3784.320500] usb 5-2: not running at top speed; connect to a high speed hub
[ 3784.334499] usb 5-2: New USB device found, idVendor=0525, idProduct=a4a2
[ 3784.334511] usb 5-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3784.334518] usb 5-2: Product: RNDIS/Ethernet Gadget
[ 3784.334524] usb 5-2: Manufacturer: Linux 4.4.9+ with 20980000.usb
[ 3784.343034] cdc_ether 5-2:1.0 usb0: register ‘cdc_ether’ at usb-0000:00:13.0-2, CDC Ethernet
Device, a6:7a:69:71:b8:7a
[ 3784.673937] userif-3: sent link down event.
[ 3784.673971] userif-3: sent link up event.
[ 3790.046232] userif-3: sent link down event.
[ 3790.046244] userif-3: sent link up event.
[ 3835.034499] userif-3: sent link down event.
[ 3835.034509] userif-3: sent link up event.

 gbaman
25TH MAY 2016 AT 10:36 AM

Are you sure Mint ships with Bonjour? (Avahi-daemon)

rena2019
25TH MAY 2016 AT 5:04 PM

yes, it is running:
$ status avahi-daemon
avahi-daemon start/running, process 957

rena2019

https://blog.gbaman.info/?p=791 11/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

25TH MAY 2016 AT 5:44 PM

Seems that dns does not work somehow but it works with IPv6 !!!!!

I found the IPv6 adr with:

$ avahi-browse -art
+ usb0 IPv6 raspberrypi Remote Disk Management local

= usb0 IPv6 raspberrypi Remote Disk Management local
hostname = [raspberrypi.local]
address = [fe80::ae54:35ca:1bdd:3400]
port = [22]
txt = []
= usb0 IPv6 raspberrypi [42:e9:3b:10:2f:3f] Workstation local
hostname = [raspberrypi.local]
address = [fe80::ae54:35ca:1bdd:3400]
port = [9]
txt = []

and RPI0 is available with ping:


$ ping6 -I usb0 -c 3 fe80::ae54:35ca:1bdd:3400
PING fe80::ae54:35ca:1bdd:3400(fe80::ae54:35ca:1bdd:3400) from XXXXXXXXXXX usb0:
56 data bytes
64 bytes from fe80::ae54:35ca:1bdd:3400: icmp_seq=1 ttl=64 time=2.87 ms
64 bytes from fe80::ae54:35ca:1bdd:3400: icmp_seq=2 ttl=64 time=0.870 ms
64 bytes from fe80::ae54:35ca:1bdd:3400: icmp_seq=3 ttl=64 time=1.13 ms

— fe80::ae54:35ca:1bdd:3400 ping statistics —


3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.870/1.628/2.879/0.892 ms

SSH connects to the RPi0 if the interface is speci ed:


$ ssh -6 pi@fe80::ae54:35ca:1bdd:3400%usb0

Thanks a lot for your blog post!

medevacs
27TH MAY 2016 AT 5:01 PM

https://blog.gbaman.info/?p=791 12/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Hey @rena2019, good catch with IPv6. I have the same problem and your idea with
connection via IPv6 worked with my RPI Zero. Aside from not being able to connect with
just pi@raspberry.local instead of IPv6, after connecting my RPI Zero, the network-
manager in my Xubuntu 14.04 gets crazy every minute or so and its icon is spinning for a
few seconds.

AndrewS
2ND JUNE 2016 AT 11:04 AM

I also had the same problem with the USB-network only working over IPv6 on Ubuntu
14.04, but I gured out how to also get it working over IPv4, which ‘ xes’ raspberrypi.local

You need to go into the network-manager menu, Edit Connections… and edit the new
Ethernet connection (for me it was “Wired connection 2”). Switch to the IPv4 tab, and
change the Method to “Link-Local only”. Click Save and then Close.

The usb0 network interface will then get assigned a 169.254.x.y address, and “ssh
pi@raspberrypi.local” will work just like it should.

HermannSW
17TH JULY 2016 AT 2:15 AM

Thanks for this great info!

I was not able to ping raspberrypi.local and went your ipv6 way.

lsusb con rms that Pi Zero really provides network device:


$ lsusb | grep USB
Bus 001 Device 002: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS
Gadget
$

Next I got usb0 ipv6 address from /sbin/ifcon g:


$ /sbin/ifcon g usb0
usb0 Link encap:Ethernet HWaddr d6:89:a2:22:3f:9a
inet6 addr: fe80::d489:a2ff:fe22:3f9a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:1 dropped:0 overruns:0 frame:1
TX packets:517 errors:0 dropped:0 overruns:0 carrier:0

https://blog.gbaman.info/?p=791 13/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:112873 (112.8 KB)

Immediately ping6 worked as for you:


$ ping6 -I usb0 -c 3 fe80::d489:a2ff:fe22:3f9a
PING fe80::d489:a2ff:fe22:3f9a(fe80::d489:a2ff:fe22:3f9a) from
fe80::d489:a2ff:fe22:3f9a usb0: 56 data bytes
64 bytes from fe80::d489:a2ff:fe22:3f9a: icmp_seq=1 ttl=64 time=0.067 ms
64 bytes from fe80::d489:a2ff:fe22:3f9a: icmp_seq=2 ttl=64 time=0.073 ms
64 bytes from fe80::d489:a2ff:fe22:3f9a: icmp_seq=3 ttl=64 time=0.075 ms

— fe80::d489:a2ff:fe22:3f9a ping statistics —


3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.067/0.071/0.075/0.010 ms
$

But “ssh -6” does not let me in:


$ ssh -6 pi@fe80::d489:a2ff:fe22:3f9a%usb0
ssh: connect to host fe80::d489:a2ff:fe22:3f9a%usb0 port 22: Connection refused
$

I did boot Raspbian with power, USB keyboard and HDMI and was able to successfully do
“ssh localhost”, so sshd is running.

The syntax seems to be correct as this change from usb0 to (non-existant) usb1 shows:
$ ssh -6 pi@fe80::d489:a2ff:fe22:3f9a%usb1
ssh: Could not resolve hostname fe80::d489:a2ff:fe22:3f9a%usb1: Name or service not
known
$

What can be the reason the very last step of doing the actual “ssh” gets refused?

Hermann.

pielu
25TH NOVEMBER 2016 AT 2:07 PM

https://blog.gbaman.info/?p=791 14/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Thank you so much rena2019 ! I spent several hours trying to connect to my Zero and your
comment solved it perfectly. As a bonus i was always puzzled by this IPv6, rst time it
proves useful :=)

ShinyCanoe
4TH JUNE 2016 AT 7:29 AM

Has anyone gured out a way to do this with an Android phone? I assume you would need a
phone capable of OTG ethernet. It would be so convenient for me to be able to plug my
deployed zeros into my phone instead of my bulky laptop in the eld.

Lightmaster
26TH JULY 2016 AT 12:42 PM

Android phones are actually really easy. Just connect with OTG cable and micro USB cable,
and in settings on your phone, go to More (at top near networking settings), then you should
see something about tethering and hotspots, and in that menu you can activate USB
Tethering. IP subnet should be the same on all phones, 192.168.42.0/24. Use the app Fing to
search that subnet and you should nd you RPi zeros up address, and you can use your
favorite SSH client on your phone to connect to it

doumatso
27TH MAY 2016 AT 11:29 AM

Ι had the same problem. You have to manually assign IP Address for the network.

rena2019
23RD MAY 2016 AT 6:45 PM

If I connect the RPi0 to a Windows PC I get the following error in the device manager under the
“USB Ethernet/RNDIS Gadget” device (with yellow warning icon)

“This device cannot start. (Code 10)


{Operation Failed}
The requested operation was unsuccessful.”

 gbaman
25TH MAY 2016 AT 10:37 AM

Which version of Windows?

https://blog.gbaman.info/?p=791 15/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Rena2019
25TH MAY 2016 AT 3:39 PM

Win8.1

Jarez
29TH MAY 2016 AT 12:45 PM

I was able to SSH using putty only when I updated the driver software automatically for the
“Ethernet Device”.
So at rst it appears yellow, right click and then click on update driver software.

PiMuncher
25TH MAY 2016 AT 8:14 PM

Great work, this is so much easier to setup now.

Should this work on all operating systems using the 4.4 kernel? I can get g_ether working on
Raspbian but not the May release of OSMC. Am I missing something obvious?

 gbaman
30TH MAY 2016 AT 2:00 PM

It should for all that are using the of cial Raspbian kernels, but don’t enough experience with
OSMC to say if it does or not.

PiMuncher
8TH JUNE 2016 AT 4:23 PM

I’ve posted this question to the OSMC forum and it looks like the modules weren’t included in
the last release. So will wait to check if they are included in the next update.

OSMC forum post:


https://discourse.osmc.tv/t/using-gadget-mode-g-ether-on-pi-zero/16737

Brandius
26TH MAY 2016 AT 3:39 PM

I have to type: ssh pi@raspberrypi.local


and not ssh raspberrypi. local.

https://blog.gbaman.info/?p=791 16/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Kevin Angus
28TH MAY 2016 AT 6:51 AM

Got my Zero today, downloaded Jessie full, formatted an eight GB SD ultra card, used Image Writer
to write the IMG, edited the les then booted Zero and tried to login;
pi / raspberry
Access Denied
I’m using Putty (current version)
With the Zero not plugged in Putty can’t connect so I know it is not something else I’m trying to
login to.

 gbaman
30TH MAY 2016 AT 2:03 PM

Perhaps try re ashing it and check your spelling? May also be a weird issue with your keyboard
layout?

Kevin Angus
30TH MAY 2016 AT 4:25 PM

Rebuild the SD card twice, downloaded another image, twice, the keyboard has worked, is
working with raspberry pi 2, and the pi/raspberry still doesn’t work on the Zero.
The Bonjour con gured the rewall, it shows Google Chrome (mDNS-In) owns the 5353
inbound UDP port.
Tried ‘sharing’ the ‘Ethernet’ connection and lost connection to my local network…..
I ordered all the cables, USB powered hub and another large bottle of TUMS.

Kevin Angus
30TH MAY 2016 AT 8:00 PM

UPDATE: I double checked my PI 2 that it could do SSH still, nope. Seems all my windows 10
machines will not connect while XP machine will. My Windows 10 machines can connect to
my Linux servers.

From the auth.log


May 30 16:41:07 raspberrypi sshd[1325]: pam_unix(sshd:auth): authentication failure;
logname= uid=0 euid=0 tty=ssh ruser= rhost=10.1.18.110 user=pi
May 30 16:41:09 raspberrypi sshd[1325]: Failed password for pi from 10.1.18.110 port
50526 ssh2

https://blog.gbaman.info/?p=791 17/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

May 30 16:41:14 raspberrypi sshd[1325]: error: Received disconnect from 10.1.18.110: 13:
Unable to authenticate [preauth]

Both Windows 10 machines are new installs as of 5 days ago.

I just sudo apt-get update/upgrade on my PI 2 and now I can login from a Windows 10
machine

Kevin Angus
30TH MAY 2016 AT 8:31 PM

Modi ed the les on the new SD card I had in the PI 2 after I had updated. Plugged the SD
card into the ZERO and now can connect with Windows 10 Putty.

Chris.T
28TH MAY 2016 AT 8:54 PM

After following the instructions on my newishly reinstalled Windows 10 Home 64 bit the pi
appeared in device manager and as an ethernet adaptor but was assigned a default address in the
169.xxx.xxx.xxx range.
To make it work I had to also do the following:
1. Install Bonjour print services from the link in the post (as documented – I had already done this
before connecting the pi)
2. Go into Network & Sharing centre
3. Click on my active internet connection – in my case Wi-Fi – opens the connection Status dialog
4. Choose Properties – opens the connection properties dialog
5. Select the Sharing tab
6. Check the box “Allow other network users to connect…”
7. Select the connection corresponding to the USB Ethernet/RNDIS Gadget – in my case Ethernet 5
8. Hit OK.
After a short pause the connection address changed from the 169 range to 192.168.137.1 and I was
able to point my ssh client at raspberrypi.local and connect.
It may be that your machine already had ICS con gured – no matter – what a handy thing to be able
to do!
Collateral bene t is that enabling ICS gives the Pi internet access from the start – I know this has
already been covered in the comments but I found that ICS was essential in order for the Pi and the
USB Ethernet device to get assigned addresses.
Here’s another challenge – can this be adapted so that several Pi Zeroes can be connected via USB
(hub? hubs?) such that they are all networked together and sharing just one ethernet or wi dongle?
Would be a great basis for a Pi Zero cluster!

https://blog.gbaman.info/?p=791 18/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Austin
23RD JUNE 2016 AT 2:19 PM

I am actually going to begin working on this and have begun my acquisition of pi zero’s.
(Microcenter still only lets me buy one per visit so I go every day during my lunch hour) Thinking
of using a raspberry pi 3 with 4 usb 4 port hubs and 16 pi zeros set up. Im only on day 3 of my
acquisition though…

Chris.T
30TH MAY 2016 AT 12:33 PM

Okay so it turns out the ICS thing is handy but not essential – raspberrypi.local is resolving to an
IPV6 address so it’s not using the ICS at all – except that the Pi can see the internet via network
adaptor usb0 which has an IPV4 address too – assigned from ICS. I’m still fascinated by the idea of a
Pi cluster just using a master Pi connected to a wi dongle or ethernet adaptor and several slave
PiZeroes connected to it…

Jarez
30TH MAY 2016 AT 5:24 PM

Ok after following this tutorial, I am now operating my Pi completely headlessly and with internet
access (Windows):
1. Follow the instructions in the tutorial
2. Once the Pi Zero appears as an ethernet device in device manager make sure the drivers are
completely up to date (Right click and search online for drivers) luckily windows found them and
pulled through for me.
3. Open up putty and SSH using default port 22 and the address rapberrypi.local
4. If all you want it terminal access stop here, if you want graphical access continue.
5. You may want to con gure the Pi Zero to have a static IP address on your home network,
therefore you will need to edit the network interfaces le, type in “sudo nano
/etc/network/interfaces” on your putty terminal.
6. Comment out everything but the line “source-directory /etc/network/interfaces.d” and add all
the information corresponding to your network setup as such:
(information can be obtained by using cmd on your windows computer and typing “ipcon g”
recording all important addresses such as gateway, broadcast etc if you dont already know them)
*************************************
auto lo
iface lo inet loopback

https://blog.gbaman.info/?p=791 19/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

allow-hotplug usb0
iface usb0 inet static
address 192.168.0.XXX # whatever IP address you want the pi zero to occupy however it must not
clash with the IP’s currently on the network or the ones which the DHCP assigns.
netmask 255.255.255.0
network 192.168.0.0 # the base IP of your network
broadcast 192.168.0.255 # whatever your broadcast #address is
gateway 192.168.0.1 # gateway IP for your network
nameserver 8.8.8.8 # google nameserver
dns-nameserver 8.8.8.8 8.8.8.4 # google dns servers
***************************************

7. Hop back over to your windows computer and go into “change adapter settings” in the networks
and sharing center.
8. Click on properties on Pi Zero ethernet adapter, and then click on ipv4 properties, set the IP
address acquisition to manual and enter the static IP address you want assigned to the Pi Zero,
along with the broadcast address, leave the gateway blank.
9. Save these settings, and then highlight your Wi-Fi / Ethernet device and also your Pi Zero eth
adapter and then click on “add to bridge” – this will bridge these two adapters and allow internet
access to be shared.
10. Restart your Pi Zero with the changes you made in step 6.
11. Restart your computer also if necessary.
12. When your computer starts up head over to putty log in to your Pi and type ifcon g in the
terminal, you should see the ip address you assigned appear as the IP address of the device.
13. Double check connections by pinging the IP address of the host device and then ping
http://www.google.com , if this does not work try pinging 8.8.8.8 which is a google nameserver, if it
can get a response your DNS con guration may be an issue. Please check your route table and
ensure that it has added the route to your host computer and to the router.
14. If you can ping google you are in good shape, type in “sudo apt-get install xrdp” , then reboot
15. Windows should already have installed remote desktop connection, type in the IP address you
have assigned to the Pi Zero and you should be able to set up a remote connections, complete with
visual control over the single USB cable!
16. If you have any issues, post and I may be able to help.

Brad Anderson
11TH OCTOBER 2016 AT 12:27 PM

Hi

https://blog.gbaman.info/?p=791 20/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Followed your instructions and everything works ne until I try to RDP into the RPi, I get the xrdp
login screen enter pi/raspberry then get;

connecting to sesman ip 127.0.0.1 port 3350


sesman connect ok
sending login info to session manager, please wait…
xrdp_mm_process_login_reponse: login successful for display
started connecting
connecting to 127.0.0.1 5910
error – problem connecting

Any help would be appreciated

Colin
17TH OCTOBER 2016 AT 10:46 AM

I found this and it worked for me


Apparently there is a/are defect(s) which prevent xrdp working with the vncserver. However it
works with tightvncserver

Also the order of installation of tightvncserver and xrdp seems to be important.

In summary
•remove the following packages : xrdp, vnc4server, tightvnc

sudo apt-get remove xrdp vnc4server tightvnc


•install tightvnc server followed by xrdp

sudo apt-get install tightvncserver

sudo apt-get install xrdp

Jay
19TH OCTOBER 2016 AT 6:13 AM

Hey I was just dealing with this issue. I found this


(https://raspberrypi.stackexchange.com/questions/56413/error-problem-connecting-to-
raspberry-pi-3-with-xrdp) question stackexchange that solved it for me .

I SSHed into my Rpi and typed the following:

https://blog.gbaman.info/?p=791 21/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

sudo apt-get remove xrdp


sudo apt-get install vnc4server
sudo apt-get install xrdp
sudo service xrdp restart
sudo reboot

I’m assuming you are already providing your pi zero with an internet connection somehow? If
not here’s a guide on how to share your computers internet through USB as well.
http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget/

Hope this helps!

Kevin Angus
30TH MAY 2016 AT 8:58 PM

This is my setup;
auto lo
iface lo inet loopback
allow-hotplug usb0
iface usb0 inet static
address 10.1.18.244
netmask 255.255.255.0
network 10.1.0.0
broadcast 10.1.0.255
gateway 10.1.18.1
nameserver 8.8.8.8

But #9 stopped me, there is not any way to ‘highlight’ Ethernet 2 and Local Area Connection’ then
Add to bridge. Windows 10.

When I reboot ZERO Windows tells me there is a con ict with an IP address

Kevin Angus
30TH MAY 2016 AT 9:21 PM

I found an error:
Log Name: Microsoft-Windows-Kernel-PnP/Con guration
Source: Microsoft-Windows-Kernel-PnP
Date: 5/30/2016 9:31:09 AM
Event ID: 441

https://blog.gbaman.info/?p=791 22/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Task Category: None


Level: Error
Keywords:
User: SYSTEM
Computer: Gate
Description:
Device USB\VID_0525&PID_A4A2\5&7727b50&0&4 could not be migrated.

Last Device Instance Id: SW\{EEAB7790-C514-11D1-B42B-00805FC1270E}\ASYNCMAC


Class Guid: {4d36e972-e325-11ce-bfc1-08002be10318}
Location Path:
Migration Rank: 0xF000FFFFFFFFF132
Present: true
Status: 0xC0000719
Event Xml:

441
0
2
0
0
0x4000000000000000

636

Microsoft-Windows-Kernel-PnP/Con guration
Gate

USB\VID_0525&PID_A4A2\5&7727b50&0&4
SW\{EEAB7790-C514-11D1-B42B-00805FC1270E}\ASYNCMAC
{4D36E972-E325-11CE-BFC1-08002BE10318}

0xf000fffffffff132
true
0xc0000719

This is from the Acer Incorporated driver dated 1/13/2010 version 1.0.0.0

Graham Toal

https://blog.gbaman.info/?p=791 23/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

30TH MAY 2016 AT 9:25 PM

> broadcast 10.1.0.255

that should be 10.1.18.255

Graham Toal
30TH MAY 2016 AT 9:28 PM

Disconnect the pi and see if you can still ping 10.1.18.244 from anywhere. You may genuinely have
two machines with the same IP, if .244 is within the range handed out by your DHCP server. Or if
you earlier con gured another pi with the same setup and forgot it was still plugged in somewhere?

Kevin Angus
30TH MAY 2016 AT 10:11 PM

I started from scratch but before adding ip information in the interfaces le I went to Network
and Sharing Center / Change adapter settings and there I was able to ‘highlight’ Ethernet 2
(ZERO) and Local Area Connection then bridge them. The bridge operation gave Zero a DHCP
address and I reserved that address in my router.
sudo apt-get update now works!

Pingback: Simple Setup for ‘Raspberry Pi Zero as a USB virtual network gadget’ @Raspberry_Pi
#raspberrypi « Adafruit Industries – Makers, hackers, artists, designers and engineers!

Kevin Angus
2ND JUNE 2016 AT 1:48 PM

Update on Zero; I removed the bridge, Ebay was timing out and all sites were doggie. Internet now
works again.

Grahame
2ND JUNE 2016 AT 4:29 PM

Do I need besides the Zero and SD Card:


an OTG usb cable/shim for this or will a regular micro to normal size USB cable work?
I have read part 1 of blog too, but I am unsure

 gbaman

https://blog.gbaman.info/?p=791 24/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

3RD JUNE 2016 AT 8:09 PM

Only thing on top of Zero and SD card is a standard micro usb cable. Nothing special about it.

silver
2ND JUNE 2016 AT 7:02 PM

Can you elaborate on the VNC setup?

Pingback: Turn A Raspberry Pi Zero Into A USB Device, No Extra Accessories Needed | Lifehacker
Australia

Grahame
3RD JUNE 2016 AT 8:51 PM

Up and running now, thanks


This is really neat – well done

Dody Suria Wijaya


4TH JUNE 2016 AT 5:12 AM

Just a note, if you’ve changed your raspberry pi hostname from the default “raspberrypi” to
something_else, you need to use that new hostname instead so it looks like

ssh pi@something_else.local

Lewis Cowles (@LewisCowles1)


5TH JUNE 2016 AT 12:37 PM

I wonder if anyone else has played with separating networks using this to demonstrate to learners
in networking that what seems like homogeneous device ecosystem (A.K.A Internet of Things), can
actually be many devices connected over different interfaces and protocols.

I’m working on something with wireless-lan, using rPi3 as a wireless access-point, that has rPi-zero’s
connecting over wlan using built-in credentials from /etc/wpa_supplicant/wpa_supplicant.conf.
Trying to switch to USB over gadget mode I feel kinda stumped…

I’m not even sure how practical it would be to have N rpi-zero’s, but just the fact it could be boxed
up, easily and affordably presented to showcase such a wide array of connected concepts interests
me.

https://blog.gbaman.info/?p=791 25/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Mark
6TH JUNE 2016 AT 3:12 AM

Hi, I have used the information in the post and in comments to somewhat make pi zero work with
my Ubuntu 16.04 desktop: I can ssh into the PI Zero, but I am really struggling to make the pi access
the Internet through my PC. Is there a way to do that?

AndrewS
12TH JUNE 2016 AT 2:15 PM

See the link to the rough’n’ready script that I wrote to do this in another comment of mine below
(written on 8th June 2016).

Chris.T
6TH JUNE 2016 AT 1:18 PM

Once I had the pizero connected as a usb slave and was able to ssh to it/apt-get update etc. I added
the network section to /etc/wpa_supplicant/wpa_supplicant.conf for my wireless lan so now I can
run it either in usb slave mode when I want to change things or just plug in a usb wi dongle and
connect power to run headless. No other changes needed as it detects which mode to run in by
what it’s connected to. Great!

AndrewS
8TH JUNE 2016 AT 1:29 PM

I was doing lots of experimentation with this last night, and found that every time I reboot the Pi
Zero, it generates a new random MAC address for each side of the USB-network connection. On
Ubuntu this is especially annoying as it creates a new “Wired Connection N” for every unique MAC
address it sees – I got up to “Wired Connction 10”! (And for each new Wired Connection that got
created, I had to manually set it to LinkLocal as described earlier)
I did a bit of searching, and found some useful info at
http://wiki.openmoko.org/wiki/USB_Networking about hardcoding the MAC addresses. In my case
(after connecting to the PiZero over SSH) I added:
options g_ether host_addr=26:7f:62:5c:48:86 dev_addr=d6:fe:44:ad:8f:13

to the le /etc/modprobe.d/g_ether.conf and after rebooting again, both sides of the connection
now have a static MAC address, which means Ubuntu doesn’t create new “Wired Connection”s, and
I was able to then go and delete the all old / redundant “Wired Connection 6” etc. that it had
created.

https://blog.gbaman.info/?p=791 26/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

In the g-ether.conf le, host_addr determines the MAC-address on the PC-side of the connection,
and dev_addr determines the MAC address on the PiZero-side of the connection.

Based on the info at https://github.com/raspberrypi/linux/issues/1212#issuecomment-224105217


I’ve also created a script to automatically setup internet access for the PiZero:
https://gist.github.com/lurch/ad939bbce48064cffdb215268eac9f62

PiMuncher
8TH JUNE 2016 AT 4:31 PM

One thing I noticed is the MAC address of the network connections (on both the device and host)
are randomly generated at each boot. This is a bit annoying if you want to use a DHCP server to
reserve a IP address for your gadget.

I got round this problem by adding the following after “rootwait modules-load=dwc2,g_ether ” in
the “cmdline.txt” le:
g_ether.dev_addr=11:22:33:44:55:66

You can also specify other options for host_addr, iManufacturer and iProduct, but I haven’t had time
to try these.

AndrewS
8TH JUNE 2016 AT 4:57 PM

LOL, I noticed the same thing about the random MAC addresses too (and found it annoying for a
different reason), and I also posted a note about how to x it earlier today as well! (but my
comment contains a couple of URLs, so it hasn’t been approved yet).
Great minds think alike, etc.

Your way of xing it (by adding options to cmdline.txt) is slightly neater than my way of xing it
(by adding options to /etc/modprobe.d/g_ether.conf) though

neiluj
13TH JULY 2016 AT 8:19 AM

Could you give to us the entire cmdline.txt ?


I’ve try your x but it’s not working on my Pi.

 gbaman

https://blog.gbaman.info/?p=791 27/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

13TH JULY 2016 AT 8:46 PM

The entire cmdline.txt le is already linked in the post?

David Albert
23RD JULY 2016 AT 10:36 PM

Adding that after the modules-load=dwc2,g_ether did not work for me, did you enter this as a
new option (space separating it from “dwc2,g_ether”) or as another option t modules-load (comma
separating it from dwc2,g_ether)?

TheDiveO
22ND MARCH 2017 AT 8:47 PM

Setting a device MAC address that is odd in the rst octet isn’t exactly a good idea, me thinks: it’s
a multicast address. So it should 12:22:33:….

Lukasz
8TH JUNE 2016 AT 7:44 PM

Hi

Im trying to connect via MAC os but looks like Bpnjure does not detect my PI Zero. Do any of you
try this on OSX?

Lukasz
8TH JUNE 2016 AT 10:02 PM

I have found the root of the problem. My USB cable is broken. After changing to other one
everything works perfectly.

P.S. Very nice work with this post

Graham Toal
8TH JUNE 2016 AT 10:59 PM

Does the rpi0 have two usable USBs? If so, you could build a cambridge ring from them, each one
daisychained to the next. [I actually did that (many) years ago with the BBC Micro’s serial port, but
that required more complex software – because there was only one serial port, data out went on
the TX pin but replies had to go all the way round the ring to come in on the RX pin from the
machine on the other side!]

https://blog.gbaman.info/?p=791 28/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

AndrewS
9TH JUNE 2016 AT 12:20 AM

Nope – the BCM2835 (SoC used on the Pi Zero) only has one USB interface, and this is directly
exposed on both the Zero and A+ (and ComputeModule). The B+ / Pi2 / Pi3 all use a LAN9514 to
provide an Ethernet interface and 4 downstream USB ports (i.e. using a built-in USB hub).

sburggsx
9TH JUNE 2016 AT 2:54 PM

I’ve been trying this on a Macbook Air and I can’t seem to get the raspberrypi.local address to
resolve. Are there any other troubleshooting steps you can suggest? It de nitely boots and I have
made the changes to the two les.

sburggsx
9TH JUNE 2016 AT 3:25 PM

Ok, my previous comment is now null and void. I missed an “=” and put in a “-” instead. It took me
three times rechecking it to catch it.

Now, about internet connection sharing on a Mac…..

PaulH
10TH JUNE 2016 AT 10:59 AM

I had real trouble with this. The Pi Zero wouldn’t show up as a network device at all on either Jessie
Lite or Full.

I nally got it working after much debugging by changing the cable. So one important note to make
is that the cable does make a difference.

AndrewS
12TH JUNE 2016 AT 2:21 PM

Yeah, I guess some USB -> microUSB cables will be power-only (i.e. only two wires connected) –
they will still allow the Zero to receive power and boot up, but the PC won’t “see” it.
You need to use a “normal” USB -> microUSB cable (i.e. with all four wires connected – two for
power and two for data) to allow the PC to see the Pi Zero as a USB device.

https://blog.gbaman.info/?p=791 29/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Jason
12TH JUNE 2016 AT 9:10 AM

Excellent stuff – I’ve been developing using the a pi set up with the original instructions all year now

But … trying the New Simple Method on a Mac has turned into a World Of Pain – the Pi shows up as
either an RNDIS device (g_ether) or CDC device (g_cdc) … but I don’t seem to be able to get the Mac
to serve it up an IP number
Oh well, a bit of virtual box and such will let me sort it out.
Did anyone get this to work with a bit of Mac con guration ?

 gbaman
13TH JUNE 2016 AT 11:31 PM

I was able to get it working ne using Mac OS internet sharing without any issue? By default
though you shouldn’t need one as should work for dirrection connection (without internet) using
raspberrypi.local (bonjour).

willie
14TH JUNE 2016 AT 6:29 PM

JEEPERS! if you’re using OS X you *have to* enable File Sharing!!!!

Jason
15TH JUNE 2016 AT 3:41 PM

“JEEPERS!”?
File sharing is nothing to do with it … as you now know.

Jason
15TH JUNE 2016 AT 3:44 PM

I’ll take another look – I looked at the avahi con g on the “fresh” image, and it has nothing to
enable avahi to advertise the ssh service – just remote disk management.
Perhaps everything work ne letting the Mac and the Pi do self assigned numbers (in the
169.254.0.0/16 network)?
I shall report back.

AndrewS

https://blog.gbaman.info/?p=791 30/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

15TH JUNE 2016 AT 4:00 PM

I haven’t looked at it in detail, but AIUI avahi (a.k.a. bonjour a.k.a zeroconf) is only used here
for the name-resolution, i.e. mapping raspberrypi.local to the 169.254.x.y that actually got
assigned to your PiZero. As Dody Suria Wijaya noted in another comment, if you change the
hostname on your Pi to e.g. mypizero than Avahi maps mypizero.local to 169.254.x.y (and
raspberrypi.local won’t exist).

Jason
16TH JUNE 2016 AT 8:00 PM

Hi Andrew, I tried this all again with a fresh image … and by following the following steps,
everything works – and there’s a note at the bottom about what I think was wrong.

1. Modify the /boot/cmdline.txt & /boot/con g.txt per The New Simple Method
2. On the Mac, in “System Preferences”, ensure that the “RNDIS/Ethernet Gadget”
interface, if it is there, is set to DHCP
3. Make sure that Internet sharing is NOT enabled. If it is and you have another Pi called
“raspberrypi.local”, Bad Things Happen and you may never connect to your Pi over
ethernet.
4. Plug the Zero into the Mac with your (known working) micro-usb cable … and wait …
5. After a while (about two or three good swigs of tea), use “ping raspberry.local” … and
behold, the Zero should respond, and the IP number will be revealed. If not repeat this step.
You will not need a new mug of tea.
6. Use ssh to log in with the IP number from #5.
7. Some while later, note that avahi/zeroconf/bonjour has got the rhythm and that using
“ssh pi@raspberry.local” now works.
8. Change the hostname to something sensible (i.e. unique and memorable), and reboot
9. Once you can connect using the new hostname, have a go at enabling Internet Sharing
for the “RNDIS/Ethernet Gadget”. Don’t change the DHCP setting on the RNDIS thing
either.
10. Reboot, check all working, make a new cup of tea to celebrate.

So, what was wrong? My guess is that my network is a little complicated and I had some old
con guration around internet sharing and on the RNDIS gadget. When I cleaned up the old
con g, and stopped the VPNs etc. everything sprang into life. I would also say that I was a
little quick to try to log in (natural impatience) and this meant that bonjour had not caught
up with the adverts from the pi.

BTW, thanks for publishing this blog – Using the PI with OTG has transformed the way I do
things when travelling.

https://blog.gbaman.info/?p=791 31/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

willie
14TH JUNE 2016 AT 6:26 PM

not working on OS X 10.10.5 on the Macbook Air… con gured the zero’s /boot/cmdline.txt and
/boot/con g.txt… zero boots ne, but is not assigned an IP address and is not accessible (Apple’s
Bonjour is installed and running and remote login is enabled on OS X)

any tips? tia!

willie
14TH JUNE 2016 AT 6:34 PM

So: for us Apple OS X users:

1. con gure your Zero’s cmdline.txt and con g.txt les


2. turn on File Sharing via System Preferences
3. ssh or sftp using pi@raspberrypi.local
4. if you have previously con gured vncserver on your Zero, you can access the running VNC
service with:

vnc://raspberrypi.local:5901

hope this helps! now my Zero is a fabulous little Python development platform!

 gbaman
14TH JUNE 2016 AT 10:30 PM

In my own testing, enabling le sharing wasn’t needed to connect to a Pi Zero over SSH, or using
SFTP given both of those rely on the services offered by the Pi side, so shouldn’t make any
difference?
I just checked and my test machine running Mac OS does not have it enabled and works ne.

willie
15TH JUNE 2016 AT 2:01 AM

tks! will test on my system again and report back – a very nice feature indeed – quite
remarkable … however, i did note that Internet access is not con gured or assigned for the usb0
interface as the IP range is outside my router’s LAN addressing?

the VNC access alone makes this a convenient development system!

https://blog.gbaman.info/?p=791 32/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

AndrewS
15TH JUNE 2016 AT 11:23 AM

Yeah, the IP address for the usb0 interface *has* to be outside the range assigned by your
router. If your computer has two interfaces (e.g. eth0 and usb0) in the same network-range,
then it won’t know which interface to use when trying to reach a speci c address. That’s why
eth0 and usb0 have to be in different network ranges, and you need to use ‘internet sharing’ /
bridging / etc. so your computer knows to route traf c from one network to the other.

Graham Toal
15TH JUNE 2016 AT 3:26 PM

A comment on the terminology, not on the advice:


That’s usually true if routing (with an exception for routing from some subnet to a ‘more
speci c subnet’ which some routers support, maybe not on the pi), but if you are bridging
between two interfaces, then both interfaces can (and indeed must) be in the same subnet
– that’s the very de nition of bridging…

AndrewS
15TH JUNE 2016 AT 3:38 PM

Thanks Graham, I guess I must have meant “IP forwarding” rather than “bridging” in my
previous comment. Spot the networking noob!

So maybe you *can* bridge eth0 and usb0 if they’re on the same network subnet, but I’ve no
idea how to do that (or whether it’d be better than simple “internet sharing” / forwarding /
routing or not).

willie
15TH JUNE 2016 AT 2:26 PM

OK! tks for all the comments on this blog! i can con rm that File Sharing does *not* have to be
enabled…

i should have paid more attention to an earlier comment regarding USB cabling – not all USB cables
work! i found one that did work and it was a short, direct cable – no adapters or power switches
attached – simply USB malemicro usb male

connection appears as “RNDIS/Ethernet Gadget” under System Preferences->Network… using


DHCP, it is assigned 169.254.188.244… i then ssh in using:

https://blog.gbaman.info/?p=791 33/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

ssh pi@raspberrypi.local

and start a vnc session (on :1) , then connect using

vnc://raspberrypi.local:5901

thanks all!

willie
15TH JUNE 2016 AT 2:31 PM

oh, and con guring ‘net access for the raspberrypi.local was easy with a couple mouse clicks:

System Preferences->Sharing->Internet Sharing (then select the checkbox for “RNDIS/Ethernet


Gadget”

Raspberry Pi Zero – what a great little computer!

Richard Rickwood
18TH JUNE 2016 AT 12:54 PM

Can anyone point me in the right direction to be able to SSH into the zero if i already have another
(or several?) devices on my network that identify as raspberrypi.local (presumably the default for all
Pis?)

 gbaman
19TH JUNE 2016 AT 10:41 PM

Well, one simple option is to disable your other network connection, ssh into the connected Pi
Zero and grab its IP address, then simply use it when you reconnect your networking. Or you
could disable other network connections, ssh into Pi and change its hostname?

AndrewS
19TH JUNE 2016 AT 10:49 PM

“Or you could disable other network connections, ssh into Pi and change its hostname”

Is the solution that I used

https://blog.gbaman.info/?p=791 34/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Geo Meadows
19TH JUNE 2016 AT 8:44 PM

Pi-Zero working ne to screen/keybd/mouse but can’t get this neat USB link to go. Using XP with
Bonjour installed and PZ shows up on XP as Local Area Connection icon but with a yellow triangle
and ‘limited or no connectivity’. Tried different cable, tried updating driver but when I use Putty to
raspberrypi.local on port 22 Putty times out. If I try to connect to the IP address that shows up for
the RNDIS Gadget I get an immediate ‘connection refused’.

Any suggestions?

 gbaman
19TH JUNE 2016 AT 10:42 PM

I haven’t played around with it on XP. Someone had mentioned a while back it might be too old to
have the correct needed drivers installed? Not sure though.

AndrewS
19TH JUNE 2016 AT 10:55 PM

I believe the IP address that shows up for the RNDIS Gadget is the address of the PC-side of the
USB-networking connection. And as you’re not running an SSH server on your PC, that’s why you
get ‘connection refused’. You actually need to connect to the IP address on the PiZero-side of the
USB-networking connection, which will be different.
But if raspberrypi.local isn’t working, then I don’t know how else you’d discover what IP address
the Zero got assigned. And I don’t have any systems still running WinXP that I could use to
investigate further. The ‘limited or no connectivity’ probably just means that the USB-network
connection doesn’t have an onward connection to the internet (which is obviously to be
expected!).

Dan
26TH JULY 2016 AT 11:12 PM

An easy answer to the question of what IP got assigned is to use “ANGRY IP” (AngryIP.org). This
is a must have tool for dealing with networks that use DHCP. it will provide a list of the
connected ethernet adaptors that can be used to scan for any devices on the address range
assigned to that adaptor. very quick and easy. Hope this helps someone

Geo Meadows

https://blog.gbaman.info/?p=791 35/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

20TH JUNE 2016 AT 11:50 AM

Thanks for suggestions. So far no joy.

1. Tried PZ with a Win10 PC, same ‘connection refused’ problem

2. Connected PZ to a Ubuntu Mate PC,


Gets stuck on ‘requesting Ethernet network address’
Opened Terminal,
ssh raspberrypi.local results in ‘name not known’

3. Tried XP again, before the yellow triange shows over the LocalAreaConnection icon it tries for a
few minutes on ‘aquiring network address’

Looks like PZ doesn’t want to talk to anyone.

AndrewS
20TH JUNE 2016 AT 12:20 PM

Sounds like in all cases the PC itself is trying to get an IP address via DHCP from the USB-network
connection (which won’t work, as the PiZero isn’t running a DHCP server).
This isn’t what you want though, you want the PC to auto-assign a link-local IP address
(169.254.x.y) to the USB network device.
For Ubuntu speci cally (I’ve not experimented with Windows yet) see my comment from 2nd
June about con guring “Link-Local only”.

pat
15TH OCTOBER 2016 AT 7:54 AM

how does one do this from the command line only, when I don’t have a desktop interface?

I’ve managed to connect to the pi over ipv6, but not with the hostname avahi is assigning it.

pat
15TH OCTOBER 2016 AT 7:55 AM

I meant in your 2nd of June post, how do you make the same settings on a CLI-only
debian/ubuntu, thanks, sorry for the confusion

AndrewS

https://blog.gbaman.info/?p=791 36/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

20TH OCTOBER 2016 AT 11:01 PM

It’s not something I’ve ever tried doing myself, but it looks like
https://www.google.co.uk/search?q=ubuntu+network-manager+cli might have some good
pointers.

Geo Meadows
20TH JUNE 2016 AT 2:17 PM

Andrew: Just followed instructions in your 2nd June post but found no improvement with ssh.
I then did a reboot and modi ed the network ip4 setting again, and I can get in!
And I can also see the ip address, 169.254.238.187 (for me) – so plugged PZ into XP system,
manually set that IP, and Putty now connects to pi@raspberrypi.local on port 22!
Then tried with Win10 machine and after manually assigning the IP address again I can get in using
Putty with pi@raspberrypi.local.

Excellent! I now have a single cable link to PiZero on three different bases.

Many thanks for the help.

Guilherme
22ND SEPTEMBER 2016 AT 5:49 AM

Dude how did you do it. Im trying but the yellow mark dont go way and i cant get the PZ ip. Plz
help

Diego
23RD JUNE 2016 AT 10:44 PM

Hi

I have done this tutorial and works perfect in my mac os x laptop, but when i try to share the
internet connection, now not recognize any of the ways.
Someone has had the same problem?

Thanks

dupont
25TH JUNE 2016 AT 12:40 PM

https://blog.gbaman.info/?p=791 37/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

It works perfectly with Windows8.1, I just had to update the RNDIS ethernet gadget.
Thank you very much
Marc

Jerome
28TH JUNE 2016 AT 2:21 PM

It works ne on my PC running windows 10!


but if i try to ssh on my laptop (i’m running opensuse leap)
it only says could not resolve hostname…
i’m pretty new at Linux and it would be great if someone could help me out here

 gbaman
2ND JULY 2016 AT 4:36 PM

You may want to have a look and see if you can install the avahi-daemon package, as it is required
for Bonjour name resolving.

XopyIP
2ND JULY 2016 AT 10:24 AM

My pi zero automatically disconnect from usb

avahi-browse -alr log:


+ enp0s29u1u3i1 IPv6 raspberrypi [aa:84:97:ad:1a:11] Workstation local
= enp0s29u1u3i1 IPv6 raspberrypi [aa:84:97:ad:1a:11] Workstation local
hostname = [raspberrypi.local]
address = [fe80::a884:97ff:fead:1a11]
port = [9]
txt = []
– enp0s29u1u3i1 IPv6 raspberrypi [aa:84:97:ad:1a:11] Workstation local

And ssh pi@raspberrypi.local doesn’t work for me (I must use ssh -6 pi@ipv6%enp0s29u1u3i1). Any
idea?

PhilK
12TH JULY 2016 AT 6:30 PM

My setup is a Pi Zero connected to a laptop running Ubuntu 16.04.

https://blog.gbaman.info/?p=791 38/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

I have added these two lines


options g_ether host_addr=26:7f:62:5c:48:86 dev_addr=d6:fe:44:ad:8f:13

to the le /etc/modprobe.d/g_ether.conf
And I modi ed the Wired Connection 2, IPv4 Settings to Link-Local Only

per AndrewS postings. I can now ssh into my Zero via USB.

But still no internet connectivity. Trying to ping 8.8.8.8 for example returns ‘connect: Network is
unreachable’

I must be missing a step someplace.

Thanks!

AndrewS
12TH JULY 2016 AT 9:05 PM

Did you also run the script (on your Ubuntu laptop) that I posted on github.com at the bottom of
my 8th June comment?

PhilK
12TH JULY 2016 AT 10:36 PM

Output from your script:


PC_INET_DEV is enp1s0
PC_ZERO_DEV (usb0) doesn’t exist

I’m a complete newbie on Ubuntu but looking at the Connection Information dialogs, I replaced
PC_ZERO_DEV=usb0
with
PC_ZERO_DEV=enp0s26f7u1
and that seems to work. I can now ping 8.8.8.8 from via ssh on my Zero. I suppose the real test is
apt-get update.

Thank you!

PhilK
12TH JULY 2016 AT 11:03 PM

https://blog.gbaman.info/?p=791 39/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Spoke too soon.

It errors on the nmcli command and cannot determine the DNS_SERVER.

Closer!

PhilK
12TH JULY 2016 AT 11:29 PM

I got it.

I replaced this line:


DNS_SERVER=$(nmcli -t -f IP4 device list iface $PC_INET_DEV | grep DNS | head -1 | cut -
d: -f2)

with this one.

DNS_SERVER=192.168.0.1

I’m on the internet.

Thanks again!

AndrewS
12TH JULY 2016 AT 11:58 PM

Glad you got it sorted! I guess things must work differently on the Ubuntu 16.04 you’re using, to the
Ubuntu 14.04 that I’m using. Maybe I’ll try testing with a LiveUSB boot of Ubuntu 16.04 at some
point…

PhilK
13TH JULY 2016 AT 5:04 AM

Something still not quite right. I can stop and start the pi, disconnect it, reconnect it and it sees the
internet just ne. But if the laptop goes to sleep or restarts or powers off and on then the network is
not visible to the pi any longer.

Something isn’t “sticky”.

https://blog.gbaman.info/?p=791 40/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

AndrewS
13TH JULY 2016 AT 11:00 AM

The two commented-out commands (sysctl and iptables) at the top of my script need to be run on
your laptop after every reboot, as their effect is only temporary. I didn’t get round to looking into
how to make them “sticky”.

Graham Toal
13TH JULY 2016 AT 9:29 PM

I would imagine that they would go in /etc/rc.local to be run as root on boot?

AndrewS
14TH JULY 2016 AT 12:30 PM

I haven’t tried either of them myself yet (so I dunno if the info is still up-to-date), but I did
some searches and http://askubuntu.com/questions/311053/how-to-make-ip-forwarding-
permanent covers sysctl, and https://www.thomas-
krenn.com/en/wiki/Saving_Iptables_Firewall_Rules_Permanently covers iptables.

MoarPink
15TH JULY 2016 AT 4:22 PM

Where can i get bonjour for windows 7 or windows 10

Scott Mason
15TH JULY 2016 AT 7:00 PM

fantastic! will be doing this tonight!

Zero
17TH JULY 2016 AT 8:35 PM

Is there any way to get this working without Bonjour / get the Pi IP address manually from
Windows? Also, is there a way to access the le system without SSH with this type of connection?

Lastly, this seems to work with Windows, but not Ubuntu (it says I have the wrong password on
Ubuntu). Any idea why?

Thank you for your post!

https://blog.gbaman.info/?p=791 41/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Alex
18TH JULY 2016 AT 9:51 PM

Hi Andrew, thank you for the blog, it was incredible to make it work.

I must confess it is my rst RPi experience, I got my RPi zero for a fun-project and stumbled
instantaneously when my usb router didn’t work with Pi. I could not connect neither mouse nor
keyboard to it. So I found your solution, every basic operation was unknown to me, so even making
SSH work was a victory, then virtual desktop was another victory. It works now!

My question to you, is how to make RPi connect to internet as well as being hooked via virtual
desktop to my laptop. Is it possible to somehow share internet from laptop to RPi??? Or I have to use
usb hub anyway to hook a wi- dongle???

Thank you in advance,


Alex

Alex
18TH JULY 2016 AT 9:54 PM

Must have mentioned, I am on Mac…

Alex
18TH JULY 2016 AT 10:04 PM

Ok, disregard! I found solution, it was just to enable sharing, somehow RPi connected itself.
Fantastic!

 gbaman
24TH JULY 2016 AT 9:10 PM

It is very possible to forward it, with Mac OS, you just use Internet Sharing from the Sharing
section in System Preferences. For Windows, am not sure though, a few people though I believe
have documented it in the comments below.

fury0
18TH JULY 2016 AT 10:01 PM

Great work!
A must on the minibian for Pi zero!

https://blog.gbaman.info/?p=791 42/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Thanks!

linus
19TH JULY 2016 AT 8:12 PM

So… would you theoretically be able to connect two pi0 together using this method? (One being
powered over the pwr port).

 gbaman
24TH JULY 2016 AT 9:13 PM

Don’t see any reason why not. James has though gone even better with one of his projects, using a
Raspberry Pi 3 and x4 Pi Zeros attached via USB using same method as described above. Is very
cool –

TAdeJong
21ST JULY 2016 AT 10:50 PM

For those running a recent avor of Ubuntu a few more pointers to set this up nicely:
– In the Network Manager for the wired connection, under IPv4 set “Method:” to “Shared to other
computers” in other to let your computer give an IP address to the zero and share the internet
connection of your computer. Of course this is possible to con gure for yourself, but this one-click
option is very nice to have.
– Each reboot the zero will have a new MAC-address, showing up as a new wired connection in the
network manager, requiring to do the con guration once again. To solve this, we can add some more
parameters to cmdline.txt. First look up the current MAC addresses:
“$ dmesg -T | grep MAC”
Now add to the end of cmdline.txt:
“g_ether.host_addr=xx:xx:xx:xx:xx:xx g_ether.dev_addr=xx:xx:xx:xx:xx:xx”
Of course replacing the xx’s with the found mac addresses. Now your pi will always show up as the
same device and be automatically bridged to the internet connection of your computer.

(@ PhilK )

AndrewS
22ND JULY 2016 AT 12:49 PM

There’s lots of other great PiZero USB-networking info over at


http://raspberryjamberlin.de/zero360-part-2-connecting-via-otg-a-cluster-of-raspberry-pi-zeros-
to-a-pi-3/

https://blog.gbaman.info/?p=791 43/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Dan
26TH JULY 2016 AT 11:17 PM

This is a little bit more advanced, might be a better question for source forge, but I will start it here.

I use a USB wi adaptor for connecting to my network when I am at home, but would like to also use
this trick to connect when I am not near a wi point I have con gured (yet..).

Is there a way to have a boot script that rst checks for a wlan0 device, and then if not fail over to
the USB connection described here?

Derek
28TH JULY 2016 AT 2:48 AM

Thanks for posting this guide. I tried it on my new raspberry pi zero and it seems to work ne until
the very last step.

My machine: windows 7 with itunes installed

I followed all the steps, and at the very end I *am* able to ssh to raspberypi.local using the command
“ssh pi@raspberrypi.local“. However it doesn’t seem to accept the default password! The default
password should of course be “raspberry”, but it always says Permission denied, please try again.

Any ideas on what I can do to see what I might be doing wrong?

Charles
1ST SEPTEMBER 2016 AT 5:17 AM

Did you ever nd a solution?


Having similar issue from Ubuntu.

Jason
28TH JULY 2016 AT 10:40 PM

Awesome

Jag
29TH JULY 2016 AT 9:09 AM

https://blog.gbaman.info/?p=791 44/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Just got my Pi zero connected directly to wi network. Followed all instructions as above but usb
Ethernet was showing as no ip. I was checking to see if connecting directly to wi will work and it
worked, i used one of those usb wi adapter with micro usb to usb otg. BTW I was using Jessie lite.

https://www.raspberrypi.org/documentation/con guration/wireless/wireless-cli.md

pete
5TH AUGUST 2016 AT 9:30 PM

Great blog! USB connection from PC to Zero is exactly what I need, but I’m getting :
RNDIS/Ethernet Gadget – no driver found

on Windows 8, do I need Win 10?

(I checked, Bonjour is running, double-checked con g le edits. Got a dev friend at work to try
connecting from his Linux machine, using avahi he could see it, but could not ssh. Avahi showed only
IPv6, not v4, could this be an issue?

Robby
16TH AUGUST 2016 AT 4:46 PM

Just curious…maybe someone asked this already, but…Could you connect it as a ethernet device to
another pi zero?

 gbaman
22ND AUGUST 2016 AT 9:45 PM

There is no reason why not. But would need to either x the IP address of both Pis, or have one be
a DHCP server.

Robby
23RD AUGUST 2016 AT 7:43 PM

It worked. I ssh’ed into the Pi Zero from my windows machine and installed xrdp. Once done I
disconnected from the usb and connected it to my P1 3. I installed Remmina on it to connect to
the raspbian desktop on the Pi Zero. Don’t know what purpose it word serve but it’s possible.

Robby
23RD AUGUST 2016 AT 7:44 PM

https://blog.gbaman.info/?p=791 45/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

*would serve – lol!

tedder
21ST AUGUST 2016 AT 9:33 PM

Hmmm. I’m trying to get a Pi Zero without needing a console cable or anything else “magic”. I have a
miniHDMI adapter so I can see that the Zero actually boots up (into X).

After booting and then putting the card back in my OSX machine, the `cmdline` looks like this:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2


rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether

I’ve tried connecting to `raspberrypi.local` and to `169.254.64.64`. Neither work. I’m plugging in to
the ‘USB’ port (J10) and using a cable that transmits data on other devices.

Any suggestions? Are there any other “zero console access needed” things to do? The older
methods had con guration on the OS itself, not just the boot partition. I don’t see that any other
gadget modules are possible without console access.

AndrewS
22ND AUGUST 2016 AT 11:58 PM

According to the instructions at the top of this page, you need to edit both cmdline.txt and
con g.txt

The two numbers after 169.254. are randomly-generated, so trying to connect to a speci c IP
address is unlikely to work (which is why you need to have Bonjour running).

tedder
23RD AUGUST 2016 AT 12:09 AM

I didn’t mention the con g.txt because it was trivial. I did try running nmap on the whole class B
and found a couple of possible hits, nothing paid off. `dns-sd -B _ssh` failed to nd anything.

Think I’ll get an OTG and keyboard and go that route for setup. (I have the IoT pHAT wi board,
so it’s just the yak shaving required to set that up)

https://blog.gbaman.info/?p=791 46/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Pingback: UPDATED GUIDE: Turning your Raspberry PI Zero into a USB Gadget #raspberrypi #pizero «
Adafruit Industries – Makers, hackers, artists, designers and engineers!

Heimo
30TH AUGUST 2016 AT 9:42 PM

tried on Windows 10 64bit, it seems that Linux is detected as COM instead of RNDIS once you
plugin the pi0 (see here: http://answers.microsoft.com/en-us/windows/forum/windows_10-
networking/windows-10-vs-remote-ndis-ethernet-usbgadget-not/cb30520a-753c-4219-b908-
ad3d45590447?page=1). There are some xes suggested there, none worked for me.

Only after update Driver for that com (Driver Manager, COM-device) to be a kindle (no joke)
following this http://www.mobileread.com/forums/showthread.php?p=3283986 it worked like a
charm

Skiiid
28TH NOVEMBER 2016 AT 6:54 PM

Thanl you very much!


Solved my problem too.

Charles Jones
4TH SEPTEMBER 2016 AT 5:19 AM

I went into this blind and followed the directions to no avail, until today.

I see several posts by with people describing very similar issues so I thought I’d publish my
foolishness.

My environment is a Windows 10 host running Ubuntu 14.04 as a guest VM. When I plug the pizero
into a USB port the VM manager lists it under removable devices. In this case it shows up as Netchip
RNDIS/Ethernet Gadget. …. all good so far.

From a linux shell I can see the interface for usb0 with mac address for IPv4 and IPv6…. again all
good so far.

So “ssh pi@raspberrypi.local‘ as documented…. BUZZZ denied


couldn’t resolve hostname

https://blog.gbaman.info/?p=791 47/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

how about “ssh pi@raspberry.local“… BUZZZ denied

Here’s where I went wrong. Instead of focusing on the hostname resolution I confused myself by
attempting to connect to the IPv6 address of the usb0 interface as many others describe above.

it pings
ping6 fe80::4c15:a8ff:fe6f:ff8e%usb0

so
ssh -6 pi@fe80::4c15:a8ff:fe6f:ff8e%usb0
codiak@ubuntu:~$ ssh -6 pi@fe80::4c15:a8ff:fe6f:ff8e%usb0
The authenticity of host ‘fe80::4c15:a8ff:fe6f:ff8e%usb0 (fe80::4c15:a8ff:fe6f:ff8e%usb0)’ can’t be
established.
ECDSA key ngerprint is 77:b7:05:4c:7b:7f:8f:e5:74:4f:8d:37:32:1a:e2:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘fe80::4c15:a8ff:fe6f:ff8e%usb0’ (ECDSA) to the list of known hosts.
pi@fe80::4c15:a8ff:fe6f:ff8e%usb0’s password:
piPermission denied, please try again.
pi@fe80::4c15:a8ff:fe6f:ff8e%usb0’s password:
Permission denied, please try again.
pi@fe80::4c15:a8ff:fe6f:ff8e%usb0’s password:
Permission denied (publickey,password).

Now I’m confused and ended up wasting a bunch of time wondering why the default password for
raspbian isn’t work… cursing a lot… wishing I’d gotten more than 4 hours sleep in the last 24… etc

Keep in mind I have lots of Pi’s… this was just the rst zero and I was trying to keep it to a single
cable

Went to bed, got 8 hours this time and setup a FTDI console to so I could check the security logs on
the PIzero….
after a couple more failed attempts and NO logs produced, it was clear I was doing something
wrong….

The punchline:
Thinking the USB0 interface on my Ubuntu machine was where I needed the IP was my mistake…
rather I needed the Ipv6 address or IP address from the PI side! For whatever reason and I really
don’t care why, raspberrypi.local just wasn’t created… all I had to do was add an entry to /etc/hosts
for it using the IP from the PIzero.

https://blog.gbaman.info/?p=791 48/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Now this does beg the question as to how you get the PI ip when you can’t log in to the device in the
rst place, but I digress. if I’d been thinking day I’d have saved myself a lot of aggravation… there are
simple ways to scan for ips that I’ll leave for people to google if needed.

Last thought…. in my rst attempts the ping6 worked… ssh was attempting to connect to
something… the answer is simple, usb0 was a loopback to my ubuntu vm! Thank god I didn’t have a
local pi user… that would have really blown my mind.

ssh pi@

Dave Noice
6TH SEPTEMBER 2016 AT 8:32 AM

Didn’t want to install Bonjour or any other name service.

After enabling ICS on the PC’s network adapter, the gadget network adapter becomes
192.168.137.1 and the Zero is assigned a random address on the 192.168.137.x subnet.

A quick way to determine the assigned address is to open a command prompt and type: arp -a

That should return a screen similar to this:

Interface: 192.168.137.1 — 0x14


Internet Address Physical Address Type
192.168.137.17 1a-3c-b4-07-2d-f1 dynamic
192.168.137.255 ff-ff-ff-ff-ff-ff static

Look for the 192.168.137.x address that is followed by the word “dynamic”. That should be the
address you need for SSH.

Kash
15TH SEPTEMBER 2016 AT 11:34 PM

Anyone got this working with multiple pi zeros? That is, have more than one pi zero connected to a
host and be able to ssh into both of them.

 gbaman
23RD SEPTEMBER 2016 AT 10:12 PM

https://blog.gbaman.info/?p=791 49/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Yip, this has been done a few times. James from Berlin Raspberry Jam for example has written up
how he did it with different hostnames for his Zero360 project. A nice way to do it as opposed to
the other option of xed IP address.

Graham Toal
25TH SEPTEMBER 2016 AT 2:38 AM

Long story short, I nally got this to work. 1) MUST use the usb slot nearest the HDMI slot. The
other one only implements power, no data. 2) At least on my Win10 portable, it is actually sensitive
to which USB socket on the PC that I connect the Pi to. One works, two don’t. (Different internal
hubs).
Since I already had a Pi connected on a shared connection using 192.168.137 on the wired ether
interface, the Zero was assigned an address in the 169.254 space. It has a connection to the PC; I
haven’t yet tried sharing to it. Hopefully I can share to both pi’s.

Graham Toal
25TH SEPTEMBER 2016 AT 3:30 AM

I was able to share the wi internet connection with both the Pi2 which is directly connected to
my Portable using an ethernet wire, and the Pi Zero which is on USB:

From http://superuser.com/questions/656998/windows-7-share-internet-connection-with-
multiple-network-interfaces

Disable internet connection sharing if you have enabled it before.

Select both LAN adapters TO WHICH YOU WANT SHARE INTERNET (by holding Ctrl and
clicking on LAN cards).

Right click on one of selected and chose from dropdown menu “create bridge connection (or
similar)”.

From now all LAN settings of these LAN cards you should enter in now created bridge connection.

Now use the standard internet connection sharing to this bridge from the LAN adapter which
connects to network.

@Archit3cture
26TH SEPTEMBER 2016 AT 12:39 AM

https://blog.gbaman.info/?p=791 50/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

This worked great except for one problem, my computer wasn’t recognizing the Pi by its hostname
“raspberrypi.local” when attempting to connect via SSH (I am using Ubuntu 16.04 LTS). An easy x
was to go into my connection settings for the Pi (Recognized as wired/ethernet connection #3) and
change the IPv4 connection settings to “Local-link only”. After that, SSH was cake. However if you
have the IP of the Pi upfront you may not need to change the connection settings what so ever. Now
that I am writing this post I realize that I could have just found the IP address of the Pi in connection
settings and SSHed to that address. I guess whatever oats your boat (or just works). Hope my
comment can be of use!!!

Ian Sutherland
28TH SEPTEMBER 2016 AT 8:04 AM

Interesting article. I currently have a line in my con g.txt referring to a dtoverlay for a USB DAC
attached to my RPi Zero. Is it possible to have multiple dtoverlay references?

ben
4TH OCTOBER 2016 AT 7:06 PM

I’m on ubuntu 16.04 and it didn’t work for me.


The network manager was trying to connect to the raspberry pi without success… BUT I read the
comment of AndrewS (2 June) and followed its instructions. It works like a charm now.

Thank you all.

Jerry
6TH OCTOBER 2016 AT 7:20 PM

I’ve had mostly success with this approach. The rst thing worth mentioning is that Ubuntu
16.04.1’s Network Manager seems to have automated much of this (port forwarding, IP
masquerading etc). I initially used Ubuntu 14.04 and followed the stated procedures to manually
con gure both the host PC and the PiZ. That all worked. I had a 16.04.1 PC sitting idly nearby, and I
decided to give it a try also. I should rst mention the PiZ had the ‘con g.txt’ & ‘cmdline.txt’ changes
(including xed MAC addresses) done at this point. The ease of the 16.04 con guration was
amazing!!!
1.) Plug in the PiZ, after 10-15s the net-manager attempts to connect (propagating radio waves).
2.) Click the net-manager icon & select ‘Edit Connections’. Choose the latest wired connection;
select the IPv4 tab; select “share with other computers”. Make any other desired changes and save
this & within several seconds the connection is established. The net-manager makes all the IP
forwarding and masquerading changes (Do a ‘iptables -L -x’ before/after connectiong if in doubt). It
also creates a ‘10.42.0.0/24’ subnet for the rst device, a ‘10.42.1.0/24’ for a second PiZ. (These

https://blog.gbaman.info/?p=791 51/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

subnets will be troublesome later on…)


3.) From a terminal on the host, SSH login to the PiZ.
$> ssh raspberrybi.local -l (pi, or your user account)
4.) You’ll be asked for a password (‘raspberry’ in the case of ‘pi’)
– at this point you’ll be in. DNS and routes will be working!
5.) To test DNS, ‘ $> ping google.com’. It should be working. ‘apt-get’ etc should also work. You
should be able to ping other devices on your local LAN.
—- What’s NOT possible —-
I’m not a networking expert so perhaps there a work-arounds for this issues.
a.) Since the PiZ subnets are unique (10.42.0/16) they will not play with devices on your LAN
(192.168.0.0/24) I added routes on the ‘192.168’ subnet devices to allow ‘10.42/24 access’ – but I
cannot ping into a Piz from a 192.168 machine.
I can ping a 192.168 device from the PiZ – but that’s port forwarding and/or masquerading at work.

— Does anyone believe it’s possible to access a PiZ that’s running ‘ethernet USB’ from another local
LAN machine?
(other than the machine it’s USB connection is physically on)
Many thanks.

Brad Anderson
11TH OCTOBER 2016 AT 12:34 PM

Anyone had success doing this with a Macbook running OSX 10.12 Sierra?

RPi zero works on my Windows 10 PC but isn’t detected at all on my Macbook, RPi zero boots up
but doesn’t show in System Preferences / Network

Ray H
14TH OCTOBER 2016 AT 9:50 PM

Just got this working on Windows 10. Didn’t work at rst, rebooted the pi with a keyboard, I
checked “ip addr” is showing a usb0 network device, so it’s de nitely ready to go. So plugged in back
into the PC and ssh into it with Putty without a problem, maybe it just need some time to sort out
DHCP, I don’t know.

Anyway, ssh’d in and realised the pi could not get online, so back to Windows and created a bridged
connection between the RNDIS adapter and my normal LAN adapter.

Go here:
Control Panel\Network and Internet\Network Connections

https://blog.gbaman.info/?p=791 52/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Then highlight the two adapters you want to bridge, right click and create a bridge connection,
that’s it.

The pi then took a couple of minutes to pick up a new ip address from the router, and is now part of
my LAN. I can get online to update packages.

Thanks for the guide!

Ben Coleman
18TH OCTOBER 2016 AT 2:55 AM

A question: If you use this to set up a Rpi Zero, and then wish to use the Rpi Zero headless, but
connected via the network (e.g. disconnect the USB cable to the PC, and connect a WiFi dongle
instead), is it necessary to reverse any of the extra settings in order to have the WiFi dongle (or
ethernet dongle) work? Can you leave the network-over-USB con g in place, and still have the Zero
recognize and use a different network device if you disconnect the PC and instead plug in the
network device, or do you have to reverse the network-over-USB con g?

 gbaman
20TH OCTOBER 2016 AT 8:35 PM

Yip, you don’t need to do anything to still allow USB to work as normal. But is worth keeping in
mind is using the DWC2 driver, instead of the more optimised driver the Pi Foundation has been
working on over past few years. So it will be work ne, but may not be as fast.

Ben Coleman
21ST OCTOBER 2016 AT 5:35 AM

So, if network speed once headless is a concern, we’ll want to disable DWC2 before going
headless. Is it necessary to back the changes out of both les, or will backing out just one get
DWC2 out of the way (just in case we want to make it a tad easier to get back to USB network
mode in case something goes wrong in headless mode)?

Bob
22ND OCTOBER 2016 AT 10:00 PM

Hi-
I have got this working on Win10 but, getting to work on my Mac OsX Sierra laptop is a failure so
far.
I made the two le changes (and con rmed it working on Win10; note: it only works in the USB

https://blog.gbaman.info/?p=791 53/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

nearest mini-HDMI, but you knew that).


When I plug it into my make: tried to ssh or ping raspberrypi.local, but no one home.
I was able to detect that it connects as a gadget using the (built-in) Network Utility. In the “info” tab,
up pops “RNDIS/Ethernet gadget (en8)”. It lists the hardware address but, the ip address is blank
. Curiously, unplugging and re-plugging, it comes up with a different hardware address each time.
Further, I used Bonjour Browser (http://tildesoft.com/) and found lots of Bonjour services (this will
be useful!) but alas, no raspberrypi.local

I am at a loss: Anyone have any further suggestions?

Steve Amor
1ST NOVEMBER 2016 AT 4:04 PM

Got this working well with Ubuntu 16.04.


Not so good with Ubuntu 16.10, could only SSH when I found the zero’s IPV4 address and no zero
internet access via the PC.
Would love to get it working with a Chromebook if anyone has any ideas?

Pingback: Pi Zero Based GPS data logger – rtklibexplorer

Arvid Kongstad
7TH NOVEMBER 2016 AT 10:48 AM

If you (like me) can’t get this to work on mac / OS X / macOS, try following these detailed step-by-
step instructions:

1. Download Raspbian (https://www.raspberrypi.org/downloads/raspbian/)


2. Download ApplePi-Baker (http://www.tweaking4all.com/software/macosx-software/macosx-
apple-pi-baker/)
3. Flash Raspbian onto microSD card using ApplePi-Baker
4. Open boot/con g.txt and add dtoverlay=dwc2 at the very bottom
5. Open boot/cmdline.txt and add modules-load=dwc2,g_ether after rootwait with a single space
before and after
6. Unmount SD card and put it in the Pi Zero
7. Attach USB data cable to the Pi’s USB (not PWR) port
8. Connect the USB cable to Mac and wait 90 seconds
9. Run ifcon g | grep broadcast
10. Run ping

https://blog.gbaman.info/?p=791 54/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

11. Run arp -a


12. Run ssh pi@ (password: raspberry)

My problem was that raspberrypi.local couldn’t be resolved, so that’s what steps 9-12 takes care of.

Hope that helps =)

Arvid Kongstad
7TH NOVEMBER 2016 AT 10:51 AM

Step 10 shall say:


ping [broadcast IP address]

Step 12 shall say:


ssh pi@[IP address of raspberrypi.local]

Scott Schulz
26TH NOVEMBER 2016 AT 4:23 PM

@Arvid Did you need to install anything else onto your Mac, e.g. a DHCPd server? Are you
running Sierra?

I’ve tried rewriting the cards several times, editing the les to con rm the settings are now in
there, but no joy on getting it to work.

I can nd other pi’s on my network (Pi3’s) which I have renamed, but not the zero. Just
wondering if I am missing a piece.

Scott Schulz
26TH NOVEMBER 2016 AT 4:26 PM

Also, I am using 2016-09-23-raspbian-jessie-lite so I wanted to ensure this worked with


Raspbian Lite. Is it possible those modules are only in the GUI version?

Arvid Kongstad
11TH DECEMBER 2016 AT 1:04 PM

@Scott Schulz No, I didn’t install any special software for this, and my Mac was running OS X
El Capitan. I used TextEdit to edit the con g les (don’t know if that could make a difference).
Are you sure you connected the Pi Zero via its USB port (not PWR)?

https://blog.gbaman.info/?p=791 55/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Scott Schulz
11TH DECEMBER 2016 AT 8:32 PM

@Arvid Kongstad Well, initially I was, but caught that pretty quick. I spent two days
messing with the crazy thing: rewrote the card several times, checked the con g les (using
vim), tried it on Mac and Linux, and then… nally looked at the tag on the USB cable and
realized it came with a gunlight, doh! That cable was intended for charging ashlights, and
apparently only has the power leads wired up. So I went out and got another cable, and
bingo! So thanks for the pointers, and thanks to OP for this post!

Zach
28TH MARCH 2017 AT 2:32 AM

Thanks! I got stuck on this and it’s because I was using the pwr not usb port Thanks for
the tip!

Riccardo Grespan
7TH NOVEMBER 2016 AT 3:58 PM

Hello, I have a problem. I’m able to connect the pi zero on my ubuntu laptop, I have the IP both in
Link-Local and shared with other computer mode, but when i try to connect via ssh it gives me
“connection refused: port 22”, It seems to me the the port 22 is closed or something like this. I tried
with other port with the same results.

I hope someone can help me.


Thanks you.

Steve Amor
8TH NOVEMBER 2016 AT 9:34 PM

Working well with Ubuntu 16.04 with PiZero internet access.

Can only ssh once I nd the IP address with Ubuntu 16.10.

Would like to get working with a Chromebook if anyone has any thoughts?

nicolas
12TH NOVEMBER 2016 AT 2:42 AM

https://blog.gbaman.info/?p=791 56/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

I have connected and I have done everything of the tutorial, but in control panel I appear as COM3
port
help me :c

NilsB
19TH NOVEMBER 2016 AT 10:49 PM

Andy,
thanks for your work. Though I had notice a problem on one of my pcs with this con guration. I
could make it work only when powering up the Raspi Zero beforehand. If I didn’t power up
beforehand and connect only directly through USB I receive the warning “USB Device not
recognized”. After a huge search I found a possible solution:

A small delay in the boot sequence worked for me:

In /etc/rc.local I put

/bin/sleep 5
/sbin/modprobe g_ether

In cmdline.txt I added

modules-load=dwc2

and in con g.txt only

dtoverlay=dwc2

And then it worked well.

dave
21ST NOVEMBER 2016 AT 2:49 PM

@nicolas: Same here, I can’t get it working and tried on two Windows 10 x64 PCs. Shows up as
Serial USB Device (COM3). In the Model-Field it states RDNIS/Ethernet Gadget, but that’s it. Not
virtual network adapter.

I guess it has something to do with hardware ID of the Pi Zero?!

https://blog.gbaman.info/?p=791 57/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Rick
26TH NOVEMBER 2016 AT 3:44 AM

For those that only get the USB Serial COM3 with Windows 10, go to the Device manager, right
click on this USB Serial device and select Update Driver. Select Windows should automatically
install the best driver. It will then download and install the USB Ethernet/RNDIS Gadget driver.
Tested on the latest fast ring build 14971, but should work on others.

Skiiid
28TH NOVEMBER 2016 AT 6:38 PM

I don’t know why but when I connect my zero with Windows 10 and your settings my device
manager shows me a new Serial Adapter “Serial USB-device COM7”.

I cant ping or connect via putty to raspberrypi.local.


I have installed Bonjour.

Can anyone help me ?

Skiiid
28TH NOVEMBER 2016 AT 6:55 PM

nvm.
Solved by the command of “Heimo”

Dave
1ST DECEMBER 2016 AT 4:30 PM

@ Rick:
I also tried updating the driver but it didn’t work on my Windows 10 64-bit. It didn’t nd any
suitable RDNIS-Drivers. Also I don’t want to install non standard drivers because I want to use the
pi on multiple non-con gured pcs.

Is there a way to use pi zero as virtual network interface on all Windows 10 installations?

Laurence Cabenda
2ND DECEMBER 2016 AT 4:18 PM

Did some changes to Andrew Scheller script to make it work on Ubuntu 16.04 for me.

https://blog.gbaman.info/?p=791 58/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

https://gist.github.com/lfcabend/b28f85da53558998c6d8a8ff4b20d9e6# le-gist le1-txt

Kris
3RD DECEMBER 2016 AT 2:47 AM

i plugged my zero in my mac book and it does nothing lights don’t even light up

Kris
3RD DECEMBER 2016 AT 2:21 PM

I’ve plugged this in to moth my Mac book and windows computer. My Mac it comes up in network
connections with a IP address. But it says can’t connect on both my windows and Mac On my
windows computer it keeps trying to install the device. Any help??

daniel
3RD DECEMBER 2016 AT 2:42 PM

after feeling like a complete failure nally found this update https://www.raspberrypi.org/blog/a-
security-update-for-raspbian-pixel/
SSH is now turned off by default

Ingo
3RD DECEMBER 2016 AT 6:23 PM

I tried over hours now to connect to my Pi Zero untill I found this:

https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=167252

SSH seems to be disabled as default.


Simply add a le named “ssh” onto your raspi sd.

Regards

Ingo
3RD DECEMBER 2016 AT 6:27 PM

*This works for the “Connection Refused” problem.

Kris

https://blog.gbaman.info/?p=791 59/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

5TH DECEMBER 2016 AT 1:34 AM

OK so heres what i found. With the lines you said to add the ssh did not turn on. I had to boot up the
pi with my monitor and keyboard and turn it on then it works ne.

PJ
5TH DECEMBER 2016 AT 4:10 PM

So I’ve gone through these instructions and Adafruits instructions and cannot get this to work. I
even tried downloading OpenSSH to make sure Putty wasn’t messing with me. I have Bonjour
installed, I have shared teh pi with my WiFI conncetion, I have made sure I have the latest drivers.
The pi has a set IP. I have tried connecting SSH to raspberrypi.local, pi@raspberry.local, the ip
address alone. I have tried redoing the sd card. I must be missing something. Anybody got a
hawkeyes view of what it is?

Brad
8TH DECEMBER 2016 AT 12:55 AM

You may have to create a le “ssh” on the boot partition. I was getting connection refused on the ssh
stage but after going back and placing this le then on the next boot it was running.

See “method 4”

http://www.raspberrypi-spy.co.uk/2012/05/enable-secure-shell-ssh-on-your-raspberry-pi/

Arvid Kongstad
12TH DECEMBER 2016 AT 9:04 AM

@Scott That’s a bummer. Oh well, I’m happy you found the problem/solution! Also (for
completeness), I’ve only tried with Raspbian Lite.

Mark
13TH DECEMBER 2016 AT 12:55 AM

BTW, if you get SSH ‘connection refused’ and your using the latest Jessie Pixel, use this simple x:

https://www.raspberrypi.org/blog/a-security-update-for-raspbian-pixel/

Berti
13TH DECEMBER 2016 AT 7:39 PM

https://blog.gbaman.info/?p=791 60/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Hello Andrew,

thankx for the instructions. Aside from the SSH con guration everything worked as you explained
it.

Because of security improvements, the newest Jessie images have switched off SSH by default.

You can circumvent this by creating an empty le named “ssh” (without any le extension) in the
boot partition of the sdcard.

Berti

Zeev
20TH DECEMBER 2016 AT 4:02 PM

I followed your instructions.

After some trouble with the driver for Ethernet gadget that was missing and which my Win 7 could
not nd by itself, I found instructions on the Web where to nd it and how to install it. I then ran
“ping raspberrypi.local -4” on Windows command line and got a reply from 169.254.114.213 (I saw
somebody above also getting a 169.254 address from the Pi). So this must be the address of the Pi. I
made sure that this is the Pi Zero I am talking to by disconnecting WiFi and LAN adaptor – and yes,
this was the Pi Zero as I still got response to the ping. To make double sure I disconnected the Pi –
and the responses to ping stopped. It was the Pi all right. I reconnected and got the ping response
again.

I then ran ipcon g in Windows and saw that the address of my PC on this interface is
169.254.114.148, net mask 255.255.0.0. Moreover, I checked the ipv4 properties of the interface
and saw that my PC is con gured as a DHCP client on this network. So I assumed that the Pi acts as
the DHCP server, which seems logical given that my PC is a client and that the address my PC has on
the interface is in the same subnet as the address of the Pi. So far so good.

However, when I tried to use Putty to ssh into raspberrypi.local :22 it did not work – the Pi did not
respond at all. I tried the numeric 169.254.114.213:22 – same result. I tried to use WinSCP to do
SFTP into the Pi – refused to connect, saying that the host does not listen to SFTP but listens to FTP.
Tried to connect with FTP – no joy.

To summarize, the Pi returns a ping but refuses to talk ssh and sftp. Please help!!

https://blog.gbaman.info/?p=791 61/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Jordan
22ND DECEMBER 2016 AT 4:48 PM

Hey guys I need help whrn I try and type in raspberrypi.local in putty and press enter putty starts up
but it appears with a error box reading ‘network error: connection refused’

Rafael
29TH DECEMBER 2016 AT 6:28 AM

Hi guys,

I have a problem with g_mass_storage module at Raspberry Pi Zero. When i connect with PC,
Windows does not recognize and appears “Unknown Device” and with others and other devices
with usb does not recognize too. I tried with g_multi too, I followed several tutorials on the internet
and it did not work.

Can someone please help me?

AndrewS
29TH DECEMBER 2016 AT 5:42 PM

“and other devices with usb does not recognize too”

Sounds like perhaps your USB ports are faulty?

Rafael
1ST JANUARY 2017 AT 6:07 AM

I do not think I was that clear. When I connect the raspberry pi as mass storage to another
device that has usb (eg small sound box) it does not recognize and can not connect and
communicate. The usb ports on the notebook are working normally. Do not you have a video of
that part of the setup? Thank you

Charles
3RD JANUARY 2017 AT 4:33 PM

After doing every steps as explained (modifying con g.txt and cmdline.txt, enabling ssh, checking
USB cable, using correct USB port on RPi Zero, checking Bonjour service is running, enabling a
shared internet connection with the Pi, trying different USB port on the computer), my RPi Zero has
never been detected by the computer as a “USB Ethernet/RDNIS Gadget”.

https://blog.gbaman.info/?p=791 62/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

I bought another RPi Zero, used same SD card, plugged it in and magic it was directly detected as a
“USB Ethernet/RDNIS Gadget” which allowed me to connect with Putty through ssh and
raspberrypi.local!
I guess there is a hardware issue with my rst RPi Zero…so as it costs 5$, don’t spend too much time
trying to connect it via USB and get another one!;)
I bought both my RPi Zero on The Pi Hut and ran Raspbian Jessie Lite (2016-11-25).

Robert Dixon
16TH MARCH 2017 AT 10:49 PM

Did you ever manage to get your original Pi Zero to work as well?

I have the same issue no ping/ssh response but these Pi Zeros are pretty hard to get a hold of and
was lucky to get one when I did.

Would appreciate it if there was a solution to the issue other than ‘hunt for a new one’.

Calvin Brice
10TH JANUARY 2017 AT 9:26 PM

I had everything setup and working correctly until I got to the part where I ping google from my pi
zero. It would ping successfully but when I went to do “sudo apt update” or “sudo apt upgrade” it
would just hang there. It took me a while to gure out but it was my rewall on my pc. Disabled it
and voila everything is working!

Laptop: Windows 10
Raspberry Pi Zero: Raspbian
USB OTG cable

TLDR: Disable rewall or add an exeption

Steve Amor
19TH JANUARY 2017 AT 8:31 PM

Some more Ubuntu help:

After struggling with Ubuntu 16.10, I reverted back to Ubuntu 16.04 and a clean build of Jessie Lite
(2016-11-25).

My IPV4 setting is “Shared to other computers”.

https://blog.gbaman.info/?p=791 63/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

I added the additional to the end of cmdline.txt to stop generating Wired Connections on each boot:
g_ether.host_addr=26:7f:62:5c:48:86 g_ether.dev_addr=d6:fe:44:ad:8f:13

I could ping raspberrypi.local but when I tried to ssh pi@raspberrypi.local I kept getting Connection
reset.

Turned out the ssh key les (/etc/ssh/) on the pizero were zero bytes. I deleted them all and then
regenerated them following the instructions here (using the ssh-keygen command):
http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html

Hey presto, I could then ssh pi@raspberrypi.local

Amirhossein Kiani
26TH JANUARY 2017 AT 1:12 AM

Great post!!

Any idea how I can share the OTG USB across the host device and a Wi dongle?

The setup I have includes the Pi Zero acting as USB Mass storage (which I got to work) but want the
Pi Zero to also have WiFi access (don’t want to share internet with the host)

I tried using the power OTG port with no success. I also tried using a USB Hub and using a Male-to-
Male USB cable, but again the device did not appear as Mass Storage.

Any help is appreciated!

Dub Steppacious
12TH FEBRUARY 2017 AT 3:42 PM

i beleive you will have to send the ethernet packets over the gpio bus if you want standalone
network access. google “ethernet over gpio raspberry pi zero”

AndrewS
14TH FEBRUARY 2017 AT 11:37 AM

Yup, I guess you should investigate one of these options (others solutions may exist too)
http://raspi.tv/2015/ethernet-on-pi-zero-how-to-put-an-ethernet-port-on-your-pi
https://redbear.cc/product/iot-phat.html
https://shop.pimoroni.com/products/esp8266-phat

https://blog.gbaman.info/?p=791 64/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

USB hubs only work when the USB port is working in host/master mode – they don’t work
when the USB port is working in device/slave mode. This is why the USB OTG only works on the
PiZero and not the Model B Pis, as the model B Pis already include a built-in USB hub (forcing
them into master mode).

Pingback: Blog | Nick Wallace

Pingback: Pi Zero SSH over USB – Site Title

Simon
21ST FEBRUARY 2017 AT 9:38 PM

I would just like to say a HUGE thank-you to Andrew for sharing this. I nally decided it was time to
do something with a Zero I bought a LONG time ago (a PiHut Zero Essentials kit version) and to cut
a long story short, couldn’t get any peripherals to work – I could see it booting up OK, but couldn’t
get a keyboard to work, or a USB wi dongle, so was pretty much stuck. The only suspicious thing in
common was the “OTG USB” cable was the one that came with the kit, and the only thing I had that I
could use to attach the keyboard/Wi . So, after a bit of hunting around, I came across this post, and
less than 30 minutes later I’m posting this thank-you as I watch “apt-upgrade” messages y past in a
terminal window on my iMac with a working Pi Zero attached to a USB hub on the Mac.
Many thanks Andrew, hugely appreciated.
Simon

Joel Hutton
3RD MARCH 2017 AT 12:56 PM

Doesn’t work with pi zero W and raspbian jesse lite. Network interface shows up on ubuntu but
raspberrypi.local does not respond to ping or ssh

Alvipe
8TH MARCH 2017 AT 1:09 PM

I had the same problem and I was only able to ssh by specifying the IPv6 address of the Pi, and the
connection only lasted a few minutes. After a few days of trying everything I found on the
internet with no results, I managed to make it work by chance, and actually the solution is pretty
simple.

https://blog.gbaman.info/?p=791 65/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

As you say, a USB network interface shows up if you click on the network icon on Ubuntu. You
have to click on edit connections, select the USB network connection and click edit. On that
window, go to the IPv4 tab and on method, select “Shared to other computers”. You can do the
same on the IPv6 tab. Wait a little bit until a connection is established and a IPv4 address is
assigned to your Pi, and then you should be able to ssh through USB with “ssh
pi@raspberrypi.local“. Every time you unplug and plug the Pi again, you have to do the above
steps. I don’t know if there is a way to automate this, that’s the next thing I want to try. I hope it
works for you, it worked for me.

Alvipe
8TH MARCH 2017 AT 1:15 PM

Sorry, the method is not “Shared to other computers” but “Link-Local only”, as some answers
above suggest. I’m not on an Ubuntu machine right now so I’ve couldn’t check if what I was saying
was correct.

Kaare Blakstad
17TH MARCH 2017 AT 9:19 PM

@Joel Hutton System Preferences -> Sharing -> Enable internet sharing service for the
“RNDIS/Ethernet gadget” and voila!

Chris
6TH MARCH 2017 AT 3:28 PM

Yea as above, struggling to get it working with the new RPi Zero W.
Not getting it show up as an adapter in Win10 like my other 4 RPi Zero’s do
Perhaps something was changed to accomodate the Wi functionality preventing the nice OTG
gadget bits working.

 gbaman
19TH MARCH 2017 AT 12:04 PM

I have just given it a quick test with the Pi Zero W, nothing different needed and it worked ne.

Daniel
8TH MARCH 2017 AT 3:17 AM

For anyone on Pi Zero W, I got this working doing only step 3 above (add ssh le to boot) and
creating a le on the sd card in the top level named, wpa_supplicant.conf, with the following

https://blog.gbaman.info/?p=791 66/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

contents:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_con g=1

network={
ssid=””
psk=””
}

As per, http://raspberrypi.stackexchange.com/questions/62888/rp-sd-card-wlan/62899#62899

Daniel
8TH MARCH 2017 AT 4:13 AM

Oh, just realized that wasn’t a fresh Jessie install but instead an image of my Pi 3.

feas
14TH MARCH 2017 AT 5:51 PM

Does this still work with pi zero v1.3 (camera)? I have been trying for weeks and have used
numerous guides and still can’t ssh or vnc into the zero via usb. So far usb-serial has been the only
way I can connect to it. My searching shows me there are alot of others in the same boat with the
v1.3. I have even used every image from the current to the beginning of may 2016.

 gbaman
19TH MARCH 2017 AT 12:07 PM

Yip, I can con rm it works ne for all 3 versions of the Pi Zero. So most likely is an issue with the
way networking is set up on your computer.

Stepan
16TH MARCH 2017 AT 10:07 PM

I tried it with zero w. On the rst windows 10 machine it did not work at all, but I was successfull on
the second one. Thanks!

Stepan
16TH MARCH 2017 AT 10:09 PM

https://blog.gbaman.info/?p=791 67/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Just a note: I tried it with raspberrian jesse lite

Robert Dixon
16TH MARCH 2017 AT 10:43 PM

Not working.

I followed all the steps but when I plug the Pi Zero into my laptop, Windows (10 Pro) makes the
drive insert sound but I cannot ping the Pi or SSH into it with Putty.

It does not appear in device management or network and sharing center so maybe its my laptop?

Would appreciate some support with this

 gbaman
19TH MARCH 2017 AT 12:09 PM

Try turning off all other network interfaces, sometimes pinging or SSH can get confused with
other interfaces.

AndrewS
19TH MARCH 2017 AT 12:18 PM

AFAIK it would only “get confused with other interfaces” if you have the same subnet (e.g.
192.168.1.*) assigned to multiple interfaces.
Although if you have two separate interfaces each con gured to the link-local 169.254.*.* range,
then I wonder if that might confuse things?

Chris
5TH APRIL 2017 AT 6:12 PM

Tried this on different pi zeros (zero v1.3 (x3) & zero W v1.1), different OSs (NOOBs & Raspbian
Jessie) and different computers (PCs with W7/W10 and RedHat), no luck. It is not ‘simple’.

RedHat sees all of the zeros, and even sees their mac addresses, but cannot connect.
Windows 7 sees the zero but gets a driver error
Windows 10 sees the zero, got a driver error initially, but wouldn’t connect.

Oh, and before someone mentions it, no it isn’t the USB lead – tried several… .

https://blog.gbaman.info/?p=791 68/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

Chris
7TH APRIL 2017 AT 6:49 PM

(pity my previous post has disappeared, but…)

I tried this with 5 Raspberry Pi Zeros (v1.3 & ‘Wv1.1), clean installs, etc, etc, but to no avail.
However, I did manage to communicate via the serial Rx/Tx, so that at least worked.

I nally got things working by:


i) installing Bonjour (I guess those with iTunes installed already had it – which probably explains why
it worked for some, not for others).
ii) boot the Pi from an external power source before connecting the data USB (I did check whether
there would be a con ict of power but it appears that as soon as power is detected on the data USB
the power drawn on the power USB drops to zero).

WilliamW
11TH APRIL 2017 AT 8:51 AM

Tried this out on a PiZ and W10 and then on my PiZW , using just the usb link (ie piowered via the
usb from my laptop). Worked a treat!
I’m in an AirBNB at the moment with wi , and using the usb link to re up the PiZW made getting its
ip address a doddle. And it will save a lot of faff in the future.
Very many thanks for this technique.

Cordyceps
28TH APRIL 2017 AT 2:59 AM

Followed these instructions and checked several times, using Ubuntu 17.04. It shows up in my
connections, but not when I use nmap, and all the ssh methods I’ve used fail to nd it. I’ve also tried
to ssh pi@ all the IPs returned by nmap to be sure. Is it potentially under some name besides
raspberrypi.local? Or is there possibly some con ict with my newer Ubuntu or Raspbian?

A.slow.Thinker
13TH MAY 2017 AT 12:51 AM

So im slow…. spent all day trouble shooting and nally decided to try a different cord….. turns out
that I was using a power only cord. So if any one just cant get it to work try using the cord to plug
your phone in. if it just charges and doesnt make any sounds its the wrong kind. Pretty obvious i
know but its easy to assume.

Thanks for the tutorial, once i got past my personal issues it worked great!
https://blog.gbaman.info/?p=791 69/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

zer0
16TH MAY 2017 AT 11:15 PM

Having problem sharing your internet to your pi zero on windows 10?

Right click on the wi icon bottom right of your screen and open the internet setup

Modify card parameter

Right click on your wi – Properties

Share

Check the rst box – OK

Now ssh into your pi raspberrypi.local

ifcon g

Copy your ip address (mine looks like 192.168.137.xxx)

Now close the ssh session and ssh into 192.168.137.172

ping 8.8.8.8 to con rm

enjoy

Pingback: 一根数据线玩转树莓派Zero – 树莓派中文站

Matt Ganis
26TH MAY 2017 AT 12:42 AM

Worked perfectly – rst try – on the Pi Zero.

I’m curious, maybe this was asked before, I didn’t see it in the comments, but why does only work on
a Pi Zero and a Raspberry Pi 3 ? Is there any solution for a Pi 3 ?

From a teaching perspective, the need for external display/keyboard makes working the Pi dif cult
– so I LOVE this solution for my Zero ! Thanks again !

https://blog.gbaman.info/?p=791 70/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

–Matt

 gbaman
24TH JUNE 2017 AT 9:01 PM

Unfortunately the same system can’t work for the Pi3, as it has the USB/Ethernet chip in the way.
It only really works on the Pi Zero, as the processor can directly talk to the device on the other
end of the USB cable.

AmanySI
27TH JULY 2017 AT 5:39 PM

it works with me on Pi ZERO W but the built in Wi-Fi is not working in parallel, So why there is a
con ict between the wi network and the USB which is works as Ethernet network??

HermannSW
25TH AUGUST 2017 AT 7:05 AM

Thanks again!
I did setup Pi Zero W Wi to connect to my home router before, and did your boot con g steps
without issues. Then I was able to login via OTG and Wi in parallel !

Hermann.

pi@raspberrypi05:~ $ who
pi pts/0 2017-08-25 05:55 (10.42.43.1)
pi pts/1 2017-08-25 05:57 (192.168.178.101)
pi@raspberrypi05:~ $ ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=45 time=24.7 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=45 time=20.0 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=45 time=18.1 ms

— 8.8.8.8 ping statistics —


3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 18.170/20.981/24.717/2.756 ms
pi@raspberrypi05:~ $

Eduardo Rotundo Soto

https://blog.gbaman.info/?p=791 71/72
3/1/2018 Raspberry Pi Zero – Programming over USB! (Part 2) | Andrew's blog

7TH NOVEMBER 2017 AT 1:15 PM

Hi!

I have a big problem and i don’t know if it’s possible to solve it, i can’t write le from computer into pi
zero when g_mass_storage it’s working, i wan’t to use raspberry as usb pen drive to transfer
information in both sides but in all cases the pi zero appears as read-only into OS

It’s possible change that? I know with this is possible the SD Card damage because receive corrupt
information

Thanks!!

Pingback: kkthx

DR
25TH DECEMBER 2017 AT 7:31 PM

Hi! Excellent guide!


I was using your guide to ssh into my Raspberry Pi Zero that had RetroPie image installed.
Couldn’t get it to connect via putty.
Found out that instead of using raspberrypi.local as the address.
The default when using retropie is retropie.local

Thought I would share to assist others who end up here.

https://blog.gbaman.info/?p=791 72/72

Вам также может понравиться