I finally decided to buy a Raspberry Pi Zero W, since well it was all the rage and for a specific project I couldn’t use my Unwired One. So this drove me nuts, I actually had to attach a monitor for it to boot.

The problem is that from Mac/Windows you cannot see the other partitions besides /boot. However luckily there is a trick that it can copy files from there to the appropriate directories. Turns out other people are lazy too ;)

Here are the steps I took to make a Raspberry Pi boot without having to attach a monitor and have it auto-join your WiFi on first boot!

This assumes you flashed the card with Raspbian, whichever version I guess (I used Lite).

Prepping

Mount the device’s card on a machine, I used OSX but on Linux it should be the same.

  • Open up the mounted SD card, this should be the /boot volume.
  • Create an empty file called ssh. This will enable SSH on bootup.
  • Then create a file called wpa_supplicant.conf add the following to it and adjust as needed.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOUR_SSID"
    psk="YOUR_SSID_PASSWORD"
    key_mgmt=WPA-PSK
}

On boot this file will be copied to /etc/wpa_supplicant/wpa_supplicant.conf

Now there should be 2 extra files on your SD card, ssh and wpa_supplicant.conf.

After booting these files will vanish from /boot and will be copied to the appropriate locations.

Now you unmount the SD-Card and stick it in your Raspberry Pi Zero W and have it boot and it will automatically join the network. Check your Router for the IP address it joined with. You’ll now be able to login using user pi and password raspberry.

Spotifyd

So I wanted to have a Spotify Connect device, since I got a nice stereo and it doesn’t natively have networking capabilities.

Turns out there’s an awesome Github project: Spotifyd/spotifyd

Setup

Time to setup the Spotifyd, you can grab the latest on their releases page.

wget https://github.com/Spotifyd/spotifyd/releases/download/untagged-9611d797f6d3344e6a8e/spotifyd-2017-07-22-armv7.zip
unzip spotifyd-2017-07-22-armv7.zip
chmod +x spotifyd
mv spotifyd /usr/bin/

Then we create a file for Spotifyd to work from, I took the example from their README, excellent stuff. This was the bare minimum I needed since I already set the default device previous. I have to software control over the volume, but it does work from Spotify’s UI.

The following should go in ~/.config/spotifyd/spotifyd.conf

[global]
backend = alsa
device_name = ZeroW
bitrate = 320
device = plughw:CARD=Audio # add this (from `aplay -L`) when you skipped the systemwide audio device

If you skipped the systemwide audio setup, you’ll have to check with aplay -L which device you need. I recommend you to use the plughw one to prevent resampling issues.

For more advanced things, like caching of files, go checkout their Github project, it’s well documented.

systemd

Spotifyd also has a systemd service file available for automatic starting of the daemon on boot.

I want the Spotifyd daemon to run on system start without logging in.

wget https://raw.githubusercontent.com/Spotifyd/spotifyd/master/contrib/spotifyd.service
sudo mv spotifyd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable spotifyd.service
sudo mv .config/spotifyd/spotifyd.conf /etc/

Now make the following adjustment to /etc/systemd/system/spotifyd.service.

## existing
ExecStart=/usr/bin/spotifyd --no-daemon
## change to
ExecStart=/usr/bin/spotifyd --no-daemon --config /etc/spotifyd.conf

That’s it for having it auto start :)

NAD DAC

So the first test with Spotifyd was done using a FiiO E10 DAC, now I thought, great time to wrap this up and attach my NAD DAC 1. Yeah so here the problems began. My initial testing I used the FiiO using type hw instead of type plughw. This was fine, since the FiiO could do both 44.1kHz and 48kHz. The NAD DAC 1 only takes 48000Hz, and Spotify feeds it 44100Hz which ALSA then has to do something with.

This can be fixed though, turns out for this card I did have to define an actual device in the spotifyd.conf, so I went back to aplay -L|grep -A1 plughw and got this as output:

plughw:CARD=Headset,DEV=0
    USB Headset, USB Audio

For resampling to work, we need to use the plughw:CARD=Headset one and not the hw one. I couldn’t get it to work purely with the asound.conf so I gave up and just added the following to ~/.config/spotifyd/spotify.conf

device = plughw:CARD=Headset

Optional Systemwide audio

On the Pi we have to do a few things, first find out your Audio device name (I use an external DAC, saves a lot of hassle), you can do so with aplay -l however this command will output the valid names for the config file. I couldn’t get this working with my NAD DAC. It did work with my FiiO DAC.

$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq
ALSA
Audio # this is the one I need

The following can then be placed in the file /etc/asound.conf

pcm.!default {
        type hw
        card Audio
}

ctl.!default {
        type hw
        card Audio
}