Controlling Trains
|
For nControl™ 2018.1 or higher
|
This article explains how to control LEGO® trains (PF motor) with nControl using a WiFi train controller.
Configuring the train controller
The first step is to configure the train controller for your WiFi network and computer you're running nControl on. A detailed description on how to do that can be found here.
Creating the train control tile
Trains can be piloted with train control tiles. To create one: switch to Configuration Mode by clicking the  button in the main toolbar and select the train control tile in the panel on the left-hand side.
This will open the Edit Train Control Properties dialog window:

The two most important settings are Label and Motor Position:
- Label: The label is not only displayed at the top of the tile, it also determines to which train controller the instructions will be sent.
The Label of the tile has to match the Alias of the train controller.
Note that tile labels are case sensitive; the label has to be identical to the alias of the train controller otherwise the train controller will not receive the instructions the tile is sending.
- Motor Position: Here you specify whether the PF motor is in the front or back of the train.
The motor position is important to know which direction is forward.
Misconfiguration of the motor position will cause the train to go in the wrong direction.
The Label Color, Label Text, and Label Logo can be used to customize the look of the train control tile and make it match the design of the train it's controlling.
These settings have however no impact on the behavior of the train, they are purely aesthetic.
Close the dialog box with the OK button to create the train control tile.
Controlling trains from nControl
Controlling trains with mobile devices
You can control the trains with a phone of tablet as well. To do this, you need to:
- export your nControl project as a web interface
- open the interface on your mobile device using a web browser
Detailed instructions on how to do that can be found here.
Keep in mind that your mobile device will not connect to the train directly, it will connect to the computer running nControl.
As such it will also be possible to control and monitor other devices in your layout: track switches, traffic lights,... or other trains.
Automating trains
You can automate the train by, for example, making them respond to train detection sensor feedback.
You can do this with Python scripts in tiles of the devices to which the train has to respond.
The API functions to control the train can be found here.
Troubleshooting
If your train does not respond:
- Check if the train controller is connected to nControl.
To do so choose Controller > MQTT Broker in the main menu and check for a 4DBrix WiFi controller connected message.
- Check if the Alias of the train controller is identical to the Label of the tile.
Remember, the label and alias are case sensitive.
Blank spaces are important too: 'Train 1' is not the same as 'Train1'.
If your train goes in the wrong direction:
- Check the Motor Position setting in the Edit Train Control Properties dialog box.
|