Background
An OTG (On-The-Go) device is a device that can act as both a host and a peripheral on a USB network. The PiZero is an OTG device. This guide pertains specifically to the PiZero and PiZero 2, but similar concepts also apply to other Raspberry Pi products (more information here).
Host mode
- Used for connecting the PiZero to a USB peripheral, eg. USB keyboard, mouse, etc
- PiZero is the OTG A device (supplying power to USB)
- USB keyboard, mouse is the OTG B device
- Used for connecting the PiZero to a host computer, eg. PC, phone
- The host computer is the OTG A device (supplying power to USB)
- PiZero is the OTG B device
Micro USB ports on the PiZero
There are two micro USB ports on the PiZero. There is only one micro USB data port (labeled USB), and it is capable of supporting OTG. The second micro USB port is used for power delivery and does not support OTG.
Controlling OTG mode
There are two methods to control whether the data port operates in host or peripheral mode.- Cable method
- Software method
Cable method
The USB cable consists of one end being a USB Micro-B male and the other being a USB-A female.
- If the ID pin on the USB Micro-B is shorted to ground, PiZero operates in host mode (cable usually known as an OTG cable)
- If the ID pin on the USB Micro-B is not shorted to ground (left floating), PiZero operates in peripheral mode
Software method
Specify the following setting in config.txt.- peripheral mode: dtoverly=dwc2,dr_mode=peripheral
- host mode: dtoverly=dwc2,dr_mode=host
- otg mode: dtoverly=dwc2,dr_mode=otg (default: forces the PiZero to follow the ID pin functions)
What if the cable method conflicts with the software method
TBD @thagrol suggested the following.
My experience is that when you force the mode to either host or peripheral the ID pin in the microUSB socket is ignored. It is only when you set dr_mode=otg or don't include dr_mode at all (because the default is otg) that the ID pin functions.