Pi Zero as a universal USB stick

Connected

The default settings in /etc/raspi2go.conf let the Pi Zero assume three roles: It advertises itself as a USB drive, USB Ethernet adapter, and serial USB adapter. Depending on the host settings, a Windows or Linux system then mounts the drive automatically.

It wouldn't make much sense to go through all this trouble for a normal USB stick, but functioning as a USB drive is ideal for installing drivers and application software. For example, Windows needs a suitable program to access the serial port, and it would be possible to provide Putty on the emulated drive of the Pi Zero. This procedure is familiar from commercial UMTS/LTE sticks: When first plugged in, they register as a CD drive with the driver software. After installing the driver, Windows then identifies the stick as a WiFi dongle.

Physically, the mass storage emulated by the Pi Zero is an image file. Do not access it simultaneously on the host and Raspberry Pi – it is not a network drive. However, the Pi Zero can also serve up this kind of drive by NFS or Samba, because it plays the role of an Ethernet adapter with two ends.

Mini-Network

A normal USB Ethernet adapter has a USB plug on one side and a socket for a network cable on the other. The wire usually leads to a router or switch but could also be plugged directly into another computer. The Pi Zero as a network gadget does exactly that – the only difference being that the cable only exists virtually and the computer on the other side is the Zero itself.

Windows and Linux detect the adapter as a network interface. For communication with the Pi Zero to work, both computers need to have addresses on the same subnet. The easiest way to do this is to use Zeroconf/Avahi. If the service is running on both sides, the participating computers negotiate the technical parameters independently; otherwise, manual configuration will do the trick. Simply assign both computers a fixed IP address in your address range.

Once configured, both devices form a mini-network, and you can launch servers (e.g., a storage or web server) on the Pi Zero and make them available to the host. The transfer rates are in the Fast Ethernet range; depending on the direction, iperf indicates 80-120Mbps as throughput.

Consoles and More

In the third emulation, the Pi Zero pretends to be a serial interface. If the Raspberry Pi starts a virtual console on the port (the raspi2go.sh script does this automatically), you can access the Raspberry Pi on the host with a terminal emulator (Putty on Windows; Screen or Tio on Linux), which is especially useful if the network configuration is not working correctly.

Another possible application is the simulation of sensor data (for sensors with a UART interface). In this case, a program on the Pi Zero simulates the data and sends it to the host over the serial interface. This scenario is ideal for software development because it not only makes it very easy to process data, but also avoid errors.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Intel Unveils Compute Stick

    Four-inch-long computer on a stick lets you boot a full Linux system from any HDMI display device.

  • Raspberry Pie Zero: Just chill a bit.
  • Zero Trust Security

    Some old-school admins are still philosophizing about secure internal networks, but the experts have already moved on: Zero trust architectures use a reliable but complex strategy to protect the network from all threats – inside and outside.

  • Adafruit PyPortal

    Unlike other displays for the Raspberry Pi, Adafruit's PyPortal touchscreen provides an autonomous environment, including a microprocessor, sound output, and a WiFi connection.

  • CircuitPython

    The CircuitPython run-time environment runs on almost all microcomputers and microcontrollers, making it perfect for cross-platform programming.

comments powered by Disqus