Setting up a Raspberry Pi

Raspberry Pis are great! I've build remote controllable LED strips, setup a tor bridge and setup a small fileserver for my flat, among other things.

After repeatedly grabbing together all the information to setup the Pi and configure it properly I've chosen to write this little walkthrough of how I setup a fresh install of raspbian.

Install

First, download raspbian from the official website, either as a zip or as a torrent.

Then use balenaEtcher to flash the image to an SD card.

headless enable wifi and ssh

Once the image is flashed to the card, ssh and wifi can be configured directly through files on the SD card, so there is no need to connect a screen or an ethernet cable at all. Afterwards you just plug the Pi into a socket and it connects to the wifi with an SSH server open.

Official Documentation.

To enable SSH without a screen connected to the Pi (headless), a file named ssh needs to be placed in the boot partition place (source).

Wifi can be anabled by placing a wpa_supplicant.conf file in the boot partition, or enabled later on if you connect with a cable at first. If you put the file there, the content should be:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert country code here>

network={
 ssid="<Name of your WiFi>"
 psk="<Password for your WiFi>"
}

Take care to replace the values for country, ssid and psk.

With wifi and headless ssh enabled it only needs power and you can connect to it with the default credentials: pi@raspberrypi:raspberry.

Configuration after First Boot

The rest of the configuration can be done on the Raspberry Pi through ssh. Official Documentation.

Run sudo raspi-config to configure a bunch of things at first.

  • Change the hostname. I like to do that since I frequently had multiple Pis in the same network. You can also just edit /etc/hostname.
  • set the timezone.
  • Expand the filesytem.
  • If you hadn't configured wifi before, do it in here.

New User, sudo, ssh-key

I like to add my own user and push my own ssh-key to the Pi.

  1. Add a new user: sudo adduser USERNAME.
  2. Add the user to the sudo group: sudo usermod -a -G sudo USERNAME.
  3. Log out and log in as the new user.
  4. Verify that you are sudo by running something like sudo touch test. You should be in the sudo group.

Copy your ssh key file to the pi: ssh-copy-id -i ~/.ssh/your_key_file.pub username@raspberrypi.

Then you could delete the pi user, but I'll leave it for now.

First, install tmux! Then in tmux, update the system and install useful things like git. It's ready!

Other Software

Once the basic setup is done, there is other software that I frequently found useful.

pi-blaster

pi-blaster is pretty neat software to set the PWM pins on the Pi. It's useful for setting LEDs for example.

The software can be installed by cloning the repo, building the deb file and installing it. It uses a systemd unit to run.

Clone:

git clone https://github.com/sarfata/pi-blaster.git

Install prerequisites:

sudo apt-get install debhelper dh-autoreconf dh-systemd dpkg-dev \
  init-system-helpers autoconf

Build and install the deb package:

dpkg-buildpackage -us -uc -i && sudo dpkg -i ../pi-blaster*.deb

After the installation is finished, configure the gpio pins that you want to control in the file /etc/defaults/pi-blaster. The default list is:

--gpio 4,17,18,27,21,22,23,24,25

0 is not a valid pin, and 6 is 'banned'.

to enable all pins:

--gpio 14,15,18,23,24,25,8,7,1,12,16,20,21,2,3,4,17,27,22,10,9,11,5,13,19,26

I have a special selection of pins I use to control 4 RGB LED strips on one of my Pis, for that one the pins are:

--gpio 14,15,18,23,25,24,17,27,22,10,9,11

The pins are ordered (rgb,rgb,rgb,rgb).

Afterwards run

sudo systemctl daemon-reload
sudo systemctl restart pi-blaster

For the new config to take effect.

Carla

Carla (GitHub) is an open source VST plugin host. It does many things right. I initially found it because it was a natural extension from working with jack, since it integrates with it perfectly; jack clients show up in Carla and vice versa.

There are no binaries distributed for ARM, and no install instructions specifically for ARM either. On GitHub some issues came up mentioning ARM (#670, #805).

To install Carla on the Raspberry Pi, clone the repository:

git clone https://github.com/falkTX/Carla.git
cd Carla
git checkout v2.0.0

Install dependencies:

sudo apt install python3-pyqt5.qtsvg python3-rdflib pyqt5-dev-tools \
  libmagic-dev liblo-dev libasound2-dev libpulse-dev libx11-dev \
  libgtk2.0-dev libgtk-3-dev libqt4-dev qtbase5-dev libfluidsynth-dev

then cd into the Carla directory and run make:

/usr/bin/make -O -j2 SKIP_STRIPPING=true NOOPT=true V=1
sudo make install

This will take a while. the NOOPT flag disables a bunch of options that do not work on the Raspberry Pi.

Also install jack

sudo apt install jackd

I have a USB microphone that I want to use with jack. aplay -l displays the alsa devices, mine is just called Device. I created the ~/.jackdrc file with contents:

jackd -dalsa -dhw:Device -r48000 -p512 -n2 -Xseq

Rust

compiling for the raspberry pi

source

Install the rustup stuff:

rustup target add armv7-unknown-linux-gnueabihf

Install the linker:

sudo apt install gcc-arm-linux-gnueabihf

in ~/.cargo/config:

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

To build:

cargo build --target armv7-unknown-linux-gnueabihf

If there are system dependencies, add armhf as an architecture

sudo dpkg --add-architecture armhf

then run apt update and install the dependencies, for example jack:

sudo apt install libjack-jackd2-dev:armhf

I had a missing -lgcc_s, I couldn't find it so I just copied it from the raspberrypi. It was in /lib/arm-linux-gnueabihf/libgcc_s.so.1 and I copied it to the same place on my system (removing the .1 at the end).