Simple guide for setting up OTG modes on the Raspberry Pi Zero
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. 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
sudo BRANCH=next rpi-update
. This will take a while.echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
.echo "dwc2" | sudo tee -a /etc/modules
echo "g_ether" | sudo tee -a /etc/modules
. You can only pick one of the above modules to use at a time.sudo systemctl enable getty@ttyGS0.service
, then you can connect to the device via Putty or Screen.echo -e "interface usb0 \nstatic ip_address=169.254.64.64" | sudo tee -a /etc/dhcpcd.conf
. You can then access the Raspberry Pi Zero by connecting to 169.254.64.64
, 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.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.
The legacy guides can be found on a separate Gist.