Testing, Tuning, and Control

Conductor Level

Turntable-EX commands

Before proceeding with testing or any configuration, it’s important to understand the two commands available for controlling Turntable-EX.

This is a debug or diagnostic command that can be executed via the serial terminal of the CommandStation:

<D TT vpin steps activity>

This is the EX-RAIL command to be included in myAutomation.h:

MOVETT(vpin, steps, activity)

For both of these commands, “vpin” is as defined in your “myHal.cpp” file, and “steps” is the number of steps from the home position, not the number of steps the turntable has to travel.

For the diagnostic command, “activity” needs to be defined as a number, whereas for the EX-RAIL command, this is defined as text based on the table below. Sound confusing? The reason for using text in the EX-RAIL command is to make your automation sequences more “human-friendly” when reading what they do later. It’s much easier for us humans to remember words rather than numbers.

Diagnostic activity

EX-RAIL activity




Turn to the desired step position



Turn to the desired step position and invert the phase/polarity



Activate the homing process, ignores the provided step position



Activate the automatic calibration process, ignores the provided step position



Turns the LED on, ignores the provided step position



Sets the LED to a slow blink, ignores the provided step position



Sets the LED to a fast blink, ignores the provided step position



Turns the LED off, ignores the provided step position



Turns the accessory output on, ignores the provided step position



Turns the accessory output off, ignores the provided step position

Here’s a quick example to demonstrate the difference between the diagnostic and EX-RAIL commands, with both commands below rotating to step position 100, and both inverting the phase/polarity of the bridge track:

<D TT 600 100 1>
MOVETT(600, 100, Turn_PInvert)

Note with the phase/polarity inversion, this activity must be defined for every position that requires the phase to be inverted compared with the surrounding tracks. If it is not defined, the relays will be deactivated, resulting in no phase/polarity inversion. The examples below will help clarify this.

Testing Turntable-EX

Firstly, power on Turntable-EX, followed by your CommandStation. By powering these on in that order, you will ensure that Turntable-EX is available prior to the CommandStation trying to load the device driver, otherwise it will consider the device as “OFFLINE”, and commands will fail.

Referring again to Adding a New Device, skip ahead to Checking the Driver, and the output you’re looking for to validate the Turntable-EX device driver is loaded and connected successfully is below:

<D HAL SHOW><* Arduino Vpins:2-69 *>
<* PCA9685 I2C:x40 Configured on Vpins:100-115  *>
<* PCA9685 I2C:x41 Configured on Vpins:116-131 OFFLINE *>
<* MCP23017 I2C:x20 Configured on Vpins:164-179 OFFLINE *>
<* MCP23017 I2C:x21 Configured on Vpins:180-195 OFFLINE *>
<* TurntableEX I2C:x60 Configured on Vpins:600-600  *>          <<== This is the important line, Turntable-EX is connected!

If there is an “OFFLINE” at the end of the Turntable-EX line, it indicates something is not quite right. Refer to Turntable-EX showing as offline with <D HAL SHOW>.

At power on, note that the turntable should have moved itself to the home position, so all commands below assume this is the case.

This command should rotate the turntable 100 steps only:

<D TT 600 100 0>

This command should rotate the turntable a further 500 steps (the difference between the existing 100 steps and target 600 steps) only:

<D TT 600 600 0>

This next command should rotate the turntable in the reverse direction by 300 steps:

<D TT 600 300 0>

This command should rotate the turntable again in the reverse direction, however should also activate both phase switching relays:

<D TT 600 2000 1>

This command should rotate the the turntable further in the reverse direction, and deactivate the phase switching relays:

<D TT 600 1500 0>

Finally, this command will cause the turntable to once again find its home position:

<D TT 600 0 2>

<TO DO: Add a video demonstrating these tests>

Providing these tests have completed successfully, you are now ready to tune the turntable positions for your layout in preparation for defining the EX-RAIL configuration and putting Turntable-EX to good use.

Tuning your turntable positions


To determine your starting positions, you will need the full turn step count as recorded in Automatic calibration.

To tune your turntable positions, there are two aspects to consider.

First will be the number of steps from the home position the turntable needs to rotate in order to reach the desired position. By default, the turntable will turn in a clockwise direction (as demonstrated by the homing activity).

Second will be the phase or polarity required for the bridge track to match the connecting layout tracks, as described in the Important! Phase (or polarity) switching section.

Determine the positions

At this point, you should either have a layout you’re fitting Turntable-EX into, or a layout design that you’re working to, with the various turntable connection tracks defined.

The simplest way to devise the approximate number of steps for each turntable position is to calculate these based on the degrees each step will turn.

For the default Turntable-EX configuration with the ULN2003/28BYJ-48 stepper driver/motor combo in half step mode, this should give a step count close to 4096 for a single 360 degree rotation, which means each step is ~0.088 degrees of movement (360/4096 = 0.088).

Therefore, to determine the number of steps required to turn a certain number of degrees, use the formula “steps = degrees/degrees per step”. To turn 10 degrees requires ~114 steps (10 / 0.088 = 113.64).

In this example, for simplicity, we will devise the steps required for a six position turntable, with position 1 being 10 degrees from the home position, position 2 a further 10 degrees, position 3 a further 10 degrees again, and positions 4 through 6 being 180 degrees from the first three positions.

Six Postion Example

Therefore, using our formula, the starting point for each position will be:


Degrees from home

Steps from home



















Determine phase switching

Assuming your layout tracks are wired correctly as per Important! Phase (or polarity) switching, each of the positions determined above will need to have the phase set correctly.

In the provided example, positions 1, 2, and 3 would match the surrounding track polarity, with positions 4 through 6 requiring the phase/polarity to be switched.

Example tuning commands

To validate the above calculated positions, the following six diagnostic commands should be executed in the serial terminal of the CommandStation, which will allow you to visually inspect the alignment with your layout tracks and adjust accordingly:

<D TT 600 114 0>
<D TT 600 227 0>
<D TT 600 341 0>
<D TT 600 2159 1>
<D TT 600 2273 1>
<D TT 600 2386 1>

If you find any of these positions are slightly out of alignment, simply adjust the step count as appropriate to compensate.

Note that the last three positions all invert the DCC phase or polarity, which should ensure that the bridge track maintains the same phase/polarity as the connecting layout tracks, meaning no short circuits.

Apply to your layout

At this point, you should be able to apply the above calculations to your own layout and come up with the step count and phase/polarity settings required for each position.

Use appropriate diagnostic commands to test and tune each position for that perfect alignment, and providing your layout is functional, you should be able to drive a locomotive on and off your turntable in each position.

Advertising positions to Engine Driver and WiThrottle applications

Now that you have defined all of your turntable positions with appropriate phase/polarity switching, it’s time to get these advertised to Engine Driver and WiThrottle applications.

The method to advertise these is to use EX-RAIL’s ROUTE function with the MOVETT command, which will ensure all of your defined turntable positions appear in the Engine Driver and WiThrottle Routes sections.

If this is your first experience with EX-RAIL and the “myAutomation.h” file, familiarise yourself with EX-RAIL by reading through Introduction to EX-RAIL Automation.

Pay particular attention to the various mentions of ROUTE and the associated examples.

There are two highly recommended additions to using just these ROUTEs:

  1. Utilise EX-RAIL’s virtual RESERVE() and FREE() functions to ensure that while you are operating your turntable, nothing else can interfere with it. This is not so important during manual operation, however if you want to add any other automation (say, turning a warning light on), you will need these to ensure the relevant automation activities are not interrupted should you choose another turntable position prior to the first move completing.

  2. Utilise aliases to make things human friendly, and we have also provided 30 pre-defined aliases for the ROUTE IDs to ensure there will be no conflicts, as all IDs must be unique.

To define the required turntable positions in the example six position turntable from above, you will need to have this content added to your “myAutomation.h” file. Note that we recommend adding an additional ROUTE to activate the homing process.


Conductor Level

To make this as simple as possible, we have included “myTurntable-EX.example.h” with the CommandStation-EX software containing an example automation macro with some pre-defined positions based on the example above as a starting point. Feel free to either copy or rename this to “myAutomation.h” and use it.

That’s it! Once you have created “myAutomation.h” and uploaded it to your CommandStation as per the process on the Introduction to EX-RAIL Automation page, the routes for each turntable position should automatically be visible in Engine Driver and WiThrottle applications.

My turntable moves on startup!

There is one “catch” with the above “myAutomation.h” example. When your CommandStation starts up and EX-RAIL starts, it will automatically execute everything in “myAutomation.h” up until the first “DONE” statement it encounters.

In this scenario, that means on startup, the turntable will automatically move to position 1.

If you wish to leave the turntable at the home position on startup, you can simply comment out the first MOVETT() command:

MOVETT(600, 114, Turn)        <<== This line here
// MOVETT(600, 114 Turn)      <<== Becomes this, add // to comment lines out

In a similar manner, if you prefer the turntable starts at some other position, you can accomplish this by simply changing the steps in that same MOVETT() command:

MOVETT(600, 167, Turn)            // Default moves to position one, edit this line to look like the below
MOVETT(600, 2386, Turn_PInvert)   // Move instead to position six, note the required DCC phase inversion to prevent a short circuit