Skip to the content
PCBKitNew board
2 layers85.6 × 56.5 mmBottom HAT, the printed circuit board in 3D

Raspberry Pi model train controller

Size
85.6 × 56.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
59
Nets
59
Pads
201
Tracks, vias
500, 3
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
5 Jul 2026
Updated
9 Jul 2026

Overview

Bottom HAT is an open-source printed circuit board by PetervanderMeij, from the PetervanderMeij/train-controller repository on GitHub. It is a 2-layer board of 85.6 × 56.5 mm with 59 parts on 59 nets, routed with 500 tracks and 3 vias.

It is built around the MCP3008-I/P, LTV-847 and BC337. Its parts include 30 resistors, 10 transistors, 7 connectors, 6 diodes and 2 ICs.

Main components

3

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

59
QtyValueFootprintReferences
1910kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR1, R2, R3, R4, R10, R11, R13, R15, R16, R20, R21, R23, R25, R26, R28, R29 +3
10BC337Package_TO_SOT_THT:TO-92_InlineQ1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10
61N6857Diode_THT:D_DO-35_SOD27_P7.62mm_HorizontalD1, D2, D3, D4, D5, D6
41kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR18, R24, R27, R30
31.5kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR5, R6, R19
21kΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR12, R17
2MountingHoleMountingHole:MountingHole_3.2mm_M3H1, H2
1150Ω/85ΩResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR14
16.8kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR22
1A/BMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ2
1Alt.+5V Supply to RPiMy_custom_library1:Jumper_P10mmJP1
1Conn_01x12Connector_PinHeader_2.54mm:PinHeader_2x06_P2.54mm_VerticalJ7
1IRDOTsMy_custom_library1:TerminalBlock_KF128_1x08_P2.54mm_HorizontalJ1
1LTV-847Package_DIP:DIP-16_W7.62mmU1
1MCP3008My_custom_library1:PDIP16_300MC_MCHU2
1P5 Pi GPIO 030 pin 5TestPoint:TestPoint_Loop_D2.50mm_Drill1.0mm_LowProfileSP1
1PBSMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ4
1PBS LEDMy_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_HorizontalJ5
1Phone Jack for Setup PotmeterMy_custom_library1:Jack_3.5mm_PJ-307_Horizontal_not cliptJ6
1Raspberry_Pi_B_2Connector_PinHeader_2.54mm:PinHeader_2x13_P2.54mm_VerticalJ3

Questions

How big is the Bottom HAT PCB?

It measures 85.6 × 56.5 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Bottom HAT use?

59 parts, built around the MCP3008-I/P, LTV-847 and BC337. 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 Bottom HAT KiCad files?

From the PetervanderMeij/train-controller repository on GitHub, at the commit this page was made from: the board is kicad/bottom-hat/Bottom HAT.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 Bottom HAT design in my own project?

Its repository states no licence, so its author keeps all rights: ask PetervanderMeij before reusing the design.

More from PetervanderMeij/train-controller

1
  • 2 layers65.6 × 56.5 mmTop HAT Alt, the printed circuit board in 3D

    Top HAT Alt

    PetervanderMeij/train-controller

    Raspberry Pi model train controller

    28 parts

Similar boards

  • 2 layers160 × 100 mmMPCNC Nano Estlcam Shield, the printed circuit board in 3D

    MPCNC Nano Estlcam Shield

    tnn85/MPCNC-Nano-Estlcam-Shield

    Ein CNC Shield für die MPCNC in Verwendung mit Estlcam

    96 parts70
  • 2 layers83.8 × 120.7 mmAtu100wifi, the printed circuit board in 3D

    Atu100wifi

    ftl/atu100wifi

    A wifi adapter device for David Fainitski's ATU-100 antenna tuner (https://github.com/Dfinitski/N7DDC-ATU-100-mini-and-extended-boards)

    31 parts28MIT
  • 2 layers63 × 80 mmBrakeOutBoard, the printed circuit board in 3D

    BrakeOutBoard

    gmoccapy/T4-MFA

    This is a color MFA designed to be used in a Volkswagen T4 Van

    65 parts9
  • 2 layers155 × 108 mmOpenPlc Rpi, the printed circuit board in 3D

    OpenPlc Rpi

    FOSSEE/openplc_v2

    115 parts5MIT
  • 2 layers320 × 81.3 mmDisplay and controls board, the printed circuit board in 3D

    Display and controls board

    411568/Atmega8_FM_radio

    Simple FM radio based on Atmega8 and TEA5767 module

    103 parts3MIT
  • 4 layers157.5 × 130 mmJv thesis, the printed circuit board in 3D

    Jv thesis

    JhonVelasquez/Embedded_system_Synchronize_Plant

    Project of a embedded system that synchronizes signals in a plant. There is electronic (PCB) and software design (FreeRTOS for STM32F7).

    233 parts2
  • 2 layers228.6 × 152.4 mmMainPCB, the printed circuit board in 3D

    MainPCB

    0x9ONU/BOREALIS

    71 parts1