From 4648650f8665c5a4bd2ce6eae6aeed845f91a0d2 Mon Sep 17 00:00:00 2001 From: Aron Date: Thu, 20 Nov 2025 12:30:36 +0100 Subject: [PATCH] upd --- WIRING.md | 131 +++++++++++++++++++++++++++++++++++++--------------- app/main.py | 6 ++- 2 files changed, 97 insertions(+), 40 deletions(-) diff --git a/WIRING.md b/WIRING.md index 57e0471..c02e8f0 100644 --- a/WIRING.md +++ b/WIRING.md @@ -1,55 +1,110 @@ # Thermal Printer Wiring Guide for Raspberry Pi 4 -## Connection Diagram +## ⚠️ CRITICAL: Printer RX ↔ Pi TX, Printer TX ↔ Pi RX (CROSSED!) + +## Correct Connection Diagram ``` Thermal Printer (58mm) Raspberry Pi 4 ┌──────────────────┐ ┌─────────────────────┐ │ │ │ │ -│ Red (VCC/5V) ├─────────────────────►│ Pin 4 (5V) │ ⚠️ May need external PSU -│ │ │ │ -│ Black (GND) ├─────────────────────►│ Pin 6 (GND) │ -│ │ │ │ -│ Green (RX) ├─────────────────────►│ Pin 8 (GPIO14/TXD) │ Pi sends data -│ │ │ │ -│ Yellow (TX) ├─────────────────────►│ Pin 10 (GPIO15/RXD) │ Pi receives (optional) -│ │ │ │ -│ Yellow/Green ├─────────────────────►│ Pin 6 (GND) │ Shield/extra ground -│ │ │ │ -└──────────────────┘ └─────────────────────┘ +│ VCC/5V ├──X───────────────────│ │ ❌ DO NOT connect to Pi +│ (Connect to │ │ │ │ (Use external 9V PSU) +│ external PSU) │ │ │ │ +│ │ │ │ │ +│ GND ────────────┼──┼───────────────────┼─► Pin 6 (GND) │ Ground to Pi +│ (Black/Blue) │ │ │ │ +│ │ │ │ │ +│ RX ─────────────┼──┼───────────────────┼─► Pin 8 (GPIO14/TX) │ Printer receives from Pi +│ (Yellow/Green) │ │ │ │ +│ │ │ │ │ +│ TX ─────────────┼──┼───────────────────┼─► Pin 10 (GPIO15/RX)│ Printer sends to Pi +│ (White/Green) │ │ │ │ (optional) +│ │ │ │ │ +└──────────────────┘ │ └─────────────────────┘ + │ + └─► External 9V PSU GND (also connect to Pi GND) + + +External 9V Power Supply +┌──────────────────┐ +│ 9V PSU │ +│ (+) ────────────┼─► Printer VCC/5V +│ (-) ────────────┼─► Printer GND + Pi Pin 6 (GND) - COMMON GROUND! +└──────────────────┘ ``` -## Pin Layout (GPIO Header View) +## Step-by-Step Wiring Instructions + +### 1. Power Connections (External PSU) ``` -Raspberry Pi 4 GPIO Header (looking down at the board) -┌─────────────────────────────────────────┐ -│ 3V3 [ 1] [ 2] 5V ← Connect Red here (or use external PSU) -│ GPIO2 [ 3] [ 4] 5V -│ GPIO3 [ 5] [ 6] GND ← Connect Black + Yellow/Green here -│ GPIO4 [ 7] [ 8] GPIO14 (TXD) ← Connect Green here -│ GND [ 9] [10] GPIO15 (RXD) ← Connect Yellow here -│GPIO17 [11] [12] GPIO18 -│GPIO27 [13] [14] GND -│GPIO22 [15] [16] GPIO23 -│ 3V3 [17] [18] GPIO24 -│GPIO10 [19] [20] GND -│ GPIO9 [21] [22] GPIO25 -│GPIO11 [23] [24] GPIO8 -│ GND [25] [26] GPIO7 -│ ... (pins 27-40 not shown) -└─────────────────────────────────────────┘ +External 9V PSU (+) ──► Printer VCC/5V pin +External 9V PSU (-) ──► Printer GND pin + └─► Raspberry Pi Pin 6 (GND) - MUST share common ground! ``` -## Quick Connection Summary +### 2. Data Connections (Pi ↔ Printer) -| Printer Wire | Pi Pin Number | Pi Pin Name | Function | -|-------------|---------------|-------------|----------| -| **Red** | **4** | 5V Power | Power supply (⚠️ high current) | -| **Black** | **6** | Ground | Common ground | -| **Green** | **8** | GPIO 14 (TXD) | Serial transmit (Pi → Printer) | -| **Yellow** | **10** | GPIO 15 (RXD) | Serial receive (Printer → Pi, optional) | -| **Yellow/Green** | **6** | Ground | Shield/secondary ground | +``` +Raspberry Pi Pin 8 (GPIO14 TX) ──► Printer RX pin +Raspberry Pi Pin 10 (GPIO15 RX) ──► Printer TX pin (optional, can skip) +``` + +## Raspberry Pi GPIO Pinout (Top View) + +``` + ┌─────────────────────────┐ + │ USB USB Ethernet │ + │ ┌┐ ┌┐ ┌───┐ │ + └──┘└───┘└──────────┘ └─┘ + +GPIO Header (40 pins) +┌────────────────────────┐ +│ 3V3 [●1] [2●] 5V │ ❌ Don't use for printer power +│ [●3] [4●] 5V │ +│ [●5] [6●] GND │ ◄── Connect Printer GND + PSU GND HERE +│ [●7] [8●] TX │ ◄── Connect Printer RX HERE (GPIO14) +│ GND [●9] [10●] RX │ ◄── Connect Printer TX HERE (GPIO15) - optional +│ [11] [12] │ +│ [13] [14] GND │ +│ [15] [16] │ +│ 3V3 [17] [18] │ +│ [19] [20] GND │ +└────────────────────────┘ +``` + +## Wire Connection Table + +| What to Connect | Where It Goes | Pi Pin # | Notes | +|----------------|---------------|----------|-------| +| **Printer GND** | Pi Pin 6 (GND) | **6** | Black/Blue wire | +| **PSU GND (-)** | Pi Pin 6 (GND) | **6** | Share with printer GND | +| **Printer RX** | Pi Pin 8 (TX/GPIO14) | **8** | Yellow/Green wire - DATA OUT | +| **Printer TX** | Pi Pin 10 (RX/GPIO15) | **10** | White/Green wire - optional | +| **Printer VCC** | External PSU (+) | **N/A** | Red wire - NOT to Pi! | +| **PSU (+)** | Printer VCC | **N/A** | 9V power supply positive | + +## Visual Reminder: TX ↔ RX Crossover + +``` +Raspberry Pi Wire Thermal Printer +┌──────────┐ ┌──────────────┐ +│ │ │ │ +│ TX ────┼───────────────────────┼──► RX │ Pi talks → Printer listens +│ (Pin 8) │ │ │ +│ │ │ │ +│ RX ◄───┼───────────────────────┼──── TX │ Printer talks → Pi listens +│ (Pin 10) │ │ │ (optional) +│ │ │ │ +│ GND ───┼───────────────────────┼──── GND │ Common ground +│ (Pin 6) │ └────────────────┼──── PSU (-) │ All grounds together! +│ │ │ │ +└──────────┘ └──────────────┘ + │ + ├──── VCC ◄─── PSU (+) + │ +``` ## Testing Steps diff --git a/app/main.py b/app/main.py index e471f99..a3391f9 100644 --- a/app/main.py +++ b/app/main.py @@ -22,6 +22,8 @@ app.mount("/out", StaticFiles(directory="out"), name="out") TASKS_FILE = Path("data/tasks.json") ENABLE_PHYSICAL_PRINTER = True # Set to False to skip physical printing (only generate preview images) +PRINTER_DEVICE = "/dev/serial0" # Serial device path +PRINTER_BAUDRATE = 19200 # Try 9600 if printer doesn't respond OUT_DIR = Path("out") OUT_DIR.mkdir(exist_ok=True) CARD_WIDTH_PX = 354 # 58mm * 300dpi / 25.4 @@ -238,9 +240,9 @@ def print_task(request: Request, task_id: str): # Print to physical printer if enabled if ENABLE_PHYSICAL_PRINTER: - print(f"[DEBUG] Attempting to print to /dev/serial0...") + print(f"[DEBUG] Attempting to print to {PRINTER_DEVICE} at {PRINTER_BAUDRATE} baud...") try: - printer = escpos.printer.Serial(devfile="/dev/serial0", baudrate=19200, timeout=1) + printer = escpos.printer.Serial(devfile=PRINTER_DEVICE, baudrate=PRINTER_BAUDRATE, timeout=1) printer.text(f"Task: {task.content}\nVon: {task.user}\nPriorität: {task.priority}\n") printer.cut() print(f"[DEBUG] Print command sent successfully")