From f51f204a9deb96fcab959aa5fe159af6bbced1b3 Mon Sep 17 00:00:00 2001 From: trav Date: Wed, 22 Jul 2026 15:57:26 -0400 Subject: [PATCH] raspi --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ photobooth.py | 5 +++ 2 files changed, 105 insertions(+) diff --git a/README.md b/README.md index c865986..69927e6 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,106 @@ that machine: put `HandleLidSwitch=ignore` in `/etc/systemd/logind.conf.d/photobooth.conf` (needs root, applies even when the booth is not running) or use the desktop's own power settings. +## Running on a Raspberry Pi (no desktop) + +The booth needs no desktop environment. On a console-only machine (no X +or Wayland session) it automatically tells SDL to draw straight to the +screen via the KMS/DRM driver, so it runs fine on Raspberry Pi OS Lite. + +1. **Install Raspberry Pi OS Lite (64-bit)** and boot with the screen, + camera, and mouse plugged in. + +2. **Install the system packages:** + + ```bash + sudo apt install python3-venv cups fonts-dejavu-core + ``` + + (`fonts-dejavu-core` is for the contact-sheet footer text — Lite + doesn't ship it and the fallback font is tiny.) + +3. **Create a virtual environment and install the dependencies:** + + ```bash + python3 -m venv ~/photobooth-venv + ~/photobooth-venv/bin/pip install pygame-ce opencv-python-headless pillow + ``` + + Note the **headless** OpenCV build: the regular `opencv-python` wheel + needs X libraries that Lite doesn't have, and the booth uses no GUI + features. If the pygame-ce wheel's SDL lacks the KMS/DRM driver + (`pygame.error: kmsdrm not available`), use the distro build instead + (`sudo apt install python3-pygame`) — the booth uses nothing + pygame-ce-specific. + +4. **Give your user access to the screen and input devices:** + + ```bash + sudo usermod -aG video,render,input $USER # then log out and back in + ``` + +5. **Check which screen modes are available.** The Pi can only use modes + the display (or HDMI adapter) advertises: + + ```bash + cat /sys/class/drm/card*-HDMI-A-*/modes + ``` + + If 800x600 isn't listed, set `[display]` width/height in `config.toml` + to one of the listed modes. For a 4:3 CRT behind an HDMI-to-coax + adapter, 720x480 fills the screen correctly (same trick as DVDs). + Everything scales to `[display]` automatically — no code changes + needed. + +6. **Set up the printer** with CUPS from the command line: + + ```bash + lpinfo -v # find the printer's URI (USB printers: usb://...) + lpinfo -m # list available drivers + sudo lpadmin -p PRINTER -E -v -m + lpoptions -d PRINTER + lpstat -p -d # verify + ``` + + Then set `printer = "PRINTER"` in `config.toml` to match. + +7. **Run it** from the console: + + ```bash + ~/photobooth-venv/bin/python photobooth.py + ``` + +### Starting automatically at boot + +Create `/etc/systemd/system/photobooth.service` (adjust the user and +paths to match your setup): + +```ini +[Unit] +Description=CRT Photobooth + +[Service] +User=pi +SupplementaryGroups=video render input +WorkingDirectory=/home/pi/nissaphotobooth +ExecStart=/home/pi/photobooth-venv/bin/python photobooth.py +Restart=on-failure + +[Install] +WantedBy=multi-user.target +``` + +Then: + +```bash +sudo systemctl enable --now photobooth +``` + +Quit with Esc/Q on a keyboard, or `sudo systemctl stop photobooth` over +SSH. The keep-awake locks work the same as on a laptop (a Pi rarely +sleeps anyway). The `auto-macally` camera lookup already waits ~15 +seconds for USB devices to enumerate, so no boot-order tweaks are needed. + ## Customizing - **All settings** live in `config.toml` — camera choice, screen text, diff --git a/photobooth.py b/photobooth.py index 97b563b..7831dba 100644 --- a/photobooth.py +++ b/photobooth.py @@ -22,6 +22,11 @@ import time import tomllib from pathlib import Path +# On a console-only machine (no X or Wayland session), tell SDL to draw +# straight to the screen via KMS/DRM, so no desktop environment is needed. +if not os.environ.get("DISPLAY") and not os.environ.get("WAYLAND_DISPLAY"): + os.environ.setdefault("SDL_VIDEODRIVER", "kmsdrm") + import pygame import camera as cam