

Top HAT Alt
Raspberry Pi model train controller
- Size
- 65.6 × 56.5 mm
- Copper layers
- 2
- Thickness
- 1.6 mm
- Parts
- 28
- Nets
- 14
- Pads
- 71
- Tracks, vias
- 158, 0
- Routed
- Yes
- KiCad
- KiCad 9.0 (file 20241229)
- Created
- 5 Jul 2026
- Updated
- 9 Jul 2026
Overview
Top HAT Alt is an open-source printed circuit board by PetervanderMeij, from the PetervanderMeij/train-controller repository on GitHub. It is a 2-layer board of 65.6 × 56.5 mm with 28 parts on 14 nets, routed with 158 tracks and 0 vias.
It is built around the TSR 1-2450, 1N4744A and BC337, with the IRF4905 and SS34 among its other parts. Its parts include 7 capacitors, 6 resistors, 5 connectors, 3 diodes and 2 transistors.
Main components
5TSR 1-2450
SIP,11.6x7.5mm-40℃~+85℃ 10.2mm 11.6mm 1A 2200uF 300uA 50mVp-p 5V 7.5mm 7V~36V 850kHz 94% Short Circuit Protection、Automatic fault recovery ±1% SIP,11.6x7.5mm DC-DC Power Modules ROHSYLPTECDC-DC Power Modules1N4744A
DO-41GZener DiodesLGEBC337
TO-92-31 NPN 100 100MHz 100nA 45V 5V 625mW 700mV 800mA NPN TO-92-3 Bipolar (BJT) ROHSFoshan Blue Rocket ElecBipolar (BJT)IRF4905
TO-220-35℃~+175℃ 1 P-Channel 12nF 150nC@10V 1nF 2.5V 200W 450pF 60V 75A 9mΩ P-Channel TO-220 MOSFETs ROHSCmosMOSFETsSS34
SMA(DO-214AC)-55℃~+125℃ 3A 40V 500uA@40V 550mV@3A Independent SMA(DO-214AC) Schottky Diodes ROHSMDDSchottky Diodes
README
README.mdtrain-controller
A Raspberry Pi–based model train controller. Automatically runs a train between two platforms, handling acceleration/deceleration, platform stopping, track switching, and safety cutoffs — with a web dashboard for monitoring and manual control.
Hardware
- Raspberry Pi 2B
- Two custom PCBs for level-shifting and motor drive:
- Bottom Hat: 3.3V → 5V level shifting (BC337 transistors), with a hardware SR-latch overcurrent safety circuit
- Top Hat: 5V → 12V level shifting into an IRF4905 P-channel MOSFET, driving the motor directly
- Sensors for slow-zone detection and platform stop detection (Platform A / B)
- A stepper-driven (or relay-driven) track switch between the two platforms
- MCP3008 ADC for current monitoring (via SPI)
- QR code scanner for per-train identification
Software Overview
The controller runs as a single Python script, integrated_train_controller_23_debug_boost_2.py, using pigpio for hardware PWM. Key behaviors:
- Automatic operation loop: accelerate → run at full speed → slow on approach → stop at platform → switch track → repeat
- Per-train speed profiles stored in a local SQLite database (
trains.db), selected via QR code scan - Emergency stop and graceful shutdown, both with double-press detection to avoid accidental triggers
- A Flask web dashboard (served directly from the script, no separate template files) for live status, speed control, and emergency stop
See TRAIN_CONTROLLER_DOCUMENTATION.md for full details on constants, GPIO wiring, and the operational workflow.
New to Git? See GIT_WORKFLOW_GUIDE.md for the commands and workflow used to maintain this repository.
Running It
- Install dependencies on the Raspberry Pi (
pigpio,Flask,spidev, etc. — see imports at the top of the script) - Ensure the
pigpiodaemon is running:sudo pigpiod - Run the script:
python3 integrated_train_controller_23_debug_boost_2.py - Open the dashboard in a browser on the same network:
http://<pi-ip-address>:5000
Status
Actively developed and bench-tested incrementally. Current focus: validating max_slow_speed against the motor's conduction threshold on the rebuilt two-PCB hardware.
Parts
28| Qty | Value | Footprint | References |
|---|---|---|---|
| 2 | 100 nF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C1, C5 |
| 2 | 4.7 kΩ | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R1, R4 |
| 2 | MountingHole | MountingHole:MountingHole_3.2mm_M3 | H1, H2 |
| 1 | 0.1 µF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C7 |
| 1 | 0.2Ω 5W | Resistor_THT:R_Axial_Power_L25.0mm_W9.0mm_P30.48mm | R6 |
| 1 | 1 µF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C3 |
| 1 | 1.2 kΩ | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R2 |
| 1 | 100 kΩ | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R3 |
| 1 | 100μF | Capacitor_THT:CP_Radial_D8.0mm_P3.50mm | C4 |
| 1 | 12V DC power input | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J4 |
| 1 | 1N4004 | Diode_THT:D_DO-41_SOD81_P10.16mm_Horizontal | D3 |
| 1 | 1N4744A | Diode_THT:D_DO-41_SOD81_P10.16mm_Horizontal | D1 |
| 1 | 22 Ω | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R5 |
| 1 | 220μF | Capacitor_THT:CP_Radial_D8.0mm_P3.50mm | C2 |
| 1 | 470 µF | Capacitor_THT:CP_Radial_D8.0mm_P3.50mm | C6 |
| 1 | 5V | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J1 |
| 1 | 5kΩ | Potentiometer_THT:Potentiometer_Runtron_RM-065_Vertical | RV1 |
| 1 | BC337 | Package_TO_SOT_THT:TO-92_Inline | Q1 |
| 1 | Conn_01x12 | Connector_PinHeader_2.54mm:PinHeader_2x06_P2.54mm_Vertical | J2 |
| 1 | IRF4905 | Package_TO_SOT_THT:TO-220-3_Vertical | Q2 |
| 1 | Power TRACK A / B | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J5 |
| 1 | SANYOU_SRD_Form_C | Relay_THT:Relay_SPDT_SANYOU_SRD_Series_Form_C | K1 |
| 1 | SS34 | Diode_SMD:D_SMA | D2 |
| 1 | TRACK | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J3 |
| 1 | TSR_1-2450 | Converter_DCDC:Converter_DCDC_TRACO_TSR-1_THT | U1 |
More from PetervanderMeij/train-controller
1- 2 layers85.6 × 56.5 mm

Similar boards
- 2 layers249.4 × 122 mm

PCB Controller
Sutthiphong-H/project-flip-disc
FlipDisc Project was made for education of Project. Chadsadakorn Piriyasiriphan Jadesalit Suriyanimitsuk Sutthiphong Hongkham
159 parts - 2 layers278 × 135 mm

- 2 layers150 × 120 mm

HydrogelBioprinter
SimonDaniel605/Hydrogel-3D-Printer
Development of a custom hydrogel 3D printer for tissue engineering and research applications for Stellenbosch University.
174 partsMIT - 2 layers100 × 100 mm

QRPAmplifier
profdc9/QRPAmplifier
Layout of WA2EBY amplifier in Kicad, licensed CC-BY-SA 4.0
133 parts26 - 2 layers120 × 75 mm

PCB FLM FTE-12V
EngLuizs/Fonte_Linear_12V
Fonte linear regulada ajustável (12V/1A) com telemetria digital integrada. Desenvolvida com ESP32, KiCad e PlatformIO para monitoramento local (LCD) e remoto (Web Server Wi-Fi).
55 parts1MIT - 2 layers85 × 90 mm

- 2 layers64 × 64 mm

Cmd power
bpmine/minou_uino
Les programmes de cette base gèrent la cabane de notre minou (voir images suivantes).
38 parts - 2 layers213.6 × 127.5 mm

Questions
How big is the Top HAT Alt PCB?
It measures 65.6 × 56.5 mm and has 2 copper layers, 1.6 mm thick.
What parts does the Top HAT Alt use?
28 parts, built around the TSR 1-2450, 1N4744A, BC337 and IRF4905. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
Where can I download the Top HAT Alt KiCad files?
From the PetervanderMeij/train-controller repository on GitHub, at the commit this page was made from: the board is kicad/top-hat/Top HAT Alt.kicad_pcb and its schematic kicad/bottom-hat/Bottom HAT.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Can I use the Top HAT Alt design in my own project?
Its repository states no licence, so its author keeps all rights: ask PetervanderMeij before reusing the design.