Back to All Cheatsheet Libraries cheatsheets

Raspberry Pi

Setup and admin commands, GPIO/I2C/SPI concepts with a Python example, and a headless-setup walkthrough.

Total Commands: 0
Category Command Description
Configsudo raspi-configOpens the interactive configuration tool — interfaces, boot options, locale, hostname.
Configsudo raspi-config nonint do_ssh 0Enables SSH non-interactively — the standard trick for headless setup scripting.
System Infovcgencmd measure_tempReads the SoC temperature — the standard thermal-throttling check.
System Infovcgencmd get_throttledReturns a bitmask flagging under-voltage or throttling events since boot.
System Infocat /proc/cpuinfoShows CPU details, including the board's Revision code (identifies exact Pi model).
Storagedf -hShows disk usage — the standard "is the SD card full" check.
Storagesudo raspi-config --expand-rootfsExpands the root filesystem to fill the whole SD card — usually automatic on first boot.
Networkhostname -IShows the Pi's current IP address(es) — the fastest way to find it for SSH.
Networksudo nmtuiText-mode Wi-Fi/network configuration UI (current Raspberry Pi OS / NetworkManager-based).
Cameralibcamera-still -o photo.jpgCaptures a still photo from the official camera module (current libcamera stack).
Cameralibcamera-vid -o video.h264 -t 10000Records 10 seconds of video from the camera module.
Packagessudo apt update && sudo apt full-upgradeUpdates package lists and upgrades installed packages, including ones needing removals (kernel updates).
Powersudo shutdown -h nowSafely powers off — always shut down cleanly before pulling power, to avoid SD card corruption.
Powersudo rebootRestarts the Pi.
Servicessystemctl status servicenameChecks the status of a systemd service — same as any modern Linux distro.
Firmwaresudo rpi-updateUpdates the bootloader/firmware — for troubleshooting only, not part of routine updates.

GPIO Concepts

BCM vs. Board Numbering

BCM numbers refer to the Broadcom SoC's internal GPIO numbering; Board numbers are simple physical pin-position counting (1-40) — libraries let you pick either mode, and mixing them up is the most common wiring bug.

3.3V Logic

GPIO pins are 3.3V, not 5V-tolerant — feeding a GPIO input 5V directly can permanently damage it. Use a level shifter or voltage divider for 5V sensors.

I2C

A 2-wire (SDA/SCL) bus for sensors/displays that each have an address — enable via raspi-config, then scan the bus to confirm a device is detected.

SPI

A faster 4-wire bus (MOSI/MISO/SCLK/CE) used for displays and ADCs — also enabled via raspi-config's interface options.

UART (Serial)

The hardware serial port on GPIO 14/15 — by default it may be used for Bluetooth or the Linux console, so enabling a project's own use of it sometimes needs the console disabled first.

PWM

Only specific GPIO pins support true hardware PWM — check the pinout before wiring a servo or dimmable LED to an arbitrary pin.

Enabling Interfaces

Command Purpose
sudo raspi-config nonint do_i2c 0Enables I2C non-interactively.
sudo raspi-config nonint do_spi 0Enables SPI non-interactively.
sudo raspi-config nonint do_camera 0Enables the camera interface non-interactively.
i2cdetect -y 1Scans I2C bus 1 and prints the address of any connected device.

Blinking an LED with Python (RPi.GPIO)

The canonical first GPIO program — set up, drive high/low, clean up.

import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) try: while True: GPIO.output(17, GPIO.HIGH) time.sleep(1) GPIO.output(17, GPIO.LOW) time.sleep(1) finally: GPIO.cleanup()

Headless Setup From Scratch

Getting a Pi on the network and reachable via SSH with no monitor or keyboard ever attached.

1

Flash the OS with Raspberry Pi Imager

The official imager's advanced options (gear icon / Ctrl+Shift+X) let you pre-set the hostname, enable SSH, and configure Wi-Fi credentials before the first boot — no separate boot-partition file editing needed on current versions.

2

Boot and wait for network join

First boot takes longer than usual (filesystem expansion, key generation) — give it a couple of minutes before trying to connect.

3

Find it on the network

ping raspberrypi.local (mDNS, works on most networks) or check your router's DHCP client list if a custom hostname was set.

4

SSH in and change the default password

ssh username@raspberrypi.local, then run passwd immediately — current Raspberry Pi OS no longer ships a universal default password, but any credential set during imaging should still be treated as first-boot-only.

Quick Tips

Under-voltage is the #1 mystery-crash cause
A rainbow square icon (or vcgencmd get_throttled returning a non-zero value) means the power supply/cable can't keep up — always use the official (or equivalently rated) power supply, especially with USB peripherals attached.
SD cards wear out — plan for it
Frequent writes (logs, databases) shorten SD card life — for anything long-running, consider booting from USB SSD (supported on Pi 4/400/5) or moving write-heavy data off the SD card.
Static IP or DHCP reservation for headless projects
Set a DHCP reservation on the router (or a static config on the Pi) for anything you'll SSH into regularly — avoids losing it when the IP changes after a router reboot.
Clone a working SD card before experimenting
Raspberry Pi Imager (or dd/Win32DiskImager) can create a full backup image of a working setup — cheap insurance before a risky config change.