Some ramblings and jottings on my experiences with running a Pi headless, tethered to a Windows PC, and breadboarding with it.
Rationale - Why headless?I don't have a fancy monitor with DVI or TV with HDMI and I wanted a low cost setup for experimenting with Pi interfacing so I decided to get a Raspberry Pi Zero W and run it headless from my Windows XP netbook. Due to the legacy windows OS, and my dislike of WiFi for home networks, I ran into various issues along the way.
1. Choice of hardwareFor breadboarding I wanted a cheap and simple hookup with the minimum number of cables. As USB OTG support for the Pi Zero (a.k.a. USB Gadget mode) has been available in the Rasbian kernel since mid 2016, a Pi Zero or Zero W (or Compute Module or even a model A) can be networked to a PC by USB, appearing as a RNDIS adaptor to the PC. You cant use any PI with on-board Ethernet or multiple USB 'A' sockets, as the on-board USB hub /Ethernet controlled chip blocks device mode access to the BCM283x SoC's USB port. A plain Pi Zero wouldn't be able to access any network except through the host PC, so I bought a PI Zero W with onboard WiFi and Bluetooth.
The Bluetooth is both a blessing and a curse as it uses the BCM2835's main PL011 hardware UART and the auxiliary mini-UART that is normally routed to the TX and RX pins on the expansion header doesn't have a proper baud rate generator so its speed varies with the CPU clock, making it essentially unusable unless you either clock down the CPU and lock its speed, slugging performance, or disable the Bluetooth in config.txt so the main UART can be rerouted to the expansion header before the kernal loads.
Other hardware choices included a Cyntech Split+ to get the expansion header into the breadboard and a 16Gb Micro-SD card that had originally come with a PI 3 B with NOOBS on it, and a K&H AD-12 breadboard. I replaced the Split+'s ribbon cable with a shorter one that also has a male 40 pin IDC header crimped to it so I can still plug in pHATs when breadboarding.
2. Initial SetupAfter some research I found that NOOBS would be of very little benefit to a headless Pi as its controlled by direct local interaction. Apparently you can control NOOBS by VNC, but then you probably will still have issues configuring the OS(es) installed by NOOBS for headless operation. I therefore decided to go straight to a fresh Rasbian Stretch image.
Raspberrypi.org's recommended one-step imaging tool - Etcher - doesn't run on XP, so, rather than firing up a Linux VM, I decided to grab the seperate tools I needed and do it manually. To install Rasbian, you need to write the image to a FAT32 formatted SD card. The native Windows formatter is best avoided, so I grabbed the SD Association's SD Memory Card Formatter. Unfortunately v5.0 doesn't work on XP and all the links to their site for v4.0 redirect to v5.0, so I had to get v4.0 from a 3rd party website. I also had to prepare a 64Gb SD card for the Pi 3B I'd nicked the 16Gb card from, but above 32Gb, the SD Memory Card Formatter will use exFAT (as will the native Windows formatter) so I grabbed a FAT32 formatter for large drives from
http://www.ridgecrop.demon.co.uk/guiformat.htm.
Raspberrypi.org's recommended image writer for Windows if you cant/wont use Etcher is Win32DiskImager - you need v0.9 for XP and Vista. Everyone else can use the current version.
I grabbed the current full Rasbian Stretch image, not the light one as I wanted to be able to VNC into the Pi.
I also had to update my 7ZIP installation to handle the ZIP64 format zipped Rasbian image from Raspberrypi.org.
After unpacking the image and writing it to a freshly formatted SD card, you need to patch some stuff to bring a Pi up headless without a logic level UART cable hooked to the expansion header. Many of the headless Pi guides are over-complex (due to the perceived need to configure WiFi) or plain out of date.
The key things thst one needs to do are to configure the Pi to enable it to run as a NDIS gadget and enable SSH access to it so you can still get in if X-Windows is borked or if there is a problem with the VNC server. SSH access used to be enabled by default, but with the introduction of on-board WiFi, it was decided that was an unacceptable risk so you now have to enable it by creating an empty file called
SSH (with no extension) in the root of the boot partition of the SD card. Rasbian 'eats' the SSH file so don't be surprised that it vanishes after its done its job.
You also need a SSH capable terminal program on the PC. I'm using puTTY.
To configure the Pi for USB RNDIS networking, you need to edit two files in the root of the boot partition. The first is
cmdline.txt which is read very early in the boot process by the GPU and is used to configure the SoC's I/O and CPU. It needs
modules-load=dwc2,g_ether added after
rootwait, but you have to be a bit careful as cmdline.txt options are all on one line, separated by a single space, there are absolutely no spaces within each option and the line doesn't have a linefeed or newline at the end of it. Also, its desirable to set the RNDIS host and slave MAC addresses, so they don't randomly change on each boot, so your PC sees it as the same network adapter, and your DNS server can give the Pi a stable IP address.
modules-load=dwc2,g_ether g_ether.host_addr=b8:27:eb:00:00:00 g_ether.dev_addr=b8:27:eb:ff:ff:ff
If you have multiple tethered Pis, use unique MAC addresses for each!
b8:27:eb is the OUI (MAC address prefix) for the Raspberry Pi Foundation. There is an infinitesimal risk of collision with real Ethernet equipped Pis, but hopefully low addresses were used 'in house' and high ones may not have been fully used before production switched to one of the Raspberry Pi Ltd OUIs.
The other is config.txt, which is a fairly normal ini file with lots of
parameter=
value lines. It (fresh out the box) doesn't use sections and uses # for comments. You need to add a line reading
dtoverlay=dwc2
at the end of it to enable 'Gadget' mode.
Todo (writeup):
- Configuring the Pi over SSH
- Setting desktop size for VNC
- Getting started with Python and Hardware interfacing
- Installing Python on the PC and accessing Pi I/O pins remotely
- Headless over Bluetooth - is it more trouble than its worth?
- Adventures in misconfiguring SAMBA, MS networking and firewalls!
<knocking off for now - I'll add more later>