Introduction
For those unfamiliar, a Raspberry Pi is a low-cost, energy efficient, highly extensible, credit card sized computer. To assist new Raspberry Pi owners I have put together my notes on the topic and will continue to append to it as new discoveries are made.
Common Commands
Copying a Raspberry Pi Operating System Image (.img) to a microSD Card
Loading an initial operating system can seem like a daunting task, in fact many Mac users are unaware that copying an .img file to a microSD does not require any additional software. In this example I will be using Raspbian Stretch Lite, a good base image for most Raspberry Pi projects.
Connect the microSD card to a Mac using an SD card adapter or a microSD to USB reader.
To find the disk identifier of the microSD card, open Terminal and run the following command:
diskutil list
Before we can copy the Raspbian data to the microSD card we need to unmount the disk first with the command:
sudo diskutil unmountDisk /dev/disk2
Time to copy the contents of the image file to the microSD card, take note of the r in front of disk2:
sudo dd if=~/Downloads/2017-11-29-raspbian-stretch-lite.img of=/dev/rdisk2 bs=1m
Setting Up a Headless (No Screen) Raspberry Pi
By default SSH (remote login) is disabled. To enable SSH create an empty file called "ssh" in the root of the SD card. On a Mac this can be achieved with the Terminal command:
touch /Volumes/boot/ssh
Connect to Wi-Fi
Raspbian includes the Raspberry Pi Software Configuration Tool, this includes a user friendly way to configure network settings. To open type:
sudo raspi-config
If you are unable to run the above command (e.g. no display or Ethernet available) and want the Raspberry Pi to connect to Wi-Fi, create a wpa_supplicant.conf file in the root of the SD card (/Volumes/boot/) and add the following:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=AU network={ ssid="Your Wi-Fi network name" psk="Your Wi-Fi password" key_mgmt=WPA-PSK }
Changing the Default User Password
By default the username is pi and the password raspberry. Once logged into the Raspberry Pi, the easiest way to change the password is with the command:
sudo raspi-config
Updating Raspbian
To check for and install any available updates:
sudo apt-get update && sudo apt-get dist-upgrade && sudo reboot now
Favourite Use Cases
Pi-hole - Block Ads On Your Local Network
Pi-hole is one of the best uses of the Raspberry Pi hardware. Pi-hole acts as a Domain Name System (DNS) server on the local network, blocking requests to ad related networks. This results in webpages and apps displaying content without unwanted ads. The screenshots below show the difference Pi-hole makes to the website speedtest.net.
Pi-hole also includes a nice dashboard, reporting usage and providing the ability to further blacklist/whitelist specific sites.