This post includes the older legacy guides and kernels for using USB OTG mode on the Raspberry Pi Zero. They have since been replaced by the official Raspberry Pi kernel files.
##Modular (all modules) - Prepreared
Kernels - https://dl.dropboxusercontent.com/u/1122948/temp/PiOTG-Test/PiZeroCombined.tar.gz
Modules included
- Serial (g_serial)
- Ethernet (g_ether)
- Mass storage (g_mass_storage)
- MIDI (g_midi)
- Audio (g_audio)
- 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
Note This section includes standard USB support as well, so can use normal USB devices (like a keyboard) throughout. It should auto switch when plugged into another computer.
- First, flash Jessie (full, not lite) onto a blank microSD card.
- Copy the tar.gz file onto the boot partition of the image.
- Start it up, at this stage should be fine with any Pi, including Pi2.
- Do normal first boot stuff (resize image etc with
sudo raspi-config
). - Run
tar xvzfC /boot/PiZeroCombined.tar.gz /tmp/
. - Then run
sudo cp -R /tmp/PiZeroCombined/fat32/* /boot/
(to copy the kernel and device tree stuff) - Then run
sudo cp -R /tmp/PiZeroCombined/ext4/lib/* /lib/
(to copy the kernel modules themselves) - At this point, you have 2 options, you can either set the module you want to run on startup, or dynamically load and unload them.
- To set a module to load on startup, edit the modules file with
sudo nano /etc/modules
and add the module name you want to start (e.g. g_ether) to the end on a new line. Also, make sure to the check the "Using the modules" section before rebooting. - Then, reboot the Raspberry Pi using
sudo reboot
. - To manually load a kernel module, after rebooting use
sudo modprobe moduleName
. To unload a module, usesudo rmmod moduleName
.
- 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 [email protected]
, 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
sudo echo -e "interface usb0 \nstatic ip_address=169.254.64.64" >> /etc/dhcpcd.conf
. You can then access the Raspberry Pi Zero by connecting to169.254.64.64
, or by usingraspberrypi.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 withsudo mkdosfs /piusb.bin
. Then, when enabling it, addfile=/piusb.bin stall=0
onto the end, for examplesudo 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.
If you have any auto switching issues, try any of the other sets of kernels below.
Note - Using these kernels below will disable standard USB on the Pi Zero with that SD card, it is recommended to also have a USB UART serial adapter on hand in case you get locked out due to lack of keyboard.
#Older kernels
##USB Virtual Ethernet - No standard USB support (only Gadget)
Note - This section is no longer recommended, it is much better to use the modular approach above as includes full standard USB support.
Ethernet kernels download - https://dl.dropboxusercontent.com/u/1122948/temp/PiOTG-Test/PiZeroEthernet.tar.gz
- First, flash Jessie (full, not lite) onto a blank microSD card.
- Copy the tar.gz file onto the boot partition of the image.
- Start it up, at this stage should be fine with any Pi, including Pi2.
- Do normal first boot stuff (resize image etc with
sudo raspi-config
). - Run
tar xvzfC /boot/PiZeroEthernet.tar.gz /tmp/
. - Then run
sudo cp -R /tmp/PiZeroEthernet/fat32/* /boot/
(to copy the kernel and device tree stuff) - Then run
sudo cp -R /tmp/PiZeroEthernet/ext4/lib/* /lib/
(to copy the kernel modules themselves) - Next, you will need to manually asign a fixed IP to the Pi, you can do this by editing the cmdline.txt file (using
sudo nano /boot/cmdline.txt
) and add on the endip=169.254.64.64:::255.255.0.0
. This will allow you to connect the Pi using the address169.254.64.64
from your computer. - Finally, reboot your Pi. It will appear on your computer as a virtual network card, make sure you also assign a fixed IP address on the PC side. (On Mac OS, a much easier way is go into settings, sharing and enable internet sharing from wifi etc to the Gadget device. Using this, you don't even have to have a fixed IP on each side as it will get one via DHCP, will be 192.168.2.3 usually)
##USB Virtual Serial - No standard USB support (only Gadget)
Note - This section is no longer recommended, it is much better to use the modular approach above as includes full standard USB support.
Ethernet kernels download - https://dl.dropboxusercontent.com/u/1122948/temp/PiOTG-Test/PiZeroSerial.tar.gz
- First, flash Jessie (full, not lite) onto a blank microSD card.
- Copy the tar.gz file onto the boot partition of the image.
- Start it up, at this stage should be fine with any Pi, including Pi2.
- Do normal first boot stuff (resize image etc with
sudo raspi-config
). - Run
tar xvzfC /boot/PiZeroSerial.tar.gz /tmp/
. - Then run
sudo cp -R /tmp/PiZeroSerial/fat32/* /boot/
(to copy the kernel and device tree stuff) - Then run
sudo cp -R /tmp/PiZeroSerial/ext4/lib/* /lib/
(to copy the kernel modules themselves) - Finally, to enable the serial service, run
sudo systemctl enable [email protected]
. - Everything is now configured, shutdown the Pi
sudo shutdown now
and insert the card into your Pi Zero, plug in the USB data port into your computer and it should appear as a Gadget serial device.