Adding Servo-Controlled Turnouts to Your Model Railway with DCC-EX and EXRAIL

Adding Servo-Controlled Turnouts with DCC-EX, EXRAIL and PCA9685

This support guide explains how to add reliable, low-cost servo turnout control to a working DCC-EX CommandStation using a PCA9685 16-channel I2C servo controller and EXRAIL.

It covers wiring, HAL setup, turnout definitions and basic servo calibration.

Before you begin: this guide assumes you already have a working DCC-EX CommandStation. If you are using the CSB1 Ready-to-Run system, your main CommandStation setup is already handled and you can use this guide only for adding servo turnout expansion.

Which setup are you using?

Setup type How this guide applies
CSB1 Ready-to-Run system Your main DCC system is already complete. Use this guide when adding PCA9685 servo turnout control.
CSB1 Core / custom setup Make sure your CommandStation, power supply and basic DCC-EX setup are working before adding servos.
DIY DCC-EX build Confirm your I2C wiring, firmware and CommandStation configuration before continuing.

Hardware You Need

To add servo-controlled turnouts, you will need:

  • Working DCC-EX CommandStation
  • PCA9685 16-channel I2C servo controller board
  • Servos — one per turnout
  • Regulated 5V power supply for the servos
  • I2C connection to your CommandStation, such as Qwiic or SDA/SCL pins
  • Common ground between the CommandStation, PCA9685 and 5V servo power supply

The PCA9685 is used as an expansion board. It allows one DCC-EX CommandStation to control multiple servos for points, turnouts, signals or accessories.

Power warning: do not power servos directly from the CommandStation. Use a separate regulated 5V servo power supply connected to the PCA9685 servo power input. The CommandStation ground, PCA9685 ground and servo power supply ground must be connected together.

Note: many users with the Ready-to-Run system will only need to focus on the PCA9685, servo power and EXRAIL configuration steps below.


Wiring the PCA9685 Servo Controller

  1. Connect SDA on the PCA9685 to SDA on the CommandStation.
  2. Connect SCL on the PCA9685 to SCL on the CommandStation.
  3. Connect VCC for logic power, usually 3.3V or 5V depending on your board and setup.
  4. Connect GND between the CommandStation and PCA9685.
  5. Connect your separate 5V servo power supply to the PCA9685 servo power input.
  6. Connect the servo power supply ground to the common ground.

Common ground example

CommandStation GND  ─┬─ PCA9685 GND
                     └─ 5V Servo PSU GND

Without a shared ground, the servos may behave unpredictably or fail to respond correctly.


Checking I2C Detection

After wiring the PCA9685, power up the CommandStation and check the console log. DCC-EX should list detected I2C devices and show the PCA9685 address.

The most common PCA9685 I2C address is:

0x40

If the console shows:

< No I2C Devices found >

Check the following:

  • SDA and SCL are connected correctly
  • The PCA9685 has logic power
  • Ground is shared with the CommandStation
  • The board is connected the correct way round

Using More Than One PCA9685 Servo Controller

If your layout requires more than 16 servo outputs, multiple PCA9685 boards can share the same I2C connection to the CSB1 or other DCC-EX CommandStation.

However, each PCA9685 connected to the same I2C bus must have a unique I2C address.

A new PCA9685 normally uses the default address:

0x40

If two boards are connected while both are set to 0x40, the CommandStation cannot address them independently. Before connecting additional boards, change their addresses using the small A0-A5 address solder pads on the PCA9685.

The address pads work as a binary offset from the base address of 0x40. Bridge the required pad, or combination of pads, with a small amount of solder.

PCA9685 Board I2C Address Address Pads to Bridge
First board 0x40 None
Second board 0x41 A0
Third board 0x42 A1
Fourth board 0x43 A0 + A1
Fifth board 0x44 A2
Sixth board 0x45 A2 + A0
Seventh board 0x46 A2 + A1
Eighth board 0x47 A2 + A1 + A0

For most model railway installations, this provides considerably more servo capacity than will normally be required.

Example: Connecting Two PCA9685 Boards

For two boards, leave the first PCA9685 unchanged at its default address:

0x40

On the second PCA9685, bridge the A0 solder pad. This changes its address to:

0x41

The two boards can then share the same SDA and SCL I2C connections while being recognised individually by DCC-EX.

The corresponding HAL configuration could be:

// First PCA9685 - channels 0-15
HAL(PCA9685, 100, 16, 0x40)

// Second PCA9685 - channels 16-31
HAL(PCA9685, 116, 16, 0x41)

This gives the first board vPins 100-115 and the second board vPins 116-131.

Important: Do not connect multiple PCA9685 boards using the same I2C address. Each board on the I2C bus must have its own unique address.

After changing an address, power up the CommandStation and check the DCC-EX console to confirm that the expected I2C addresses are detected before configuring your servos.


HAL Configuration for PCA9685

Declare the PCA9685 in myAutomation.h using the HAL(...) macro.

Example PCA9685 HAL entry

// start vPin, count, I2C address
HAL(PCA9685, 100, 16, 0x40)

This creates 16 virtual pins, starting at vPin 100.

vPin to PCA9685 Channel Map

vPin PCA9685 Channel
100 Channel 0
101 Channel 1
102 Channel 2
... ...
115 Channel 15

Adding a second PCA9685 board

If you add another PCA9685, it must use a different I2C address and a different vPin range.

HAL(PCA9685, 116, 16, 0x41)

Defining Servo Turnouts in myAutomation.h

After registering the PCA9685 with HAL, define each servo turnout using SERVO_TURNOUT.

Syntax

SERVO_TURNOUT(id, vPin, active_angle, inactive_angle, profile, description)

Basic example

SERVO_TURNOUT(1, 100, 250, 250, Fast, "Turnout 1")
SERVO_TURNOUT(2, 101, 250, 250, Fast, "Turnout 2")

In this example:

  • 1 and 2 are the turnout IDs
  • 100 and 101 are the vPins assigned through the PCA9685 HAL entry
  • The angle values are placeholders for calibration
  • Fast is the movement profile
  • The final text is the turnout description

Calibrating Servo Angles

Servo angle calibration is usually the most important part of turnout setup. Start gently and avoid forcing the turnout mechanism.

  1. Start with both servo angle values the same, for example 250, 250.
  2. Use EX-Toolbox or your preferred DCC-EX method to test movement.
  3. Adjust the active and inactive values gradually.
  4. Upload the updated configuration.
  5. Test the turnout in both directions.

Test commands

<T 1 C>
<T 1 T>

These commands test turnout ID 1 in the closed and thrown positions.

Calibration tip: do not allow the servo to push hard against the turnout end stops. If the servo buzzes or strains, reduce the travel range.


Recommended Expansion Path

For a simple DCC-EX layout, the best approach is usually:

  1. Start with a working DCC-EX CommandStation
  2. Confirm train control is working reliably
  3. Add the PCA9685 servo controller
  4. Configure servo turnouts in EXRAIL
  5. Add more automation later if required

Using a CSB1 Ready-to-Run system? You do not need to rebuild the CommandStation. Add the PCA9685 servo controller as an expansion module, then follow the configuration steps in this guide.


Troubleshooting

Problem Likely Cause Check
No I2C device found SDA/SCL wiring, power or address issue Check wiring, ground and I2C address
Servo does not move No servo power or incorrect vPin Check 5V supply and HAL mapping
Servo jitters Weak power supply or poor grounding Use a regulated 5V supply and common ground
Turnout buzzes Servo over-travel Reduce active/inactive angle range

Useful Products

The following products may be useful when adding servo turnout control to a DCC-EX layout:


Your DCC-EX CommandStation can now support servo-controlled turnouts through EXRAIL and a PCA9685 servo controller.