Tag Archives: USB

Summary

An extremely simple new way to setup Raspberry Pi Zero as a USB virtual network gadget, allowing SSH, SFTP, VNC etc over a single USB cable. All without need of a keyboard, mouse, screen etc to setup!
To make it clear though, this can only work with the Raspberry Pi Zero.

Quick history lesson

So back over Christmas 2015, I had worked on getting the Raspberry Pi Zero OTG/Slave USB mode working and documented. My work was based off the excelent work done by awesome volunteers from the Raspberry Pi community here and here.
Back then, it required you have a screen, keyboard, mouse and internet connection to set everything up from a stock Raspbian image. This was a bit of a pain if all you had was your normal Windows/Mac/Linux computer with downloaded Raspbian, an SD card, Pi Zero and a USB cable.

Then, with the 2016-05-10 release of Raspbian, the required modules and kernel version were included on the stock Raspbian images, but they still required configuring. At least all this could be done with a screen and keyboard plugged into the Pi Zero (no internet required).

Now, after a heck of a lot of Linux Kernel documentation digging/hunting around, I have stumbled across what seems to be a very little known kernel cmdline parameter. This parameter allows us to do all the configuration on the /boot partition, which is formatted FAT32 and readable on Windows/Mac/Linux (vs normal root partition only being readable with Linux).

What does this mean?

You can now set up a virtual network connection between your Raspberry Pi Zero and normal PC using a single USB cable in a matter of seconds, without the need for any extra hardware!
No need for an HDMI screen, keyboard, mouse etc, all with stock Raspbian Jessie lite or full.
You can then SSH into the Raspberry Pi Zero, copy files with SFTP or use VNC (extra installation required).

How do I set it up?

Setup is super simple! Once you have flashed your Raspbian image, should take only a few minutes to set it up! See guide below.

Update 19/05/2016 – The modules are now included in the most recent version of Raspbian and thanks to some digging around in kernel documentation, it is now possible to set the full thing up without a keyboard/mouse/screen! Just need a Windows/Mac/Linux computer!

Update 15/01/2016 – The modules have now been merged into the Raspberry Pi Foundation maintained kernels! So no more need for custom kernels, just need to grab the most recent alpha kernels. Doing this is now far simpler.

Full credit for the initial documentation for this goes to a number of Pi experts from the Raspberry Pi community, see here and here.

An acknowledgement also to Lady Ada of Adafruit who was working on documenting in parallel to myself on Christmas eve. She has taken a different approach which requires a UART serial cable. Her guide can be found here.

What is this?

The Raspberry Pi Zero is a very cool little computer. At £4, is pretty amazing for the price. But one thing many Pi users have wanted to be able to do for a long time is program their Raspberry Pi from another computer, using only a single USB cable!

The Raspberry Pi Zero is able to do this, hardware wise anyway, although a lack of software support was holding up it ever happening. Until now!

So what can it do?

Using the Linux USB Gadget modules, we can get the Pi Zero to emulate a whole host of USB devices including

Virtual Serial – So can get a serial connection into the Pi, similar to using the UART pins. You can use Putty (on Windows) or Screen (on Mac and Linux).

Virtual Ethernet – You can get your Pi Zero to appear as a USB Ethernet modem. With a little configuration, you can then get full SSH, VNC, FTP etc.

Mass storage device – You can get the Pi Zero to appear as a flash drive, allowing you to for example, copy files over and have the Pi run these files (useful for robotics for example)

Virtual MIDI – The Pi Zero could appear as a virtual MIDI instrument.

Virtual Audio – The Pi Zero could appear as a virtual headphone output or microphone input.

Virtual Human Interface Device (HID) – The Pi Zero could appear as a virtual HID, for example a keyboard or mouse. So when you plug it into your computer, it could start typing!

You can also combine a few of the above (up to 3 at a time) using the g_multi module, although Windows and Mac have difficulty handling it then.

Examples

Where is this useful? Lets take an example of some Raspberry Pi robots in a classroom. Although you could be using Wifi for each robot, remembering addresses, unreliability with wifi etc all make wifi a bit of a rubbish answer.
With this, the student simply plugs in the robot and perhaps drops their script onto the flash drive that appears. When they unplug it, the robot runs the script, dumping the results of the script back onto the mass storage device, ready to be read when it is plugged in next.

Another example, lets say you don’t have access to a screen to use with your Raspberry Pi Zero, in for example, a school. You could still let your students play with GPIO or Linux by simply using the serial module (with Putty or Screen), or the virtual ethernet module to allow them SSH access.