Skip to the content
2 layers65.6 × 56.5 mmTop HAT Alt, the printed circuit board in 3D

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

5

README

README.md

train-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

  1. Install dependencies on the Raspberry Pi (pigpio, Flask, spidev, etc. — see imports at the top of the script)
  2. Ensure the pigpio daemon is running: sudo pigpiod
  3. Run the script: python3 integrated_train_controller_23_debug_boost_2.py
  4. 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
QtyValueFootprintReferences
2100 nFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC1, C5
24.7 kΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR1, R4
2MountingHoleMountingHole:MountingHole_3.2mm_M3H1, H2
10.1 µFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC7
10.2Ω 5WResistor_THT:R_Axial_Power_L25.0mm_W9.0mm_P30.48mmR6
11 µFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC3
11.2 kΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR2
1100 kΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR3
1100μFCapacitor_THT:CP_Radial_D8.0mm_P3.50mmC4
112V DC power inputMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ4
11N4004Diode_THT:D_DO-41_SOD81_P10.16mm_HorizontalD3
11N4744ADiode_THT:D_DO-41_SOD81_P10.16mm_HorizontalD1
122 ΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR5
1220μFCapacitor_THT:CP_Radial_D8.0mm_P3.50mmC2
1470 µFCapacitor_THT:CP_Radial_D8.0mm_P3.50mmC6
15VMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ1
15kΩPotentiometer_THT:Potentiometer_Runtron_RM-065_VerticalRV1
1BC337Package_TO_SOT_THT:TO-92_InlineQ1
1Conn_01x12Connector_PinHeader_2.54mm:PinHeader_2x06_P2.54mm_VerticalJ2
1IRF4905Package_TO_SOT_THT:TO-220-3_VerticalQ2
1Power TRACK A / BMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ5
1SANYOU_SRD_Form_CRelay_THT:Relay_SPDT_SANYOU_SRD_Series_Form_CK1
1SS34Diode_SMD:D_SMAD2
1TRACKMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ3
1TSR_1-2450Converter_DCDC:Converter_DCDC_TRACO_TSR-1_THTU1

More from PetervanderMeij/train-controller

1
  • 2 layers85.6 × 56.5 mmBottom HAT, the printed circuit board in 3D

    Bottom HAT

    PetervanderMeij/train-controller

    Raspberry Pi model train controller

    59 parts

Similar boards

  • 2 layers249.4 × 122 mmPCB Controller, the printed circuit board in 3D

    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 mmN3-universal, the printed circuit board in 3D

    N3-universal

    oliviera999/n3_firmwires

    firmwires des bojetw connectés n3

    179 parts
  • 2 layers150 × 120 mmHydrogelBioprinter, the printed circuit board in 3D

    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 mmQRPAmplifier, the printed circuit board in 3D

    QRPAmplifier

    profdc9/QRPAmplifier

    Layout of WA2EBY amplifier in Kicad, licensed CC-BY-SA 4.0

    133 parts26
  • 2 layers120 × 75 mmPCB FLM FTE-12V, the printed circuit board in 3D

    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 mmBle audio, the printed circuit board in 3D

    Ble audio

    lukasbarti/automotive-bluetooth-receiver

    44 parts
  • 2 layers64 × 64 mmCmd power, the printed circuit board in 3D

    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 mmZuendbox v3 32, the printed circuit board in 3D

    Zuendbox v3 32

    fixxl/el-fueradoro

    Open source ignition-system for audio-fireworks

    205 parts10

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.