This commit is contained in:
Aron Petau 2025-11-20 12:30:36 +01:00
parent d991a07583
commit 4648650f86
2 changed files with 97 additions and 40 deletions

131
WIRING.md
View file

@ -1,55 +1,110 @@
# Thermal Printer Wiring Guide for Raspberry Pi 4 # 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 Thermal Printer (58mm) Raspberry Pi 4
┌──────────────────┐ ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────┐
│ │ │ │ │ │ │ │
│ Red (VCC/5V) ├─────────────────────►│ Pin 4 (5V) │ ⚠️ May need external PSU │ VCC/5V ├──X───────────────────│ │ ❌ DO NOT connect to Pi
│ │ │ │ │ (Connect to │ │ │ │ (Use external 9V PSU)
│ Black (GND) ├─────────────────────►│ Pin 6 (GND) │ │ external PSU) │ │ │ │
│ │ │ │ │ │ │ │ │
│ Green (RX) ├─────────────────────►│ Pin 8 (GPIO14/TXD) │ Pi sends data │ GND ────────────┼──┼───────────────────┼─► Pin 6 (GND) │ Ground to Pi
│ │ │ │ │ (Black/Blue) │ │ │ │
│ Yellow (TX) ├─────────────────────►│ Pin 10 (GPIO15/RXD) │ Pi receives (optional) │ │ │ │ │
│ │ │ │ │ RX ─────────────┼──┼───────────────────┼─► Pin 8 (GPIO14/TX) │ Printer receives from Pi
│ Yellow/Green ├─────────────────────►│ Pin 6 (GND) │ Shield/extra ground │ (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) External 9V PSU (+) ──► Printer VCC/5V pin
┌─────────────────────────────────────────┐ External 9V PSU (-) ──► Printer GND pin
│ 3V3 [ 1] [ 2] 5V ← Connect Red here (or use external PSU) └─► Raspberry Pi Pin 6 (GND) - MUST share common ground!
│ 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)
└─────────────────────────────────────────┘
``` ```
## Quick Connection Summary ### 2. Data Connections (Pi ↔ Printer)
| Printer Wire | Pi Pin Number | Pi Pin Name | Function | ```
|-------------|---------------|-------------|----------| Raspberry Pi Pin 8 (GPIO14 TX) ──► Printer RX pin
| **Red** | **4** | 5V Power | Power supply (⚠️ high current) | Raspberry Pi Pin 10 (GPIO15 RX) ──► Printer TX pin (optional, can skip)
| **Black** | **6** | Ground | Common ground | ```
| **Green** | **8** | GPIO 14 (TXD) | Serial transmit (Pi → Printer) |
| **Yellow** | **10** | GPIO 15 (RXD) | Serial receive (Printer → Pi, optional) | ## Raspberry Pi GPIO Pinout (Top View)
| **Yellow/Green** | **6** | Ground | Shield/secondary ground |
```
┌─────────────────────────┐
│ 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 ## Testing Steps

View file

@ -22,6 +22,8 @@ app.mount("/out", StaticFiles(directory="out"), name="out")
TASKS_FILE = Path("data/tasks.json") TASKS_FILE = Path("data/tasks.json")
ENABLE_PHYSICAL_PRINTER = True # Set to False to skip physical printing (only generate preview images) 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 = Path("out")
OUT_DIR.mkdir(exist_ok=True) OUT_DIR.mkdir(exist_ok=True)
CARD_WIDTH_PX = 354 # 58mm * 300dpi / 25.4 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 # Print to physical printer if enabled
if ENABLE_PHYSICAL_PRINTER: 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: 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.text(f"Task: {task.content}\nVon: {task.user}\nPriorität: {task.priority}\n")
printer.cut() printer.cut()
print(f"[DEBUG] Print command sent successfully") print(f"[DEBUG] Print command sent successfully")