Instantly share code, notes, and snippets.

What would you like to do?
Simple guide for setting up OTG modes on the Raspberry Pi Zero

Raspberry Pi Zero OTG Mode

Simple guide for setting up OTG modes on the Raspberry Pi Zero - By Andrew Mulholland (gbaman).

The Raspberry Pi Zero (and model A and A+) support USB On The Go, given the processor is connected directly to the USB port, unlike on the B, B+ or Pi 2 B, which goes via a USB hub.
Because of this, if setup to, the Pi can act as a USB slave instead, providing virtual serial (a terminal), virtual ethernet, virtual mass storage device (pendrive) or even other virtual devices like HID, MIDI, or act as a virtual webcam!
It is important to note that, although the model A and A+ can support being a USB slave, they are missing the ID pin (is tied to ground internally) so are unable to dynamically switch between USB master/slave mode. As such, they default to USB master mode. There is no easy way to change this right now.
It is also important to note, that a USB to UART serial adapter is not needed for any of these guides, as may be documented elsewhere across the internet.

##Which process should I choose?
There are 2 routes you can take for setting up the Raspberry Pi Zero as a USB Slave (OTG mode).

  1. The quick route - The quick route doesn't require anything beside your Pi Zero, SD card and a Windows, Mac or Linux computer. It though only supports setting up the Pi Zero as a virtual Ethernet device (allowing full SSH, SFTP, VNC etc). For any of the other USB Gadget drivers (beside g_ether), use route 2.
  2. The modular slower, but more flexible route - This route requires a screen and keyboard to configure your Pi Zero once it has completed its first boot.

###1. Very quick way (No USB keyboard, mouse, HDMI monitor needed)
The newer method has now been brought out into a separate Gist, which can be found here.

###2. Modular, but slower to setup method For this method, a Pi Zero, SD card (with Raspbian Jessie lite or full), screen and keyboard are required.
You are able to set up any of the below modules using this method and are not just limited to g_ether. The required kernels are also now shipped with Raspbian 2016-05-10 releases and beyond. So no need to do a raspi-update.
No web connectivity is required, nor is a USB-UART adapter required for this method. This documentation is based off the initial excellent work done on this Github pull request.
Modules included

  • Serial (g_serial)
  • Ethernet (g_ether)
  • Mass storage (g_mass_storage)
  • MIDI (g_midi)
  • Audio (g_audio)
  • Keyboard/Mouse (g_hid)
  • Mass storage and Serial (g_acm_ms)
  • Ethernet and Serial (g_cdc)
  • Multi (g_multi) - Allows you to configure 2 from Ethernet, Mass storage and Serial
    In addition to the above modules, a few other (less useful) modules are included.
  • Webcam (g_webcam)
  • Printer (g_printer)
  • Gadget tester (g_zero)
  1. First, flash Jessie (only tested on full, lite version may also work though) onto a blank microSD card.
  2. (step only needed if running Raspbain version before 2016-05-10) Once it starts up again, run sudo BRANCH=next rpi-update. This will take a while.
  3. Next we need to make sure we are using the dwc2 USB driver echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt.
  4. And enable it in Raspbian echo "dwc2" | sudo tee -a /etc/modules
  5. Need to now pick which module you want to use from the list above, for example for ethernet echo "g_ether" | sudo tee -a /etc/modules. You can only pick one of the above modules to use at a time.

Using the modules

  • g_serial - To use the standard serial module, you need to tell the Pi to forward the serial console to it with sudo systemctl enable getty@ttyGS0.service, then you can connect to the device via Putty or Screen.
  • g_ether - Using virtual ethernet, you should simply be able to ssh into the address of your Raspberry Pi. To do this, there is a little extra configuration required though. There is a few ways we could set up the point to point networking. The proper way would be to set up a DHCP server on one of the ends. A far simplier was though is just to give the Raspberry Pi a fixed IP address. To do this, you will need to run echo -e "interface usb0 \nstatic ip_address=" | sudo tee -a /etc/dhcpcd.conf. You can then access the Raspberry Pi Zero by connecting to, or by using raspberrypi.local if your computer has Bonjour installed (Mac and most Linux OSs including Raspbian). Note this method does not support adding a fixed address to the cmdline.txt file. For that, you have to use the Ethernet only kernel below.
  • g_mass_storage - To have your Pi Zero appear as a mass storage device (flash drive), first create a mini filesystem in a file on your Pi with sudo dd if=/dev/zero of=/piusb.bin bs=512 count=2880 and set it up as a fat32 filesystem with sudo mkdosfs /piusb.bin. Then, when enabling it, add file=/piusb.bin stall=0 onto the end, for example sudo modprobe g_mass_storage file=/piusb.bin stall=0.

In theory, most USB devices should work alongside these kernels, to switch to USB OTG mode, simply don't use an OTG adapter cable and use a standard USB cable to plug your Pi Zero into another computer, it should auto switch.

Legacy guides

The legacy guides can be found on a separate Gist.


This comment has been minimized.

tyrower commented Dec 24, 2015

Great getting to take a sneak peak at this. Thanks. Downloading the archives as I type....


This comment has been minimized.

dblicken commented Dec 24, 2015

Fantastic! Thanks for sharing...


This comment has been minimized.

jarjartee commented Dec 24, 2015

This is a brilliant Christmas Pressie ;0)


This comment has been minimized.

mobluse commented Dec 26, 2015

It seems as if the last tar.gz-file is the same as the first. I have a Raspberry Pi Model A (and not Zero) and I then need files that are hard-coded to gadget mode, because the OTG-ID-pin is connected to ground, i.e. always host.


This comment has been minimized.

blackketter commented Jan 2, 2016

This is awesome, thanks! My Zero arrives tomorrow and this will be the first thing I try. You mention HID support but I don't see it in the list of modules you mentioned. Is it included implicitly?


This comment has been minimized.

bencord0 commented Jan 2, 2016

Is there a reason why the Jessie lite images won't work?
Is it missing a specific package? or does it have a different configuration file somewhere? Is the kernel, or one of the boot files different in any meaningful way?

Or has nobody tried it yet?


This comment has been minimized.

leopatras commented Jan 6, 2016

Hi gbaman, do you have a tip how to enable HID devices ( mouse, keyboard ) ? Thanks a lot in advance


This comment has been minimized.

shrx commented Jan 8, 2016

+1 @bencord0
Can you explain which packages are needed for it to work? I'd very much like to avoid running the whole Jessie image.


This comment has been minimized.

Sephiroth87 commented Jan 9, 2016

+1 on the Jessie Lite questions :)


This comment has been minimized.

t3chguy commented Jan 13, 2016

I have it functional with a Jessie Lite image based card.


This comment has been minimized.

GM-Script-Writer-62850 commented Jan 16, 2016

sudo echo "string" >> /path/to/file does not work, you can either run sudo su then drop the sudo or run echo "string" | sudo tee -a /path/to/file
on jessie lite you need to install rpi-update: sudo apt-get in rpi-update


This comment has been minimized.

Darkmelman-zz commented Feb 12, 2016


i have updated to the new raspbian release of 2016-02-09 and the USB- Gadget isn’t working…can anyone confirm that or hast anyone a solution?



This comment has been minimized.

ajfisher commented Feb 18, 2016

Can anyone confirm this working on a A+ and do you need an OTG cable for it or a simple standard USB cable is sufficient?


This comment has been minimized.

mrjoshuap commented Feb 22, 2016

@Darkmelman: I can confirm it works on my PI Zero as I just performed these steps using 2016-02-09 and it worked properly for g_serial and g_mass_storage.

The only thing I am not sure of is, for g_serial, if there is a difference between:

systemctl enable getty@ttyGS0.service


systemctl enable serial-getty@ttyGS0.service


This comment has been minimized.

quietbiker commented Feb 28, 2016

Hopefully the screenshot appears, the g_serial is working very well here. Using RealTerm on my Win10 Laptop, USB cable between PC and Pi Zero, with nothing else plugged into the Pi.

I'm going to try to look into using the Pi Zero as an IO expander for a PC (so GPIO/SPI/I2C)


This comment has been minimized.

strasharo commented Mar 3, 2016

echo -e "interface usb0 \nstatic ip_address=" | sudo tee /etc/dhcpcd.conf

Shouldn't this be a "tee -a", because it wipes out all of the default configuration from the file?


This comment has been minimized.

simonbyrne commented Mar 3, 2016

And same with 5 (tee /etc/modules)?


This comment has been minimized.

ajfisher commented Mar 5, 2016

Am sure this will be awesome once Pi Zeroes are actually available. Unfortunately whilst everything appears to load and work on Pi A+, the Pi won't drop into peripheral mode so can't get it to talk to any computer I own :(

Plenty of docs that say "it should be possible" but unfortunately no instructions on what else needs configuring to make it happen...


This comment has been minimized.

prudy commented Mar 13, 2016

It does work with my recent pull request. There was a problem in dwc2 gadget overriding hw configuration.


This comment has been minimized.

DoomHammer commented Apr 12, 2016

Since my Pi is headless: can you provide a preconfigured image at least from step 3 (or best step 6 with g_serial)?


This comment has been minimized.

carlosliam commented Apr 22, 2016

I tried doing this with g_hid and I get this message when booting:

[    4.396884] systemd[1]: systemd-modules-load.service: main process exited, code=exited, status=1/FAILURE
[    4.415944] systemd[1]: Failed to start Load Kernel Modules.
[    4.423600] systemd[1]: Unit systemd-modules-load.service entered failed state.

Any assistance would be appreciated.


This comment has been minimized.

aars commented Apr 30, 2016

I had g_ether working once, but my mac just won't detect the RNDIS device now. Everything loads fine on the pi. I have a usb0 interface configured with a static IP. I have no idea what (I) changed. Tried a fresh install, using the same (and other cables) that worked fine before.

Anybody have an idea what I'm missing here?

(Tested on a windows 10 machine as well, nothing)

EDIT: Apparently most, if not all, my cables are wonky. It works now (raspbian jessie lite)


This comment has been minimized.

gritstub commented May 3, 2016

When using the Pi Zero as a g_serial, do I connect it to my computer via the USB or PWR port? Can i provide power and have the device connected to serial at the same time, or do I need two separate cables?


This comment has been minimized.

gritstub commented May 3, 2016

What is missing from Raspbian Jessie lite that requires the full distribution?


This comment has been minimized.


gbaman commented May 9, 2016

@gritstub you use the USB port, as it can provide power also via back powering. (even though you aren't really meant to do that...).
That should provide power and data at the same time.


This comment has been minimized.

aars commented May 9, 2016

@gritstub It should work fine on Jessie Lite. I have no idea why this (and other) doc(s) mention not using Lite.


This comment has been minimized.

ben-wing commented May 18, 2016

Now that the official Raspbian (as of 2016-05-10 image) has rolled out with a 4.4 kernel (where the gadget mods have been accepted), should I be able to boot a vanilla SD card as a gadget?

I simply didn't pay attention to the fact that my Ubuntu 16.04 laptop (which is playing host to my PiZero) is running NetworkManager.
so, once i properly set a static IP on the usb network connection that was presented by the PiZero (after having applied updates described above), rather than trying to blindly configure a usb0 interface in /etc/network/interfaces i'm now happily SSH-ing to my PiZero via USB.


what i tried (and it worked!) was:

  1. write a fresh raspbian download to SD card
  2. mount the dos partition on my linux box and execute @gbaman step 4 to modify config.txt to include dtoverlay=dwc2
  3. mount the ext4 partition on my linux box and execute @gbaman step 5 to modify /etc/modules to append
  1. based on ladyada's guide append a static IP for the usb0 device to /etc/network/interfaces

anybody else tried something similar?


This comment has been minimized.

rena2019 commented Jun 7, 2016

I tried g_mass_storage without luck:
$ sudo dd if=/dev/zero of=/tmp/piusb.bin bs=512 count=2880
$ sudo mkdosfs /tmp/piusb.bin
$ sudo modprobe g_mass_storage file=/tmp/piusb.bin stall=0
modprobe: ERROR: could not insert 'g_mass_storage': No such device


This comment has been minimized.

jazzycamel commented Jun 9, 2016

I can't seem to get g_mass_storage to work. I've followed the guide (2) above and the modprobe succeeds, but it won't mount on an OSX or Ubuntu host. There is a message on boot "failed to start g_mass_storage -22". I'm using an original Zero with the latest version of Jessie Lite (2016-05-27). I can get the g_ether example to work fine, so I don't think this is a hardware issue. Anyone got any hints, tips or thoughts?


This comment has been minimized.

belese commented Jul 10, 2016

Just a quick note for g_multi to load on boot,
as it seems /etc/modules doesn't allow parameter for modules,
my '/etc/modules' looks like this

# /etc/modules: kernel modules to load at boot time.
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

and i've to create a second file
/etc/modprobe.d/multigadget.conf (you can use whatever you want before .conf)
that contain :
options g_multi file=/dev/mmcblk0p3 host_addr=11:22:33:44:55:66

in this case, i've made a third partition formated in fat32 on sd card, and i set the mac adress so my pc don't detect new ethernet card at each time, and keep configuration for network.

and for info speed for mass storage is not so bad,
it copy at speed between 5 and 6 MB/sec (on ubuntu) and 3/4 on windows

Note for windows 10 (don't test others)

mass storage is detected but iv'e to recreate a partiton and format it inside windows (i've done it with gparted before, don't know why it wasn't recognize in windows). But now it work in ubuntu and windows

driver for usb rnis gadget don't install automaticaly, i need to install drivers form list, microsoft->network card->usb rnis gadget, and it was working too.

i continue my finding, as i share a block device, even if i create a partition in fat32, windows 10 detect it like no partition was create inside. (it was working ok on ubuntu), and i need to create a partition and formated it inside windows.

on the pi, if i done
sudo losetup /dev/loop8 /dev/mmcblk0p3

Disk /dev/loop8: 10.4 GiB, 11195645952 bytes, 21866496 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc408fa62

Device Boot Start End Sectors Size Id Type
/dev/loop8p1 2048 21862399 21860352 10.4G c W95 FAT32 (LBA)

so i can see my windows create partition, and mount it with
sudo mount -o ro,loop,offset=$((2048 * 512)) /dev/mmcblk0p3 /mnt

and now i can access file copied with windows or ubuntu on the mass storage gadget partition.


This comment has been minimized.

lost-hope commented Jul 14, 2016

I get an error when I try to do modprobe g_serial
the error is modprobe: ERROR: could not insert 'g_serial': No such device

I have followed the guide to set up the OTG modes. Have I done something wrong?


This comment has been minimized.

stephenstarkie commented Aug 10, 2016

I am wondering whether this can be made to work on the Compute Module?


This comment has been minimized.

exander77 commented Nov 3, 2016

I have exactly same question as stephenstarkie. Compute module has two usbs, one master, one slave. Can it be done on slave?


This comment has been minimized.

bqian commented Nov 14, 2016

Can Chromebooks detect Pis on GTO mode?


This comment has been minimized.

modelorona commented Nov 16, 2016

Works great on windows 10, appreciate it! 😄


This comment has been minimized.

PaintHat commented Nov 23, 2016

I've been trying to get the g_multi setup to work for Ethernet and mass storage. I've not had any luck with the storage. The Ethernet works great though.


This comment has been minimized.

aldajo92 commented Dec 28, 2016

If I want to use the serial port not for connect for to do login but to for doing a serial communication... is it possible? I skip the step for enable service with sudo systemctl enable getty@ttyGS0.service and doing a simple code for try to send information through of the serial port on /dev/ttyGS0 with a python script but this not work... does anyone know if its necessary to enable something? the python script made is the following (its very very simple):

import time
import serial
ser = serial.Serial('/dev/ttyGS0', 115200)
while True:

This comment has been minimized.

aldajo92 commented Dec 28, 2016

I already resolve the last issue.... any additional step is needed... its only follow the same steps mentioned on gist and skip sudo systemctl enable getty@ttyGS0.service and after that... use the same code with python dependences already installed (in this case pyserial) and connect to a computer using a serial terminal... waiting until data is available... Ohh I forgot to mention something... also its necessary to start the script on /etc/rc.local with python /path/to/script & before exit 0


This comment has been minimized.

CannonFodderSE commented Jan 9, 2017

leopatras commented on Jan 6, 2016

Hi gbaman, do you have a tip how to enable HID devices ( mouse, keyboard ) ? Thanks a lot in advance

This seems to have gone unanswered, at least publicly.

I been banging around for almost a week and can't get HID mode working on pi zero. Has anybody got it to work and have a step by step guide? Seen many out there, but none work with the latest raspian release (November 2016).



This comment has been minimized.

MitchDresdner commented Jan 10, 2017

I now have it working on both Windows 7 and Windows 10 and it seems to be a simple as Mr gbaman described.

The problem I encountered was the result of a 2' USB Micro cable I was using. It applied power and the Zero booted, but (guessing) the data line was defective or not intended for use in the original device.

Couple other points:

For troubleshooting, you'll want Bonjour Browser

Or to use cmd shell dns-sd.
i.e. dns-sd -B _services._dns-sd._udp

Also, raspberrypi.local is the default hostname of a virgin pi, if you change the hostname you'll be ssh'ing to yourHostname.local

Thanks gbaman!


This comment has been minimized.

akiani commented Jan 26, 2017

@gbaman Any idea how I can share the OTG USB across the host device and a Wifi 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!


This comment has been minimized.

alexellis commented Mar 7, 2017

This doesn't appear to work at all with the image released in March for Raspbian Lite. Anyone else tried?


This comment has been minimized.

rknall commented Mar 7, 2017

Tried it here as well with a Pi Zero W and can confirm, that it does not seem to work with the newest Raspbian image. The dwc2 issues in dimes report an error for setting up a queue:

[ 0.000000] Kernel command line: 8250.nr_uarts=0 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 dma.dmachans=0x7f35 bcm2708.boardrev=0x9000c1 bcm2708.serial=0x1287663a bcm2708.uart_clock=48000000 bcm2708.disk_led_gpio=47 smsc95xx.macaddr=B8:27:EB:87:66:3A vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[ 0.483011] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[ 0.486025] dwc_otg: FIQ enabled
[ 0.486054] dwc_otg: NAK holdoff enabled
[ 0.486066] dwc_otg: FIQ split-transaction FSM enabled
[ 0.486134] Module dwc_common_port init
[ 2.891315] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[ 3.484571] dwc2 20980000.usb: DWC OTG Controller
[ 3.487654] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[ 3.490707] dwc2 20980000.usb: irq 33, io mem 0x00000000
[ 3.515184] usb usb1: Manufacturer: Linux 4.4.50+ dwc2_hsotg
[ 3.776534] dwc2 20980000.usb: dwc2_hsotg_enqueue_setup: failed queue (-11)
[ 3.782087] dwc2 20980000.usb: bound driver g_ether


This comment has been minimized.

Programming4life commented Mar 8, 2017

Does anyone know of a otg controller that i can use in my projects? I don't want to use the raspberry pi zero for just otg. I'd rather have just the parts needed for otg to work. Seems like a stupid question but does anyone know if I can use a usb hub to be able to connect multiple otg devices?


This comment has been minimized.

SpiraMirabilis commented Mar 9, 2017

ISP1763A is a USB OTG controller. You can get a development kit from ST. Texas Instruments also offer similar chips. It has a USB host port in addition to a OTG as well.


This comment has been minimized.

jamescarruthers commented Mar 26, 2017

I'm having issues with the latest Raspian too — shame


This comment has been minimized.

nsayer commented Apr 14, 2017

systemctl enable getty@ttyGS0.service isn't enough for the gadget serial getty. You need to add -w to the agetty command line. You need to copy /lib/systemd/system/getty@.service to /lib/systemd/system/gadget-getty.service and modify it a little bit, including adding -w before --noclear in ExecStart, then enable gadget-getty@ttyGS0.service.

If you don't do this, the agetty will hang when a host is not connected, preventing proper shutdown and reboot.


This comment has been minimized.

1rdsk1 commented May 13, 2017

hi, I cant get a mouse or keyboard to work with the micro usb port via my OTG cable (tried two OTG cables and think they're ok, the mouse and keyboard work on another rpi). I can see the mouse pointer but it does not move. Should I assume that there is a fault with the Pi Zero W?
I tried SSH but understand that this is now defaultng to disabled. So apart from seeing the Pixel desktop I cant do anything).


This comment has been minimized.

1rdsk1 commented May 13, 2017

My bad... now work fine with powered USB hub.


This comment has been minimized.

jmsaavedra commented May 19, 2017

Verified g_mass_storage working on RPi Zero W with latest Jessie ! Thank you !


This comment has been minimized.

sebdl commented May 30, 2017

Regarding dwc2 on raspberry A+. After some search I found this very interesting for me:
I managed to make it work without hw modifications, so just added:
dtoverlay=dwc2,dr_mode=peripheral in file /boot/config.txt.
Of course you can't change mode dinamically but for my purpose it does the trick!
@gbaman if you update with this maybe will be useful for others.
Many Thanks!


This comment has been minimized.

nick-2017 commented Jul 26, 2017

@alexellis todays (27 jul 2017) image is not working with mass storage, will try builds earlier this year.


This comment has been minimized.

JamesMcNee commented Aug 23, 2017

g_mass_storage not working with Rasbian Stretch (atleast on Widows, using the provided instructions). Windows device mamager gives error message: Device Descriptor Request Failed.


This comment has been minimized.

Habbie commented Oct 21, 2017


Can Chromebooks detect Pis on GTO mode?

Yes! g_ether + dhcpd gives me SSH and VNC (if configured on the Pi) directly over the USB cable from the Chromebook. Note that at least my Chromebook cannot power the Pi reliably - so I also need 5v on the microusb port labeled PWR.

g_serial works with Beagle Term.


This comment has been minimized.

PieGuy314 commented Nov 8, 2017


Have you been able to establish routing from the Pi through the Chromebook? I'm able to access the net when I go through a MacBook but only able to SSH in when connected to the Chromebook.

The Pi is configured with a static IP address ( Router is

The Mac and Chromebook are similarly configured... Static IP address ( Router is

The only difference is that 'Internet Sharing' for the RNDIS/Ethernet Gadget is enabled on the Mac. This bridges the interfaces.

Can't see any obvious way to do similar on the Chromebook. Am I missing a trick?


This comment has been minimized.

erotundo commented Nov 8, 2017

Hi @gbaman and @belese!

I follow the basic step first

"/boot/config.txt" -> add dwc2
"/boot/cmdline.txt" -> add modules-load=dwc2,g_mass_storage after rootwait
"create mini filesystem" -> sudo dd if=/dev/zero of=/home/pi/usb-drive.img bs=1M count=50
"set permissions" -> sudo chown 755 /home/pi/usb-drive.img
connect to laptop with running Windows, after Windows can't install the component execute
"sudo modprobe g_mass_storage file=/home/pi/usb-drive.img stall=0"

With this step in Windows device manager appear "USB Mass Storage" but i can't Access to the "drive", the drive not appear in Linux

So i use another method to generate the mass storage

"/boot/cmdline.txt" -> add modules-load=dwc2,g_multi after rootwait
"/etc/modprobe.d/" -> create g_multi.conf and add "options g_multi file=/home/pi/usb-drive.img stall=0 removable=y ro=0 host_addr=11:22:33:44:55:66 dev_addr=aa:bb:cc:dd:ee:ff

With this last step, the drive appears into Linux and Windows read only mode and i need to modify the files into the minifile system drive

I don't know where it's the problem

I try to do this in Raspberry Pi Zero W



This comment has been minimized.

gwshaw commented Dec 1, 2017

I'm trying to use gadget mode on the Zero (using the latest releases) and the g_printer device to emulate a printer so I can capture data, process it, and send it to some APIs over wi-fi. I've set up the board using the instructions above. Using the g_ether device the board will show up as a network device to my Macbook. However, if I edit the /etc/modules to contain g_printer rather than g_ether (only one, and reboot) the board does not show up as a printer available to the Macbook.

modinfo returns:

filename:       /lib/modules/4.9.65+/kernel/drivers/usb/gadget/legacy/g_printer.ko
license:        GPL
author:         Craig Nadler
description:    Printer Gadget
srcversion:     2F1D50E570B8D48FA4C2DD9
depends:        libcomposite,udc-core
intree:         Y
vermagic:       4.9.65+ mod_unload modversions ARMv6 p2v8 
parm:           idVendor:USB Vendor ID (ushort)
parm:           idProduct:USB Product ID (ushort)
parm:           bcdDevice:USB Device version (BCD) (ushort)
parm:           iSerialNumber:SerialNumber string (charp)
parm:           iManufacturer:USB Manufacturer string (charp)
parm:           iProduct:USB Product string (charp)
parm:           iSerialNum:1 (charp)
parm:           iPNPstring:MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1; (charp)
parm:           qlen:uint

so it looks to be loaded. What else is needed for the board to show up as a printer?


This comment has been minimized.

alfredopons commented Dec 8, 2017

Please, has anyone tried this on compute module 3?
There are no OTG modules in the kernel. I have tried to compile the kernel by adding these modules but it still doesn't work for me.


This comment has been minimized.

nenadlazovic commented Dec 17, 2017

I have setup where RPI 3 is connected to 2 PI Zero's over 2 USB cables. Pi Zeros are configured to use ether_g / dwc2 modules. (details in
All works ok. RPI 3 can access PI Zeros and Pi Zeros can access RPI3 over IP (over USB).

Problem is when RPI 3 is rebooted. During RPI 3 reboot power is kept on Pi Zero's, and they don't reboot.
IP connection is lost.

Is there a way to configure PI Zero's to reconnect ? (restart ether_g module, ...) ?


This comment has been minimized.

StephaneSchmit commented Jan 7, 2018

@sebdl Thanks so much! dr_mode=peripheral works with Model A too. Really hope @gbaman updates this.


This comment has been minimized.

Conundrum1885 commented Jan 19, 2018

Hi, I am also trying to do this.
Hint: test the OTG cable with a phone first.
If it won't pick up your device the Pi won't work either.
I used the cable adaptor from one of those mini USB-USB micro and that works.


This comment has been minimized.

Xmetalfanx commented Feb 25, 2018

I am thinking of a "down the road gift" (noting that I have a Pi 2 and Pi 3 myself) with (Pi zero w starter kit with a few of the additional things needed, pre-included. ... I have bought a similar starter kit before... was cheaper than the parts by themselves)... ANYWAY ... a HUGE snag I see is the use case... RIGHT NOW the idea is a non-powered (I really dont want to have to get ANOTHER hub to replace the existing non-powered one, that is only a few months old) USB Hub plugged into the USB of a tv, with a few 32GB flash drives with content on them. THE IDEA is to remote that and via the cables/connectors included, plug that USB Hub "into" the Pi Zero, but I am of course wondering for basic flash drives attached that way ... would the pi zero's power cable be able to power that and the pi with say LibreElec, without issue? (if it does, but every few minutes due to say power "issues" the pi zero restarts,... thats A FAIL in my book) .. I know even for my pi 3, if it is an external hdd (the 1TB kind, not basic flash drives), i need my POWERED Pluggable (I highly recommend them, btw) USB hub. I dont want to get the kit, then realize the main use case for this family member is not doable ... (though if i just get a powered USB hub ... it does make the existing hub pointless and its almost new .... then that will work.


This comment has been minimized.

computarium commented Mar 7, 2018

Problem with g_serial and Prolific USB-Serial cable.
I want to drive the PI0 from a vintage TTY ASR-33 (the ASR-33 has a RS232 connection). I installed the serial gadget, which works fine when tying the PI0 USB port with a plain USB cable into a USB port of a Win7 machine running Teraterm (which sees the PI0 as COM8).
But I want to connect serially to a traditional RS232 device. I Tested with different Prolific USB-serial cables (USB part into PI0, RS232 via null-modem into the RS232 port of a laptop, 115200,n,8,1) running Teraterm: the login does not show up (as it does on the Win7 machine). What am I goofing here? Thx for every answer...


This comment has been minimized.

radzimir commented Jun 8, 2018


Based on this and some other descriptions I have just made a script setting up Raspberry Pi image with OTG functionality.


This comment has been minimized.

markosjal commented Oct 4, 2018

As I understand it this will NOT work with RPi B nor B+ which I have a few of laying around.

I see also there is now a Rpi Zero W with integrated wireless . Will it work with that? I am a little confused as to what models are compatible, and the functionality of the software.

My objective is to use the Pi as USB mass storage but in reality that mass storage points to a NAS, NFS, or SAMBA on a different system.

This way I can set up a tuner / STB (that will only accept a USB memory or hard disk) as a DVR that records to the network storage directly while STB happily believes it is recording to a mass storage device.

I am sure I am not the first nor last that wants this kind of device , so any experiences here please let me know.

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