Prepare SD card with Raspbian

Download Raspbian Buster Lite and write it with balenaEtcher to the SD-card.

Alternative: DD img file to SD card

1
2
3
diskutil list
diskutil unmountDisk /dev/diskX
sudo dd bs=4m if=[path/to/raspbian.img] of=/dev/rdiskX

Enable SSH server

After you copied Raspbian onto the SD card you have to create a file called ssh on the volume. touch /Volumes/boot/ssh

Prepare SD card for Wi-Fi

Create a text file /boot/wpa_supplicant.conf with your Wi-Fi settings.

1
2
3
4
5
6
7
8
9
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=[TWO_LETTER_COUNTRY_CODE]

network={
    ssid="[WIFI_NAME]"
    psk="[WIFI_PASSWORD]"
    key_mgmt=WPA-PSK
}

Log into Raspberry Pi

The easiest way to find your Raspberry Pi is by logging into your router (usually 192.168.1.1) and finding there the DHCP IP address assigned to the device.

ssh pi@[IP_ADDRESS] with password raspberry

Headless Setup

There are a few steps you have to do on your first login:

  1. Change the default password with passwd
  2. Change hostname with sudo raspi-config -> 2 -> N1
  3. Change local to us_US.UTF-8 sudo raspi-config -> 4 -> I1
  4. Change timezone in sudo raspi-config -> 4 -> I2
  5. Update raspberry sudo apt-get update && sudo apt-get upgrade -y
  6. (optional) Reduce GPU memory to 16MB in sudo raspi-config -> 7 -> A3
  7. (optional) Upgrade distro sudo apt-get update && sudo apt-get dist-upgrade
  8. Setup password less login ssh-copy-id pi@[IP_ADDRESS]

After reboot you have to connect to new hostname. sudo reboot

Configure Static IP

You can reserve the IP in the router, but I prefer the devices to be configured with a fix IP, so that in case of a poweroutage they don’t have to wait for the router.

sudo nano /etc/dhcpcd.conf - inside you will find an example.

1
2
3
4
interface eth0
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 8.8.4.4

Backup and Restore SD on a Macbook

This will create a backup of all the blocks so you can only restore it to a stick of the same size.

1
2
3
4
5
diskutil list
diskutil unmountDisk /dev/disk2
sudo dd bs=4m if=/dev/disk2 | gzip > rasbian.img.gz
(gunzip --stdout rasbian.img.gz | sudo dd bs=4m of=/dev/rdisk2)
gzip -dc rasbian.img.gz | dd of=/dev/rdisk2

Advertise SSH in mDNS (bonjour)

mDNS allows you to find your device easier in the network, you can connect to it with ssh pi@hostname.local.

sudo nano /etc/avahi/services/ssh.service

1
2
3
4
5
6
7
8
9
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
     <type>_ssh._tcp</type>
     <port>22</port>
  </service>
</service-group>

Discovery - DNS-SD Browser for macOS

Installing node.js on Raspberry Pi

I recommend using the Node Version Manager Install LTS version nvm install --lts or latest nvm install node. Test it with node -v and learn where nvm put it with which node.

Alternative: Installing node.js directly into /usr/local

Visit the node.js download page and get the download link for ARM.

1
2
3
wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-armv7l.tar.xz
sudo tar --strip-components 1 -xf node-v12.13.0-linux-armv7l.tar.xz -C /usr/local/
node -v

Installing Go on Raspberry Pi

Visit Go download page and copy the ARM download link.

1
2
3
4
5
wget https://dl.google.com/go/go1.13.4.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.13.4.linux-armv6l.tar.gz
echo "export PATH=\$PATH:/usr/local/go/bin" >> $HOME/.profile
# on your next login
go version

Common Problems

  • -bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) -> your Terminal locale settings are different from the Pi. Change the local on the Pi.
  • Time/Timezone is not working or problem with NTP -> run sudo raspi-config and setup timezone.
  • How can I extend the life of my SD card?
  • Print serial: cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2
  • Print MAC: cat /sys/class/net/eth0/address
  • Print Pi Model: cat /proc/device-tree/model
  • The Wi-Fi can fail to reconnect http://raspberrypi.stackexchange.com/a/28047/52917

Misc tools

1
sudo apt-get install vim nano rsync bc wget curl -y

Benchmark SD card

Its just good to have a feeling how fast you can read and write to the SD card. This allows you to judge what applications to run on the Raspberry Pi.

Downlaod sd_card_speed_test.sh

1
2
3
sudo bash sd_card_speed_test.sh /
Average sequential write speed: 19.26MB/sec.
Average sequential read speed: 22.19MB/sec.

Blink system LED

When you need to identify a Raspberry Pi, because you have so many :)

  • Turn off all triggers (I think per default it blinks on disk writes) for the LED echo none >/sys/class/leds/led0/trigger
  • Set brightness to full echo 1 >/sys/class/leds/led0/brightness
  • Turn off LED echo 1 >/sys/class/leds/led0/brightness
  • Set a trigger for the LED echo timer >/sys/class/leds/led0/trigger