

Bottom HAT
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
3MCP3008-I/P
PDIP-16-40℃~+85℃ 1.35MHz~3.6MHz 10 1LSB 2.7V~5.5V 200kHz 5nA 61dB 8 Multiplexers SAR SPI Yes PDIP-16 Analog to Digital Converters (ADC) ROHSMicrochip TechnologyAnalog To Digital Converters (ADC)LTV-847
DIP-16-30℃~+110℃ 1.2V 100mV@20mA,1mA 200mW 35V 3us 4 4us 50% 50mA 50mA 5kV 600% 6V DC Phototransistor DIP-16 Transistor, Photovoltaic Output Optoisolators ROHSLite-OnTransistor, Photovoltaic Output OptoisolatorsBC337
TO-92-31 NPN 100 100MHz 100nA 45V 5V 625mW 700mV 800mA NPN TO-92-3 Bipolar (BJT) ROHSFoshan Blue Rocket ElecBipolar (BJT)
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
59| Qty | Value | Footprint | References |
|---|---|---|---|
| 19 | 10k | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R1, R2, R3, R4, R10, R11, R13, R15, R16, R20, R21, R23, R25, R26, R28, R29 +3 |
| 10 | BC337 | Package_TO_SOT_THT:TO-92_Inline | Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10 |
| 6 | 1N6857 | Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal | D1, D2, D3, D4, D5, D6 |
| 4 | 1k | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R18, R24, R27, R30 |
| 3 | 1.5k | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R5, R6, R19 |
| 2 | 1kΩ | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R12, R17 |
| 2 | MountingHole | MountingHole:MountingHole_3.2mm_M3 | H1, H2 |
| 1 | 150Ω/85Ω | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R14 |
| 1 | 6.8k | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R22 |
| 1 | A/B | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J2 |
| 1 | Alt.+5V Supply to RPi | My_custom_library1:Jumper_P10mm | JP1 |
| 1 | Conn_01x12 | Connector_PinHeader_2.54mm:PinHeader_2x06_P2.54mm_Vertical | J7 |
| 1 | IRDOTs | My_custom_library1:TerminalBlock_KF128_1x08_P2.54mm_Horizontal | J1 |
| 1 | LTV-847 | Package_DIP:DIP-16_W7.62mm | U1 |
| 1 | MCP3008 | My_custom_library1:PDIP16_300MC_MCH | U2 |
| 1 | P5 Pi GPIO 030 pin 5 | TestPoint:TestPoint_Loop_D2.50mm_Drill1.0mm_LowProfile | SP1 |
| 1 | PBS | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J4 |
| 1 | PBS LED | My_custom_library1:TerminalBlock_KF128_1x02_P2.54mm_Horizontal | J5 |
| 1 | Phone Jack for Setup Potmeter | My_custom_library1:Jack_3.5mm_PJ-307_Horizontal_not clipt | J6 |
| 1 | Raspberry_Pi_B_2 | Connector_PinHeader_2.54mm:PinHeader_2x13_P2.54mm_Vertical | J3 |
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 mm

Similar boards
- 2 layers118.1 × 67.3 mm

FunctiongeneratorMK3PowerControl
pstimpel/waveformgenerator
A waveform generator based on XR2206 and Arduino
42 parts14 - 2 layers160 × 100 mm

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 mm

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 mm

- 2 layers155 × 108 mm

- 2 layers320 × 81.3 mm

Display and controls board
411568/Atmega8_FM_radio
Simple FM radio based on Atmega8 and TEA5767 module
103 parts3MIT - 4 layers157.5 × 130 mm

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 mm
