Skip to the content
2 layersControllerTHT, the printed circuit board in 3D

Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

Copper layers
2
Thickness
1.6 mm
Parts
71
Nets
55
Pads
325
Tracks, vias
169, 6
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
30 Dec 2018
Updated
5 Nov 2026

Overview

ControllerTHT is an open-source printed circuit board by deltaphi, from the deltaphi/RR32CanController repository on GitHub, published under the GPL-3.0 licence. It is a 2-layer board with 71 parts on 55 nets, routed with 169 tracks and 6 vias.

It is built around the 74LS367PC, CH340C and ESP32-WROOM-32, with the TJA1051T and BC547 among its other parts. Its parts include 22 resistors, 15 capacitors, 9 switches, 8 connectors and 6 ICs. It belongs with the interfaces and adapters boards and the ESP32 boards of this library.

Main components

5

README

README.md

RR32CanSwitchboard

Sketch for a Switchboard talking the Maerklin CAN protocol based on the ESP32 NodeMCU-Board.

CI Status

  • Linux Unittest Build CI

  • Embedded Build PlatformIO CI

  • Windows Unittest Build Windows CI

Software

This project is built using PlatformIO. It makes use of some features that may not be easily portable to other Arduino-supported MCUs.

Library Notes

This project makes use of several libraries. Versioned links to those libraries are available as git submodules. Note that for seom libraries, using forks from the same source as this project may be required.

Note that the CAN driver from the lib directory must not be present when you want to compile using the ESP32-IDF driver. Otherwise, the Controller will just attempt to sit there without sending queued messages or receiving any messages transmitted on the bus.

WiFi

This sketch only supports runtime-selection of CAN connection vs. WiFi connection. The WiFi connection information (SSID, Password, IP of CAN-Gateway) must be hardcoded.

To support hardcoding, a template file "_wificonfig.h" is provided. Copy the template to "wificonfig.h" and adjust the configuration information to your needs.

Menuing

General concept

General: Shift + Direction Change enters the menu (cycles through menus) or leaves the menu without applying any changes.

Menu Levels:

  • Level 0/Default: Loco Control
  • Level 1: Loco List
  • Level 2: Settings Menu
Menuing for Accessories

Menuing is required to map turnout input buttons to turnouts or action lists.

TODO: Design.

Menuing for Engine Control

Menuing is required for selecting an engine to control. This involves the following usecases:

  • Select locally known engine

    • Show list of locally known Engines
    • Select engine
    • Selected Engine is now the active engine
  • Select locally unknown engine

    • Verify that at least one local slot for an engine is open
    • If not:
      • Promt the user to remove an engine from the local database to be able to download a new one.
      • Show list of locally known Engines
      • Select an engine.
      • Selected Engine is marked for replacement
    • If yes:
      • Empty engine slot with lowest index is marked for replacement
    • Download list of Engines & total number of known engines from the master controller.
    • Either: Select engine from the master list
      • Details of Selected engine are downloaded.
    • Either: Scroll up/down beyond the currently known set of engine names.
      • If the engine name is unknown, download list of engines from the master controller.
    • Once the download is complete, the selected engine is now the active engine
Encoder Acceleration for Engine Control

Formula for acceleration curve: y = m*x + c. x is the time since the last rotation in the same direction, y is the number of actual increments to apply.

The acceleration is linear. It should be set up so that there is a cutoff at 500ms (no acceleration when increments are more than half a second apart) and that an "immediate" half rotation (e.g., within 50ms) hits the opposite end of engine velocity.

Thus, boundary conditions for an encoder with 24 increments per rotaton are: 1 Tick = m*500ms + c kMaxEngineVelocity Ticks / 12 increments = m * (50ms / 12 increments) + c

Formulas for calculating m and c:

m = (y1 - y2)/(x1 - x2) = (1 - (kMaxEngineVelocity/12))/(500 - (50/12)) = -0.16

c = y1 - m*x1 = 84.03

Settings Menu

Menu Entries:

  • Turnout mapping
  • Action list mapping
  • Default connection settings
  • WiFi settings
Turnout Mapping

When in the Turnout mapping menu:

  • Press a button (red or green) for a turnout
  • Display shows number of button and whether red or green was pressed (line 1)
  • Display shows human-readable number of currently mapped turnout
  • Use encoder to adjust the number of the turnout
  • pressing the encoder stores the turnout mapping (visual feedback possible?)
  • pressing another turnout button switches to settings for that button
  • pressing shift + encoder leaves the menu.

Possible extension: Use the function buttons to increase/decrease in steps of 10

Unit Testing

This project includes a CMake project. The CMake project is purely used to run unit tests for some parts of the code on your development machine. You do not need to deal with unit tests (or the CMake project) unless you want to actively develop the software. To use the CMake project, create an out-of-tree build directoy (in-tree build will confuse the Automagic of PlatformIO). Unit testing should be possible using any C++14 capable compiler on any Desktop Operating System. It has been tested successefully using MSVC 2017 Community Edition.

Hardware

PCB

There is a KiCAD PCB design included for turning this project into a handheld device. The PCB is designed for the Strapubox 2090 case.

Parts

71
QtyValueFootprintReferences
2210kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR1, R2, R3, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19, R20, R21, R22 +6
1010nCapacitor_THT:C_Disc_D3.4mm_W2.1mm_P2.50mmC1, C2, C3, C4, C5, C6, C7, C8, C9, C10
4PCB ScrewMountingHole:MountingHole_2.5mm_Pad_ViaH3, H4, H5, H6
2100nCapacitor_THT:C_Disc_D3.4mm_W2.1mm_P2.50mmC11, C15
2BC547Package_TO_SOT_THT:TO-92_InlineQ1, Q2
2Conn_01x02_FemaleConnector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_VerticalJ7, J8
2D_SchottkyDiode_THT:D_A-405_P7.62mm_HorizontalD1, D2
110uCapacitor_THT:CP_Radial_D10.0mm_P5.00mmC14
1470uCapacitor_THT:CP_Radial_D10.0mm_P5.00mmC12
14u7Capacitor_THT:CP_Radial_D5.0mm_P2.50mmC13
174LS367Package_DIP:DIP-16_W7.62mm_SocketU3
18P8CConnector_RJ:RJ45_Amphenol_54602-x08_HorizontalJ1
1CH340CPackage_SO:SOIC-16_3.9x9.9mm_P1.27mmU4
1Case ScrewMountingHole:MountingHole_3.2mm_M3H1
1Conn_01x05_FemaleConnector_PinHeader_2.54mm:PinHeader_1x05_P2.54mm_VerticalJ6
1D24V10F3Controller:D24V10F3U5
1DOIT_ESP32_DEVKIT_V1Controller:ESP32-DEVKITV1U6
1ESP32-WROOM-32RF_Module:ESP32-WROOM-32U1
1LCD HeaderConnector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_VerticalJ2
1PIN1Jumper:SolderJumper-3_P1.3mm_Open_Pad1.0x1.5mm_NumberLabelsJP1
1PIN2Jumper:SolderJumper-3_P1.3mm_Open_Pad1.0x1.5mm_NumberLabelsJP2
1Rotary_Encoder_SwitchRotary_Encoder:RotaryEncoder_Alps_EC11E-Switch_Vertical_H20mmSW1
1S88Connector_PinHeader_2.54mm:PinHeader_1x06_P2.54mm_HorizontalJ4
1SW_F0Button_Switch_THT:SW_PUSH_6mm_H9.5mmSW2
1SW_F1Button_Switch_THT:SW_PUSH_6mm_H9.5mmSW3
1SW_F2Button_Switch_THT:SW_PUSH_6mm_H9.5mmSW4
1SW_F3Button_Switch_THT:SW_PUSH_6mm_H9.5mmSW5
1SW_F4Button_Switch_THT:SW_PUSH_6mm_H9.5mmSW6
1SW_PushButton_Switch_THT:SW_PUSH_6mmSW9
1Screw_Terminal_01x05TerminalBlock_4Ucon:TerminalBlock_4Ucon_1x05_P3.50mm_VerticalJ5
1ShiftButton_Switch_THT:SW_PUSH_6mm_H9.5mmSW7
1StopButton_Switch_THT:SW_PUSH_6mm_H9.5mmSW8
1TJA1051TPackage_SO:SOIC-8_3.9x4.9mm_P1.27mmU2
1USB_B_MicroConnector_USB:USB_Micro-B_Molex_47346-0001J3

More from deltaphi/RR32CanController

8
  • 2 layers35 × 124 mmController, the printed circuit board in 3D

    Controller

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    63 parts2GPL-3.0
  • 2 layers85.1 × 49.5 mmIOBreakout, the printed circuit board in 3D

    IOBreakout

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    51 parts2GPL-3.0
  • 2 layers66 × 33 mmSwitchboardSMD, the printed circuit board in 3D

    SwitchboardSMD

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    47 parts2GPL-3.0
  • 2 layers99.1 × 48.3 mmSwitchboard, the printed circuit board in 3D

    Switchboard

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    42 parts2GPL-3.0
  • 2 layers81.3 × 59.7 mmESP32Breakout, the printed circuit board in 3D

    ESP32Breakout

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    33 parts2GPL-3.0
  • 2 layers75 × 50 mmLocoCardBreakout, the printed circuit board in 3D

    LocoCardBreakout

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    10 parts2GPL-3.0
  • 2 layers28 × 40 mmS88Driver, the printed circuit board in 3D

    S88Driver

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    9 parts2GPL-3.0
  • 2 layers7.6 × 25.4 mmSwitchboardConnector, the printed circuit board in 3D

    SwitchboardConnector

    deltaphi/RR32CanController

    Sketch for a Switchboard talking the CAN CS2 protocol based on the ESP32 NodeMCU-Board

    2 parts2GPL-3.0

Similar boards

  • 2 layers102 × 66 mmFREE ENERGY ESP, the printed circuit board in 3D

    FREE ENERGY ESP

    Sureshbkmr/Energy-Harvesting-Based-on-Beaden-Research-Paper

    Based on Beaden Research Paper full custom PCB

    60 parts
  • 2 layers100 × 100 mmVCU V2 kicad9, the printed circuit board in 3D

    VCU V2 kicad9

    HKUST-Red-Bird-Racing-EVRT/GEN5_ELEC

    Repository for RBR EVRT 2025 EE

    84 parts3
  • 2 layers150 × 50 mmEsp32-led smps, the printed circuit board in 3D

    Esp32-led smps

    lucysrausch/esp32-led-smps

    230V main LED smps. 2x30W Constant Current.

    179 parts30
  • 2 layers95.3 × 95.3 mmCPU, the printed circuit board in 3D

    CPU

    f4deb/Kicad

    90 parts

Questions

What parts does the ControllerTHT use?

71 parts, built around the 74LS367PC, CH340C, ESP32-WROOM-32 and TJA1051T. 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 ControllerTHT KiCad files?

From the deltaphi/RR32CanController repository on GitHub, at the commit this page was made from: the board is Hardware/ControllerTHT/ControllerTHT.kicad_pcb and its schematic Hardware/SwitchboardSMD/SwitchboardSMD.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the ControllerTHT design in my own project?

Its repository publishes it under the GPL-3.0 licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).