Prints a random Magic: The Gathering creature by mana value on a thermal printer. This is designed for Momir Basic style play in paper, where you get random creatures of different mana values as your only spells.
This tool:
- Queries Scryfall for a random creature card by mana value.
- Renders a receipt-style image with the art and rules text.
- Prints to ESC/POS thermal printers over USB or network, or saves a PNG for testing.
See the Momir Basic rules here: https://magic.wizards.com/en/formats/momir-basic
- Python 3.9+
- A USB or network ESC/POS thermal printer (58mm or 80mm)
Install Python 3.9+ using one of these options:
- Microsoft Store (simple, auto-updates)
- python.org installer (check "Add Python to PATH")
Verify:
python --version
pip --versionA virtual environment keeps this app's dependencies isolated from other Python projects on your machine.
cd scryfall-thermal
python -m venv .venvActivate it:
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation, run one of these and try again:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedor for this session only:
Set-ExecutionPolicy -Scope Process Bypasspip install -U pip
pip install -e .scryfall-thermal --mv 3 --dry-run --output output.pngUSB format: usb:0x1234:0xabcd[?intf=0&out=0x02&in=0x81]
Network format: net:192.168.1.50:9100
Example:
scryfall-thermal --mv 2 --printer usb:0x04b8:0x0202If your printer needs explicit USB endpoints (common on some models):
scryfall-thermal --mv 2 --printer usb:0x0525:0xa4a7?intf=0&out=0x02&in=0x81The steps below assume Raspberry Pi OS Lite (no desktop) and SSH access.
sudo apt update
sudo apt upgrade -ysudo apt install -y python3 python3-venv python3-pipIf you are using the Scryfall symbol cache, CairoSVG requires extra system packages:
sudo apt install -y libcairo2 libffi-dev libgdk-pixbuf2.0-0 libpango-1.0-0 libpangocairo-1.0-0git clone <YOUR_REPO_URL>
cd scryfall-thermal
python3 -m venv .venv
source .venv/bin/activatepip install -U pip
pip install -e .scryfall-thermal --mv 3 --dry-run --output output.pngUSB format: usb:0x1234:0xabcd[?intf=0&out=0x02&in=0x81]
Network format: net:192.168.1.50:9100
Example:
scryfall-thermal --mv 2 --printer net:192.168.1.50:9100If your printer needs explicit USB endpoints (common on some models):
scryfall-thermal --mv 2 --printer usb:0x0525:0xa4a7?intf=0&out=0x02&in=0x81Use a rotary encoder and a 2-digit 7-segment display (common cathode) to select mana value and trigger printing.
Default GPIO mapping (BCM numbering):
-
Encoder A/CLK: GPIO17
-
Encoder B/DT: GPIO18
-
Encoder SW: GPIO27
-
Segments 3,9,8,6,7,4,1,2: GPIO5, GPIO6, GPIO13, GPIO19, GPIO26, GPIO12, GPIO16, GPIO20
-
Digit commons 10,5: GPIO21, GPIO25 Wiring notes:
-
The encoder A/B/SW lines should use pull-ups (gpiozero defaults to pull-ups).
-
Use 220-330 ohm resistors for each segment line.
-
Because this is a bare 2-digit display, you must multiplex the digits.
-
Use NPN transistors (e.g., 2N2222) to switch each digit common cathode.
-
TIP120 option: emitter to GND, collector to digit common, base to GPIO through ~1k resistor (Darlington NPN low-side switch).
GPIO backend (gpiozero + lgpio):
Newer Raspberry Pi OS versions disable the legacy /sys/class/gpio interface. Use gpiozero with the lgpio backend.
sudo apt install -y python3-gpiozero python3-lgpioRun once to test:
GPIOZERO_PIN_FACTORY=lgpio scryfall-thermal --hardware --dry-run --output output.pngRun in hardware mode:
scryfall-thermal --hardware --dry-run --output output.pngIf you have a printer later:
scryfall-thermal --hardware --printer usb:0x1234:0xabcdOverride pins if needed:
scryfall-thermal --hardware --seg-pins 5,6,13,19,26,12,16,20 --digit-pins 21,25Create a systemd unit file at /etc/systemd/system/scryfall-thermal.service:
[Unit]
Description=Scryfall Thermal Hardware UI
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=colefin8
WorkingDirectory=/home/colefin8/scryfall-thermal
ExecStart=/home/colefin8/scryfall-thermal/.venv/bin/scryfall-thermal --hardware --dry-run --output /home/colefin8/output.png
Environment=GPIOZERO_PIN_FACTORY=lgpio
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl daemon-reload
sudo systemctl enable --now scryfall-thermalCheck status/logs:
systemctl status scryfall-thermal
journalctl -u scryfall-thermal -b- Default render width is 384px (58mm printers). Use
--width 576for 80mm printers. - If the printer is not connected, use
--dry-runto validate output. - A symbology snapshot is bundled at
src/scryfall_thermal/assets/symbology.jsonso new clones do not need to fetch the symbol list. PNGs are still downloaded on first use and cached locally. SetSCRYFALL_SYMBOLS_DIRto override the cache directory. - Refresh the snapshot with:
curl -L https://api.scryfall.com/symbology -o src/scryfall_thermal/assets/symbology.json - Windows:
cairosvgneeds the Cairo DLLs (for example, install MSYS2 andpacman -S mingw-w64-x86_64-cairo, then add the MSYS2bintoPATH). Ensurecairo-2.dllis discoverable before running.