Raspberry Pi — Novice-to-Pro Developer Guide
What is a Raspberry Pi?
Headless, hardened ARM64 Linux + 3.3V GPIO; gpiozero speaks BCM, only lgpio works on Pi 5, buy RAM to the job.
Flash Raspberry Pi OS Trixie (Debian 13, kernel 6.18) with Imager 2.x — fill the Customisation tab (hostname, user, Wi-Fi, SSH public key, optional Connect key) before first boot — then `ssh user@host.local`. Harden like any server: keys-only sshd drop-in, ufw default-deny, unattended-upgrades incl. the Raspberry Pi archive; sudo now asks for a password by default. Reach it via Raspberry Pi Connect or a tailnet, never an open port. Physical computing via `gpiozero` (`sudo apt install python3-gpiozero`; venvs use `--system-site-packages`; mock pins for laptop tests). Rules: GPIO is 3.3V and NOT 5V-tolerant, `LED(17)` = BCM17 = physical pin 11, and only the lgpio backend works on the Pi 5. Local LLMs: Ollama on a Pi 5 8 GB (1–4B models) or the AI HAT+ 2 (Hailo-10H, 8 GB on-HAT). 2026 memory prices mean a 1 GB Pi 5 is $45 but 16 GB is $305 — spec RAM to the workload.
Six things to know
The board, the pins, the OS workflow, and the libraries that make it sing. Tap a card for commands + gotchas.
The 40-pin header — click a pin
The Pi’s defining feature, made tangible. Click any pin to see its function and the gpiozero call. Flip BCM ⇄ Physical numbering to feel the #1 beginner trap, and highlight a bus (I2C / SPI / UART / PWM) to see how the header is organised.
from gpiozero import LED
led = LED(17) # BCM17 = physical pin 11Pinout is the universal 40-pin J8 standard (raspberrypi.com/documentation, pinout.xyz). Pins are 3.3V — feeding 5V into a GPIO input can fry the SoC; the 5V pins are for powering peripherals only. Run pinout on your Pi for the live diagram.
██████╗ █████╗ ███████╗██████╗ ██████╗ ███████╗██████╗ ██████╗ ██╗ ██╗ ██████╗ ██╗
██╔══██╗██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔════╝██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔══██╗██║
██████╔╝███████║███████╗██████╔╝██████╔╝█████╗ ██████╔╝██████╔╝ ╚████╔╝ ██████╔╝██║
██╔══██╗██╔══██║╚════██║██╔═══╝ ██╔══██╗██╔══╝ ██╔══██╗██╔══██╗ ╚██╔╝ ██╔═══╝ ██║
██║ ██║██║ ██║███████║██║ ██████╔╝███████╗██║ ██║██║ ██║ ██║ ██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝Raspberry Pi — Novice-to-Pro Developer Guide
Focus: A complete path from "I just bought a Pi" to shipping production edge workloads — hardware models and current prices, headless OS setup, security hardening, remote access, the 40-pin GPIO header and its 3.3V rule, the Python physical-computing stack (
gpiozero,picamera2,lgpio), Node/TypeScript on the Pi, running local LLMs (Ollama, llama.cpp, AI HAT+ 2), experiments to run with Claude Code, and how the Pi compares to Arduino, ESP32, Jetson, and the Pi's own Pico microcontroller. Grounded inraspberrypi.com/documentation, the Raspberry Pi OS release notes,gpiozero.readthedocs.ioanddocs.ollama.com; reviewed 2026-10-20.
The Raspberry Pi is the rare device that is approachable on day one and still in your rack five years later. The trick is to learn it in the right order: get a headless, hardened Linux box running first (no monitor, no keyboard), then reach for the soldering iron. The interactive learn module above this page is a live 40-pin GPIO pinout explorer — start there to build intuition for the header, then use this reference.
Table of Contents
- What a Raspberry Pi actually is
- Pick the right board (and what it costs now)
- Headless OS setup (the right way)
- First-boot configuration
- Security hardening
- Remote access options
- The 40-pin GPIO header
- Physical computing with
gpiozero - The camera & other interfaces (I2C/SPI/UART)
- Node.js & TypeScript on the Pi
- Local LLMs and edge AI
- Hardware components shopping list
- Build ideas — novice to pro
- Experiments with Claude Code
- Raspberry Pi Pico (the microcontroller)
- Comparable tech stacks
- codeAmani notes
Official Documentation
Current versions at a glance (verified 2026-10-20):
| Thing | Current | Notes |
|---|---|---|
| Raspberry Pi OS | Trixie (Debian 13; Debian point release 13.7), image 2026-10-06 | Kernel 6.18.50 (moved off 6.12 in the 2026-06-18 image). Bookworm is the previous release. |
| System Python | 3.13 | PEP 668 blocks pip install into system Python — use apt or a venv |
| Raspberry Pi Imager | v2.0.12 (2026-10-08) | "Customisation" tab replaces the old ⚙ dialog |
gpiozero | 2.0.1.post3 | Default pin factory lgpio; only lgpio works on the Pi 5 |
picamera2 | 0.3.38 (2026-10-12) | Prefer sudo apt install python3-picamera2 |
lgpio (PyPI) | 0.2.2.0 | aarch64 wheels only up to cp312 — on Trixie use the apt package |
rpi-lgpio | 0.6 | RPi.GPIO-compatible shim on lgpio — for legacy RPi.GPIO code |
libgpiod (Debian gpiod) | 2.2.1 | v2 CLI (gpioget/gpioset/gpioinfo) |
| OpenSSH (Trixie) | 10.0p1 | DSA gone; Ed25519 default key type |
| Ollama | 0.40.6 (2026-10-16) | Official arm64 Linux build |
1. What a Raspberry Pi actually is
A single-board computer (SBC): a complete ARM-based Linux computer — CPU, RAM, USB, HDMI, networking, storage (microSD or NVMe) — on one board, with a 40-pin GPIO header for talking to electronics. That dual nature is the whole point:
Why it matters: because it's real Linux, everything you already know — ssh, systemd, Docker, Python, Node, cron, nginx — works unchanged. And because it has GPIO, the same box that runs a web app can also read a temperature sensor or drive a relay. It is the cheapest honest "computer + I/O" you can buy.
Microcontroller vs SBC: A Pi runs a full OS and is great at software (servers, ML, networking). A microcontroller (Arduino, ESP32, the Pi Pico) runs one program on bare metal with precise real-time timing and microamp sleep. Many real projects pair them: Pi for brains + network, Pico/Arduino for the twitchy real-time pins. See §15 and §16.
2. Pick the right board (and what it costs now)
The 2026 reality: memory prices drive Pi prices. LPDDR4 costs rose so steeply through 2025–26 that Raspberry Pi raised prices four times (Dec 2025, 2 Feb 2026, Apr 2026, 1 Oct 2026). The 1 GB boards were held flat; everything with more RAM went up — the 16 GB Pi 5 more than doubled. Raspberry Pi's own advice: buy the RAM your workload needs, not headroom.
| Board | RAM options | US list price (Oct 2026) | Best for | Notes |
|---|---|---|---|---|
| Pi Pico 2 / Pico 2 W | — (RP2350 MCU) | — | Real-time sensors, battery | Not Linux — a microcontroller (§15) |
| Pi Zero 2 W | 512 MB | check reseller | Tiny always-on jobs, cameras | Quad-core, Wi-Fi/BT; header often unpopulated |
| Pi 4 Model B | 1 / 2 / 3 / 4 / 8 GB | $35 / $67.50 / $83.75 / ~$100 / ~$165 | Home server, NAS, kiosk | 3 GB variant added Apr 2026 as a cheaper step |
| Pi 5 | 1 / 2 / 4 / 8 / 16 GB | $45 / $77.50 / ~$110 / ~$175 / $305 | Fast I/O, NVMe, local LLMs, edge AI | BCM2712 (4× Cortex-A76 @ 2.4 GHz), PCIe; needs active cooling + 5V/5A PSU |
| Pi 500 / 500+ | 8 / 16 GB | $180 unit · $200 kit / from $410 | Keyboard-in-a-box desktop (Pi 5-class) | 500+ = mechanical keys + internal 256 GB SSD |
| Pi 400 | 4 GB | $60 | Cheapest all-in-one desktop | Unaffected by the 2026 rises |
| Compute Module 4 / 5 | up to 8 / 16 GB | rose with RAM — check product page | Your own carrier board / product | CM5 is Pi 5-class (BCM2712) |
Prices: 1 GB, 2 GB, 3 GB, Pi 400, Pi 500 and the Pi 5 16 GB are as published on raspberrypi.com product pages / news posts. The "~" figures are computed by adding the announced increases to the original list prices — confirm on the product page before you quote a customer. Approved Resellers honour the published maximum prices; avoid unauthorised sellers with inflated pricing.
Also buy (these are not optional): a quality power supply — the Pi 5 / Pi 500 want 5V at 5A (the official 27 W USB-C PSU); on a 5V/3A supply the Pi 5 limits USB peripherals to 600 mA. The Pi 4 wants 5V/3A. Under-volting causes mysterious crashes. Add a decent A2-rated microSD card (or better, NVMe via an M.2 HAT on the Pi 5) and, for the Pi 5, active cooling.
3. Headless OS setup (the right way)
You do not need a monitor or keyboard. The professional workflow is headless from minute one.
1. Flash with Raspberry Pi Imager (v2.x). Download from raspberrypi.com/software, pick your device, choose Raspberry Pi OS (64-bit) — Lite (no desktop) for servers. Then open the Customisation tab before writing (Imager 2 replaced the old ⚙ "Edit settings" dialog):
- Hostname — letters, numbers, hyphens (
amani-pi); reachable asamani-pi.local(mDNS) - Localisation — choose a capital city; Imager fills time zone, keyboard and the Wi-Fi regulatory domain
- User — lowercase username + password (there is no default
pi/raspberryaccount). This password is now also yoursudopassword — see §4 - Wi-Fi — SSID + password (mandatory for a Wi-Fi-only headless Pi)
- Remote Access — Enable SSH → Use public key authentication, paste your
~/.ssh/id_ed25519.pub(Imager may pre-fill an existing RSA key — prefer an Ed25519 key) - Raspberry Pi Connect (optional) — toggle on, create an auth key in the browser and Imager receives it. Personal auth keys expire 6 hours after creation (organisation keys 1–90 days), so boot the Pi online before then
2. Boot and SSH in — no screen required:
# From your laptop (mDNS resolves <hostname>.local — or .lan — on the same network)
ssh amani@amani-pi.local
# or by IP if .local doesn't resolve:
ssh amani@192.168.1.42
# First things first
sudo apt update && sudo apt full-upgrade -y
sudo rebootIf
*.localdoesn't resolve (some Windows/Android setups), find the IP from your router's DHCP table. On Windows, install Bonjour or just use the IP.
No Imager? On the bootfs partition create an empty file named ssh plus a userconf.txt containing one line, <username>:<encrypted-password> — generate the hash with openssl passwd -6 (on macOS use Homebrew OpenSSL; LibreSSL lacks -6). Imager customisation is still the better path because it can install your public key.
4. First-boot configuration
Know what changed in 2026 images:
- Passwordless
sudois disabled by default (image 2026-04-13 onward).sudoprompts for the password you set in Imager. Automation (Ansiblebecome, provisioning scripts) must supply it, or you re-enable NOPASSWD deliberately via the switch inraspi-config/ Control Centre → System. Leave it off on anything networked. - Kernel 6.18 since the 2026-06-18 image; PulseAudio dropped in favour of PipeWire;
python3-flaskno longer preinstalled. - Upgrading Bookworm → Trixie in place is not recommended — Raspberry Pi "strongly recommend[s]" a clean install of the new image.
raspi-config is the official text UI for system settings; most of it is scriptable:
sudo raspi-config # interactive: interfaces, locale, hostname, boot, sudo
sudo raspi-config nonint do_i2c 0 # enable I2C non-interactively (0 = enable)
sudo raspi-config nonint do_spi 0 # enable SPI
sudo raspi-config nonint do_ssh 0 # ensure SSH onInterfaces can also be toggled directly in /boot/firmware/config.txt via device-tree params — useful in provisioning scripts and Ansible:
# /boot/firmware/config.txt — enable buses at boot
dtparam=i2c_arm=on
dtparam=spi=on
dtparam=audio=on
# camera autodetect is on by default on current Pi OS:
camera_auto_detect=1# Sanity checks after enabling
ls /dev/i2c-* # I2C bus appears
ls /dev/spidev* # SPI device appears
i2cdetect -y 1 # scan the I2C bus (sudo apt install i2c-tools)
vcgencmd measure_temp # SoC temperature — watch for throttling
vcgencmd get_throttled # 0x0 = no under-voltage / throttling since boot5. Security hardening
A Pi on a network is a server. Treat it like one — the defaults are better than they were (no default account, sudo asks for a password) but SSH still accepts passwords until you turn them off. Full SSH depth lives in the remote-access guide; this is the Pi-specific minimum.
1. Keys only, no root, via a drop-in (Debian's sshd_config includes /etc/ssh/sshd_config.d/*.conf, so you never edit the main file):
# On your laptop — if you didn't paste a key into Imager
ssh-keygen -t ed25519 -C "you@laptop"
ssh-copy-id amani@amani-pi.local
# On the Pi — confirm key login works in a SECOND terminal first, then:
sudo tee /etc/ssh/sshd_config.d/10-hardening.conf >/dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
AllowUsers amani
EOF
sudo sshd -t && sudo systemctl reload ssh # validate before reloading2. Firewall — default-deny inbound (ufw 0.36.2 in Trixie, an nftables front end):
sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp # SSH from the LAN only
# sudo ufw allow in on tailscale0 # if you use a tailnet (§6)
sudo ufw enable
sudo ufw status verboseAllow SSH before ufw enable or you lock yourself out of a headless box. If you only reach the Pi via Raspberry Pi Connect or Tailscale, you can drop the LAN SSH rule entirely — both work outbound-only.
3. Automatic security updates with unattended-upgrades (2.12 in Trixie). Debian's default config covers the Debian security archive; add Raspberry Pi's own archive (its Release file declares Origin: Raspberry Pi Foundation, Codename: trixie) so firmware/kernel fixes land too:
sudo apt install -y unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades # writes /etc/apt/apt.conf.d/20auto-upgrades
sudo tee /etc/apt/apt.conf.d/52raspi-origins >/dev/null <<'EOF'
Unattended-Upgrade::Origins-Pattern {
"origin=Raspberry Pi Foundation,codename=${distro_codename},label=Raspberry Pi Foundation";
};
// Field nodes: reboot in a quiet window if a kernel update needs it
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
EOF
sudo unattended-upgrade --dry-run --debug 2>&1 | tail -20 # verify the origins matchAutomatic updates stay within Trixie. Never let anything
dist-upgradeacross major releases unattended — reimage instead (§4). Avoidrpi-update(pre-release firmware) on anything in the field.
4. Brute-force protection. OpenSSH 10 (Trixie) has built-in per-source penalties (PerSourcePenalties) that throttle repeat offenders; with password auth off and SSH not exposed to the internet, fail2ban is optional. Add it if SSH must face the internet — but the better answer is not exposing it (§6).
5. Hygiene checklist: unique hostname + user per device · secrets in EnvironmentFiles with chmod 600 (never in the image) · disable services you don't use (systemd-analyze blame, systemctl disable --now <unit>) · rpi-connect shell off if you use Connect only for screen sharing · back up the SD/NVMe image before risky changes.
6. Remote access options
The question is how do I reach a Pi that isn't on my desk — and the answer is almost never "port-forward 22 on the router". Pick by situation; the remote-access guide has the full SSH/tunnel/VPN depth.
| Option | How it reaches the Pi | Best for | Cost |
|---|---|---|---|
| SSH on the LAN | Direct TCP 22 | Same network, dev bench | Free |
| Raspberry Pi Connect | Pi connects out to Raspberry Pi's service; browser ↔ Pi is WebRTC peer-to-peer, falling back to a TURN relay | Remote shell / screen share from any browser; remote OTA updates for fleets | Personal accounts free; Connect for Organisations billed monthly |
| Tailscale (managed WireGuard mesh) | Outbound to coordination server, then P2P WireGuard | Reaching many Pis + services by MagicDNS name, identity-gated | Free personal tier |
| WireGuard (self-hosted) | UDP to your own VPN endpoint | Full control, no third party | Free (you run it) |
| Cloudflare Tunnel | Outbound-only cloudflared | Publishing an HTTPS service on the Pi (dashboards, Daraja callbacks) | Free tier |
Raspberry Pi Connect (Bookworm or later; screen sharing needs a Wayland desktop, so Lite images use Connect Lite = remote shell only):
sudo apt update
sudo apt install rpi-connect-lite # Lite / headless (remote shell only)
# sudo apt install rpi-connect # desktop images (adds screen sharing)
rpi-connect on
rpi-connect signin # prints a connect.raspberrypi.com/verify/... URL
loginctl enable-linger # keep Connect running with no one logged in (headless!)
rpi-connect doctor # checks STUN/TURN, API reachabilityConnect also does remote updates: install rpi-connect-ota, opt in with rpi-connect ota on, then push either script artefacts (built with otamaker, run as root — e.g. package upgrades) or full A/B boot images (built with rpi-image-gen, auto-revert on failure; needs Pi 4+ imaged with an A/B layout on Trixie). That is the first-party answer to "update 50 kiosks behind 50 different routers".
Data-flow note: Connect sessions are end-to-end encrypted (WebRTC/DTLS, fresh keys per session); when P2P fails, encrypted traffic relays via Raspberry Pi's TURN servers in London (Europe/Africa) or California (Americas/Asia/Oceania), and relaying cannot be disabled except by firewalling the TURN hosts. Access is gated by a Raspberry Pi ID — turn on its 2FA. Connect runs as a user service, hence
loginctl enable-linger. For devices in PCI or customer-data scope, prefer a tailnet with your own ACLs and keep Connect's remote shell off (rpi-connect shell off).
7. The 40-pin GPIO header
Every current Pi (and the Zero, sometimes unpopulated) exposes a 40-pin header on a 0.1in (2.54 mm) pitch. The single rule that saves your board:
⚠️ GPIO is 3.3V logic, not 5V. The pins source/sink 3.3V and are not 5V-tolerant — putting 5V on a GPIO input can permanently damage the SoC. There are two 5V pins (for powering peripherals) and several 3V3 and GND pins, but every signal pin is 3.3V. Use a level shifter for 5V sensors, or hang them off a Pico instead.
The header is a fixed standard across boards. The layout (physical pin → function):
| Pin | Function | Pin | Function | |
|---|---|---|---|---|
| 1 | 3V3 power | 2 | 5V power | |
| 3 | GPIO2 (I2C SDA) | 4 | 5V power | |
| 5 | GPIO3 (I2C SCL) | 6 | GND | |
| 7 | GPIO4 (GPCLK0) | 8 | GPIO14 (UART TXD) | |
| 9 | GND | 10 | GPIO15 (UART RXD) | |
| 11 | GPIO17 | 12 | GPIO18 (PCM/PWM) | |
| 13 | GPIO27 | 14 | GND | |
| 15 | GPIO22 | 16 | GPIO23 | |
| 17 | 3V3 power | 18 | GPIO24 | |
| 19 | GPIO10 (SPI MOSI) | 20 | GND | |
| 21 | GPIO9 (SPI MISO) | 22 | GPIO25 | |
| 23 | GPIO11 (SPI SCLK) | 24 | GPIO8 (SPI CE0) | |
| 25 | GND | 26 | GPIO7 (SPI CE1) | |
| 27 | GPIO0 (ID EEPROM) | 28 | GPIO1 (ID EEPROM) | |
| 29 | GPIO5 | 30 | GND | |
| 31 | GPIO6 | 32 | GPIO12 (PWM) | |
| 33 | GPIO13 (PWM) | 34 | GND | |
| 35 | GPIO19 (PCM/SPI1) | 36 | GPIO16 | |
| 37 | GPIO26 | 38 | GPIO20 (PCM/SPI1) | |
| 39 | GND | 40 | GPIO21 (PCM/SPI1) |
BCM vs physical numbering — the #1 beginner trap. Software (
gpiozero,lgpio, libgpiod line offsets on the main GPIO chip) addresses pins by Broadcom (BCM) GPIO number, not by physical position.LED(17)means BCM17, which sits at physical pin 11 — not physical pin 17 (that's a 3V3 power pin). When in doubt, runpinouton the Pi:
pinout # ASCII diagram of YOUR board's header (ships with gpiozero)
gpioinfo # libgpiod v2: every chip and line, with names (sudo apt install gpiod)8. Physical computing with gpiozero
gpiozero is the official, beginner-friendly Python library — it wraps pins as devices (LED, Button, Servo, DistanceSensor) so you write intent, not register pokes. It's pre-installed on Raspberry Pi OS desktop images; on Lite:
sudo apt install python3-gpiozero # recommended — pulls python3-lgpio and the `pinout` toolIn a virtual environment, inherit the system packages. Trixie's Python is 3.13 and PyPI's lgpio has no 3.13 aarch64 wheel, so pip install lgpio tries to compile. The documented fix is a venv that can see apt's python3-lgpio / python3-picamera2:
python3 -m venv --system-site-packages ~/myapp/.venv
source ~/myapp/.venv/bin/activate
pip install paho-mqtt # your app's own deps go in the venvWhich backend? gpiozero's docs are explicit: "Only lgpio works on the Pi 5."
RPi.GPIO(last release 0.7.1, 2022) andpigpiodon't support the Pi 5's RP1 I/O chip.rpi-lgpiois an RPi.GPIO-compatible shim on lgpio — use it only to run legacy RPi.GPIO code on a Pi 5, not for new gpiozero code. Raspberry Pi OS Trixie also removed the old "Remote GPIO" option.
Blink an LED (LED on BCM17 = physical pin 11, through a ~330Ω resistor to GND):
from gpiozero import LED
from time import sleep
led = LED(17) # BCM17 — NOT physical pin 17
while True:
led.toggle()
sleep(0.5)Button toggles LED — event-driven, no polling loop:
from gpiozero import LED, Button
from signal import pause
led = LED(17)
button = Button(2) # BCM2, with internal pull-up by default
button.when_pressed = led.on
button.when_released = led.off
pause() # sleep forever, let callbacks firePWM for brightness / motor speed:
from gpiozero import PWMLED
from time import sleep
led = PWMLED(17)
led.value = 0.1 # 10% duty cycle
sleep(1)
led.pulse() # smooth fade in/out in a background thread
sleep(5)gpiozero uses BCM numbering and it is not configurable — but you can pass alternate notations that all resolve to BCM: LED(17), LED("GPIO17"), LED("BOARD11") (physical), or LED("J8:11") (header:pin).
Unit-test pin logic on your laptop with the mock pin factory — no hardware, no Pi:
env GPIOZERO_PIN_FACTORY=mock python3 -m pytest tests/9. The camera & other interfaces (I2C/SPI/UART)
Camera (CSI ribbon → picamera2). Modern Pi OS autodetects official camera modules. picamera2 is the supported Python API (the old picamera is deprecated). Install it from apt — it depends on system libcamera:
sudo apt install -y python3-picamera2 # desktop images
sudo apt install -y python3-picamera2 --no-install-recommends # Lite OS, no GUI depsfrom picamera2 import Picamera2
from time import sleep
picam2 = Picamera2()
picam2.start()
sleep(2) # let auto-exposure settle
picam2.capture_file("shot.jpg")
picam2.stop()rpicam-still -o test.jpg # CLI capture (formerly libcamera-still)
rpicam-hello -t 5000 # 5s preview to confirm the camera is detectedThe three buses, in one breath:
| Bus | Pins (BCM) | Use it for | Enable |
|---|---|---|---|
| I2C | SDA=2, SCL=3 | Many low-speed sensors/displays sharing 2 wires by address | dtparam=i2c_arm=on |
| SPI | MOSI=10, MISO=9, SCLK=11, CE0=8 | Fast displays, ADCs, SD/flash | dtparam=spi=on |
| UART | TXD=14, RXD=15 | Serial to a Pico/Arduino/GPS/modem | console off, enable_uart=1 |
i2cdetect -y 1 # find I2C device addresses (e.g. 0x3c for an OLED, 0x76 for BME280)10. Node.js & TypeScript on the Pi
The Pi is ARM64 Debian, so Node runs natively (install from NodeSource or nvm; keep to an LTS line). The interesting question is GPIO from Node, and the honest 2026 answer is: most Node GPIO packages are stale.
| Package | Latest | Status on Pi 5 / Trixie |
|---|---|---|
onoff | 6.0.3 (2022) | Uses the deprecated sysfs GPIO interface — avoid for new work |
rpio, pigpio (npm) | 2.4.2 / 3.3.1 (2022) | Pre-Pi 5 register access — does not work with RP1 |
node-libgpiod | 0.6.0 (Jan 2026) | Character-device API, but its README targets libgpiod 1.5/1.6; Trixie ships libgpiod 2.2.1 — unverified, test before relying on it |
The codeAmani pattern: keep pin I/O in a small Python gpiozero service (the officially supported path) and let Node/TypeScript talk to it over MQTT or a local HTTP socket — or, for one-off reads/writes, call the libgpiod v2 CLI (gpioget/gpioset) with execFile and an argument array (never a shell string, per our security convention). Node's real job on the Pi is the networked app: dashboards, telemetry agents, and talking to a local LLM.
Example — a dependency-free health probe (runs on any Pi with Node ≥ 20; full version with POSTing in examples/pi-health.mts):
import { execFile } from "node:child_process";
import { readFile } from "node:fs/promises";
import { promisify } from "node:util";
const run = promisify(execFile);
export interface PiHealth {
socTempC: number;
throttledHex: string;
underVoltageSinceBoot: boolean;
throttledSinceBoot: boolean;
}
export async function readPiHealth(): Promise<PiHealth> {
// millidegrees C, e.g. "48300\n"
const raw = await readFile("/sys/class/thermal/thermal_zone0/temp", "utf8");
// args as an array — no shell interpolation
const { stdout } = await run("vcgencmd", ["get_throttled"]); // "throttled=0x50005\n"
const hex = stdout.trim().split("=")[1] ?? "0x0";
const bits = Number.parseInt(hex, 16);
return {
socTempC: Number(raw.trim()) / 1000,
throttledHex: hex,
underVoltageSinceBoot: (bits & (1 << 16)) !== 0,
throttledSinceBoot: (bits & (1 << 18)) !== 0,
};
}11. Local LLMs and edge AI
Raspberry Pi's own framing: most edge AI/ML belongs on the CPU; accelerators are for the minority of workloads the CPU can't handle. For language models you have three tiers:
| Tier | Hardware | Software | What fits | Reality check |
|---|---|---|---|---|
| CPU only | Pi 5, 8 GB (16 GB if proven needed) | Ollama (official arm64 build) or llama.cpp | ~0.6–4B params at 4-bit: qwen3:0.6b/1.7b/4b, gemma3:1b, llama3.2:1b/3b, granite4:1b/3b, gemma4:e2b | Usable for short, scoped prompts (classify, extract, summarise a reading). Measure tokens/s on your board and cooling. |
| AI HAT+ 2 | Pi 5 + Hailo-10H, 40 TOPS (INT4), 8 GB on-HAT RAM, $200 | sudo apt install dkms hailo-h10-all → hailo-ollama (Ollama-compatible REST API, default port 8000) | Hailo-compiled models only: Qwen2/2.5 1.5B, Qwen2.5-Coder 1.5B, Qwen3 1.7B, Llama 3.2 1B, DeepSeek-R1-Distill-Qwen 1.5B, plus VLMs | Frees the Pi's own RAM/CPU; model choice is limited to Hailo's GenAI zoo |
| Vision NPU | AI HAT+ (Hailo-8L 13 TOPS / Hailo-8 26 TOPS), legacy AI Kit, AI Camera (Sony IMX500) | sudo apt install dkms hailo-all · sudo apt install imx500-all | Detection/segmentation/pose — not LLMs (the AI docs: LLMs are AI HAT+ 2 only) | Pair a vision NPU with a CPU/cloud LLM for "see → describe" |
Third-party option: the Sixfab AI HAT+ (DEEPX DX-M1M, 25 TOPS at ~3 W, 2 GB on-module) runs CNNs, compact VLMs and SLMs — Raspberry Pi's own post measured Qwen3-1.7B at 4.64 tok/s on it (Pi 5 8 GB).
CPU path — Ollama (official installer creates the ollama user + systemd unit; API on http://localhost:11434):
curl -fsSL https://ollama.com/install.sh | sh
ollama pull qwen3:1.7b
ollama run qwen3:1.7b "Classify: 'pump pressure dropped to 0.8 bar' -> ok|warn|fail"
# Expose to the LAN/tailnet only if you must — via a systemd override, then firewall it:
sudo systemctl edit ollama # [Service] Environment="OLLAMA_HOST=0.0.0.0:11434"Ollama's API has no authentication. Keep it on
127.0.0.1and put your app in front of it, or bind it only to thetailscale0interface and restrict withufw. Never port-forward it.
llama.cpp is the engine underneath; build it on the Pi (cmake -B build && cmake --build build -j4, releases are tagged bNNNNN — b11755 on 2026-10-20) when you want llama-server's OpenAI-compatible endpoint, GGUF files you control, or tighter memory tuning than Ollama exposes.
AI HAT+ 2 path — hailo-ollama:
sudo apt update && sudo apt full-upgrade -y
sudo apt install dkms
sudo apt install hailo-h10-all
sudo reboot
# Hailo Model Zoo GenAI (v5.4.0) provides the hailo-ollama server:
hailo-ollama &
curl --silent http://localhost:8000/hailo/v1/list
curl --silent http://localhost:8000/api/pull -H 'Content-Type: application/json' \
-d '{ "model": "qwen2:1.5b", "stream": true }'Because both servers speak the Ollama /api/chat shape, the same TypeScript client works against either — see examples/ollama-chat.mts:
interface ChatMessage { role: "system" | "user" | "assistant"; content: string }
interface ChatResponse { model: string; message: ChatMessage; done: boolean; eval_count?: number; eval_duration?: number }
export async function chat(baseUrl: string, model: string, messages: ChatMessage[]): Promise<ChatResponse> {
const res = await fetch(`${baseUrl}/api/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, messages, stream: false }),
signal: AbortSignal.timeout(120_000), // small boards are slow on first load
});
if (!res.ok) throw new Error(`chat failed: ${res.status} ${await res.text()}`);
return (await res.json()) as ChatResponse;
}
// CPU Ollama: chat("http://127.0.0.1:11434", "qwen3:1.7b", msgs)
// hailo-ollama: chat("http://127.0.0.1:8000", "qwen2:1.5b", msgs)Routing rule (codeAmani AI policy): the on-device model is the offline fallback and the privacy-first classifier, not the brain. Complex reasoning and code generation still route to Claude; structured output to GPT-4o — when the link is up. See §17.
12. Hardware components shopping list
A starter kit that covers 90% of beginner projects:
- Breadboard + jumper wires (M-M, M-F) + a 40-pin GPIO breakout / T-cobbler ribbon (keeps you off the live header)
- Resistors (330Ω for LEDs, 10kΩ for pull-ups), assorted LEDs, tactile push-buttons
- Sensors: BME280 (temp/humidity/pressure, I2C), HC-SR04 (ultrasonic distance — its 5V echo needs a divider), PIR (motion), MCP3008 (ADC — the Pi has no analog input, this is how you read analog sensors over SPI)
- Output: SSD1306 OLED (I2C), relay module (mains switching — be careful), small servo (SG90), DC motors + a motor driver / motor HAT (never drive motors straight off GPIO)
- Power discipline: a logic level shifter for 5V parts, and a separate supply for motors/servos (back-EMF + current spikes will brown-out your Pi)
- HATs (Hardware Attached on Top): Sense HAT, PoE HAT, M.2 HAT+ (NVMe on Pi 5), motor/relay HATs, AI HAT+ / AI HAT+ 2 (§11); the new Smart Display Module ($30) for low-power display products
The cardinal hardware rules: common ground between Pi and any external supply; never source motor/relay current from a GPIO pin; level-shift anything 5V; and double-check polarity before powering on.
13. Build ideas — novice to pro
- Novice: Blink, traffic-light LEDs, reaction-timer button game, GPIO-controlled buzzer; a tiny web page on the LAN that turns an LED on/off (your first "IoT").
- Intermediate: Weather station (BME280 → SQLite/Postgres → a dashboard); Pi-hole + WireGuard/Tailscale to reach home from anywhere; Samba/NAS on NVMe; time-lapse camera; print server.
- Advanced: MQTT sensor network (Picos/ESP32s publishing to a Mosquitto broker on the Pi); kiosk signage (Chromium kiosk mode) with Connect for remote fixes; Home Assistant hub; doorbell camera with on-camera detection (AI Camera).
- Pro: Offline assistant — AI Camera or AI HAT+ for perception + a local SLM (Ollama / hailo-ollama) for "describe/decide"; a fleet updated through Connect's A/B OTA images built with
rpi-image-gen; a Compute Module 5 baked into your own carrier board as a shippable product; a solar-powered remote telemetry node.
14. Experiments with Claude Code
Claude Code runs on the Pi (it's just ARM64 Linux) or drives it remotely over SSH from your laptop. Both unlock fast hardware iteration: describe the circuit and the behaviour, let Claude write the gpiozero script, run it, read the output, and iterate. For the current install method see the anthropic guide — on a 1–2 GB Pi prefer driving it over SSH from your laptop rather than running the agent locally.
Experiments that play to Claude Code's strengths:
- Conversational circuit bring-up. "I wired a BME280 to I2C and an SSD1306 OLED — read temp/humidity every 10 s and show it on the display." Claude writes it;
i2cdetect -y 1confirms addresses; you run and refine. - Hardware-in-the-loop TDD. Claude writes tests against gpiozero's mock pin factory (
env GPIOZERO_PIN_FACTORY=mock) so logic is unit-tested on your laptop, then deployed to real pins. - Sensor → cloud pipeline. "Publish each reading to MQTT and also POST to a Next.js API route." Pairs with the webhooks and supabase guides.
- Local LLM on the edge. Run
qwen3:1.7bunder Ollama (or a Hailo model on AI HAT+ 2) and have Claude Code build the glue: an assistant that classifies sensor events offline and syncs when connectivity returns. - Vision on the edge. AI Camera or AI HAT+: Claude scaffolds a
picamera2capture loop feeding a detector, writing events to a DB. - Harden and verify. Ask Claude to audit the box:
sshd -T,ufw status verbose,unattended-upgrade --dry-run,systemd-analyze security <unit>— and fix what it finds.
Run Claude Code over SSH for the tightest loop: edit on the laptop, execute on the Pi, watch real sensor output stream back. Pair with chrome-devtools to verify any web UI the Pi serves.
15. Raspberry Pi Pico (the microcontroller)
The Pico is a different animal: a microcontroller board built on the in-house RP2040 (Pico/Pico W) or RP2350 (Pico 2 / Pico 2 W) chip — not a Linux computer. The RP2350 keeps the dual-core, dual-PIO design but adds switchable Arm Cortex-M33 or RISC-V (Hazard3) cores, more SRAM, and secure/signed boot. No OS, no SD card; you flash one program that runs on bare metal. It shines where the Pi is weak: precise real-time timing, microamp sleep, true analog inputs (ADC), and being cheap enough to scatter — and its price isn't hostage to LPDDR4.
Two ways to program it:
# MicroPython (drag-and-drop firmware, then this is main.py) — blink the onboard LED
from machine import Pin
from time import sleep
led = Pin("LED", Pin.OUT)
while True:
led.toggle()
sleep(0.5)// C/C++ with the Pico SDK — pico-examples style
#include "pico/stdlib.h"
int main() {
const uint LED = PICO_DEFAULT_LED_PIN;
gpio_init(LED); gpio_set_dir(LED, GPIO_OUT);
while (true) { gpio_put(LED, 1); sleep_ms(250); gpio_put(LED, 0); sleep_ms(250); }
}Pico W (RP2040) and Pico 2 W (RP2350) add 2.4 GHz Wi-Fi + Bluetooth, so they can publish to MQTT on their own. The classic architecture: Picos at the edge (sensors, real-time control) talking to a Pi hub (network, storage, dashboard).
16. Comparable tech stacks
| Platform | Type | Pick it when |
|---|---|---|
| Arduino (Uno/Nano) | MCU | Dead-simple 5V I/O, huge tutorial base, no networking needed |
| ESP32 | MCU + Wi-Fi/BT | Cheap connected sensors; battery IoT (the budget IoT king) |
| Raspberry Pi Pico 2 / Pico 2 W | MCU (RP2350) | Real-time control, PIO, MicroPython/C, very cheap |
| NVIDIA Jetson (Orin Nano) | SBC + GPU | On-device deep-learning / larger LLMs a Pi 5 + HAT can't keep up with |
| Hailo / DEEPX / Coral accelerators | NPU add-ons | Fast, low-power inference added to a Pi |
| BeagleBone | SBC | Hard real-time via PRUs, industrial I/O |
| Orange Pi / Radxa / Banana Pi | SBC | More specs per dollar; software/community less polished |
| x86 mini-PCs (N100-class) | x86 | You need x86 compatibility — and at 2026 Pi 5 8–16 GB prices, often comparable cost |
The honest summary: the Pi wins on ecosystem — documentation, community answers, first-party tooling (Imager, Connect, OS updates), and "it just works" software. Rivals win on specific axes (price-per-GB in 2026, GPU, battery life, real-time determinism). Most serious builds are hybrids: a Pi for brains + a Pico/ESP32 for the real-time edge.
17. codeAmani notes
- The Pi is our edge node — spec RAM to the job. codeAmani is US-first; Pis show up as in-store kiosks, sensor hubs, and offline-capable assistants. After the 2026 price rises, a 1–2 GB Pi 5 ($45–$77.50) covers almost every service; reach for 8 GB only for a CPU-hosted LLM, and price an AI HAT+ 2 ($200, 8 GB on-HAT) against a 16 GB board ($305) before choosing. Quote prices from the product page on the day.
- Harden every unit before it leaves the bench. Keys-only SSH via a
sshd_config.ddrop-in,ufwdefault-deny,unattended-upgradesincluding the Raspberry Pi origin,sudowith a password (the 2026 default — keep it), Connect remote shell off unless needed. Use the remote-access guide for tailnet ACLs. - Never open a port to reach a Pi. Default: Tailscale (identity-gated, our ACLs). Raspberry Pi Connect is fine for non-sensitive kiosks and is the cleanest fleet OTA path (A/B images via
rpi-image-gen). Cloudflare Tunnel only when a Pi must serve a public HTTPS endpoint. - Secrets stay server-side. A Pi image is a deployable artefact: no API keys, Stripe keys, DB creds or Daraja credentials baked in. Use
EnvironmentFile=withchmod 600and our Hazina vault workflow. A Pi should never hold a Stripe secret key — it calls your backend, which talks to Stripe (default rail); the same applies to M-Pesa/Daraja on Kenya-targeted projects. - AI routing. On-device LLMs (Ollama / hailo-ollama) are the offline fallback and privacy-first pre-filter; complex reasoning and codegen route to Claude, structured output to GPT-4o, when online. Keep Ollama bound to localhost — it has no auth.
- Power, storage and heat are reliability. Official 27 W PSU for Pi 5, NVMe or A2 cards, active cooling; ship
vcgencmd get_throttled+ SoC temperature in telemetry (seeexamples/pi-health.mts). - Kenya-targeted / field deployments. Where a project's users are in Kenya, the same edge node pays off more: unstable mains (use a UPS HAT or solar + battery), heat and dust (enclosure + monitoring), and intermittent links (offline-first, sync on reconnect, low-bandwidth payloads — see
AFRICAN_MARKET_GUIDE.md). Set the Imager locale to Nairobi there; Connect and Tailscale both work behind carrier-grade NAT on mobile data. - Pi + Pico is the pattern. Don't fight the Linux scheduler for real-time pins — offload to a Pico/ESP32 over UART/MQTT and let the Pi do networking, storage, dashboards.
- Iterate with Claude Code over SSH, and unit-test pin logic with gpiozero's mock factory before it touches hardware.