Zero Blinking Lights

In between tackling a work project that kind of spilled over into the weekend and watching TechReady1 sessions, I decided to fix an annoyance I had with the Zero.

Like I wrote , the Zero supports USB OTG, and you can get it to act as a virtual Ethernet port by simply appending dtoverlay=dwc2 at the end of config.txt to patch the device tree and add modules-load=dwc2,g_ether to cmdline.txt just after rootwait.

That’s the work of a few seconds, and when hooked up to another computer, the Zero will simply set itself up with an IPv4 local link address and announce itself over – which works wonderfully with my and most boxes, including other Pis. All I need to do is ssh [email protected] and I’m set.

If I need to install or update something, it’s trivial to share my network connection to it – but that just doesn’t work under Windows for me. I already have enough trouble with , the Hyper-V virtual switch and access to corporate Wi-Fi (right now, for whatever reason, they’re mutually exclusive), so I decided not to fiddle with my work laptop that deeply and figure out a way to know the Zero’s link-local address.

The Scroll pHAT, close up. The connector makes it take up a lot more volume than you'd expect.

Fortunately, I had a Scroll pHAT lying around, so all I really needed to do was solder a set of headers onto the Zero…

Soldering the headers on the Zero, doing the ends first to make sure the connector was properly seated.

…and tweak the network config (on post-up for usb0) to run a little script to display the IP address on it:

#!/usr/bin/env python

from scrollphat import write_string, scroll, clear, set_brightness
from socket import socket, AF_INET, SOCK_DGRAM
from time import sleep

def get_ip_address():
    """Fool the network stack into telling us what the outbound interface is without actually connecting anywhere"""
    s = socket(AF_INET, SOCK_DGRAM)
    s.connect(("8.8.8.8", 53))
    return s.getsockname()[0]

set_brightness(3)
write_string(" IP: %s " % get_ip_address())
for i in range(0,128):
    sleep(0.15)
    scroll()
clear()

It’s a bit clunky and marquees have always been a tad cheesy, but it works and I can now move on to prototyping a few things. Also, I had to dim down the brightness a tad because those LEDs pack a serious punch. So if everything else fails, I now have myself an Internet-enabled reading light…


  1. TechReady is an internal Microsoft event that happens twice a year. I decided to skip the summer edition to be here for the kids during their vacation, but sessions are livestreamed and recorded, so I’ve been watching videos at 1.5x speed every evening for the past week, which is a lot more comfortable than actually flying over and spending a week or two in Seattle. ↩︎