Raspberry Pi USB Gadget Tutorial

Nico edited this page May 16, 2016 · 2 revisions

It is recommended to use a serial adapter to connect to the raspberry. That makes it a lot easier to debug the usb port while it is in device mode. Here are some tips on how to use the serial. Also see the Arch Wiki

However I still have an issue to input more chars than the terminal width. This post describes it, but i cannot solve it. https://askubuntu.com/questions/24358/how-do-i-get-long-command-lines-to-wrap-to-the-next-line

Using USB OTG (starting with a fresh jessie full image, lite could also work):

# This is required in the config.txt to enable usb device mode
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt

# Now reboot and see if the pi still boots up with those settings (no gadget loaded yet)
sudo reboot

# You then can try to manually enable the g_ether module at runtime
sudo modprobe g_ether

# You can also unload it again and test another device
sudo rmmod g_ether

# To permanently add the g_ether (or any other) module, add it to /etc/modules
echo "dwc2" | sudo tee -a /etc/modules
echo "g_ether" | sudo tee -a /etc/modules

# And finally you might want to change the mac address for the g_ether module
# Make sure to not use a mac that conflicts with your network
# The host mac is the mac that the usb0 PC host adapter gets
# The device mac is the mac that the pi gets
# You have got two mac addresses, because it simulates a virtual connection with 2 ends of course.
echo "options g_ether host_addr=00:11:22:33:44:55" | sudo tee -a /etc/modprobe.d/g_ether.conf
echo "options g_ether dev_addr=00:55:66:77:88:99" | sudo tee -a /etc/modprobe.d/g_ether.conf

# After a reboot everything should work. The pi will look for a DHCP server on USB0
# You might want to enable ipv4 "shared to other computers" on your host system
sudo reboot

# You can now try to ssh into your pi. This might not work with windows.
ssh pi@raspberrypi.local

Mac Address Resources: Link1. Link2.

Other useful Links:

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.