Remote control functionality will be available from firmware 1.2.

The MattzoTrainController for Bluetooth (MTC4BT) has two main use cases:

  • Act as MattzoTrainController, i.e. making locomotives on the layout go and stop.
  • Act as MattzoRemoteController, i.e. integrate LEGO Powered Up remote controls into the MattzoBricks Train Automation System 2.0.

On this page, the MattzoRemoteController functionality of the controler is described

Supported devices

MTC4BT supports the following remote controls:

  • LEGO Powered Up remote control (from firmware 1.2)

Up to nine BLE devices can be concurrently connected to the MTC4BT. This means that you can connect nine remote controls to the MTC4BT as the same time.

You can also combine any number of remote controls and other BLE devices to the MTC4BT, as long as you respect the maximum number of BLE devices of 9.

Concept and definitions

In the Mattzobricks Train Automation System, a PU remote controls components.

Components can be of the following type:

  • loco,
  • accessory.

Accessories can be of the following type:

  • switch, including:
    — switches in the direct sense (including triple and double slip-switches),
    — level crossings,
    — bridges,
    — decouplers (if defined as switch in Rocrail), and
    — any other components that are controlled in a similar way,
  • output, any kind of outputs, e.g. street or building lights, decoupler (if defined as output) etc., and
  • signal

A PU remote has buttons.

Each button can be assigned to a specific functionality. A functionality is a defined action applied to a specific component. Depending on the details of the remote configuration, buttons may be wired to predefined functionalities, or can be assigned freely according to the user’s preferences.

In addition to controlling components, a PU remote can also trigger system commands.

Required components, wiring and firmware upload

Please refer to the information on the page for the MattzoTrainController use case of the MTC4BT.

Prerequisites

In Rocrail, it is a good idea to set the decoder steps to 100 / 100 in the loco interface configuration, as shown in the picture below:

To get to this dialog, right-click on a loco in the loco list, and choose “properties”. Then click on the “Interface” tab.

Remote controller configuration

The controller is configured as in the MattzoTrainController use case.

The configuration file controller_config.json contains configuration for locos and remotes. You’ll find examples in the data_example folder.

It can either contain loco and remote configurations directly, or it can link to a separate file. This is important, because remote configurations can easily and quickly exceed the maximum number of 4096 bytes per configuration file. Too large configuration files make the controller crash.

The following example of a controller_config.json shows a configuration with one loco and two remotes. The configuration for the loco and both remotes is specified in three separate files:

{
    "name": "MTC4BT-LOCOS-AND-REMOTES",
    "espPins": [
    ],
    "fn": [
    ],
    "locos": [
    ],
    "remotes": [
    ],
    "locoConfigs": [
        "/loco_E94.json"
    ],
    "remoteConfigs": [
        "/pu_remote1.json",
        "/pu_remote2.json"
    ]
}

Configuration modes

A PU remote can be operated in two configuration modes:

  • in list mode, or
  • in free mode.

If more than one PU remote is configured in a single MTC4BT, they can have different configuration modes.

List mode

General list mode requirements

The list mode is used to control a number of components with a single remote. There is only one list per controller. Only one component can be controlled at the same time. In order to control a component, you need to navigate to the component by using the B+ and B- button. The LED on the remote indicates by its color what component is presently controlled. The presently selected object is called the “selected component”. After boot, the first component in list is selected.

Button assignment in list mode

Hard-wired buttons:

  • B+: navigate up
  • B-: navigate down
  • Bred: Emergency brake (switches layout power off and stops all trains)
  • Green: Layout power on (releases emergency brake)

Other buttons:

  • The functionalty of A+, Ared and A- depend on the selected component, especially its type.
  • For locos, the functionality for these buttons is hard-wired:
    — A+: increase speed (decrease speed if going backwards)
    — Ared: stop loco (set speed to 0)
    — A-: decrease speed (increase speed if going backwards)
  • For accessories, the functionality for these buttons is predefined by the following default values:
    — For switches:*
    — A+: straight (triple switch: left)
    — Ared: flip (triple switch: straight)
    — A-: turnout (triple switch: right)
    — For outputs:
    — A+: on
    — Ared: flip
    — A-: off
    — For signals:
    — A+: green
    — Ared: flip
    — A-: red

All of these default assignments can be overridden by the configuration.

Allowed values:

  • For switches:
    — flip, straight, turnout, left, right, noop
  • For outputs:
    — flip, on, off, noop
  • For signals:
    — flip, green, red, yellow, white, noop

“noop” means “no operation” and is used to deactivate a button without replacing it with another functionality.

Configuration examples in list mode

The following configuration contains a remote in list mode. The file must be linked from the controller_config.json file. The controller controls 4 locos:

{
    "type": "PUController",
    "name": "PUC1",
    "address": "1e:90:le:9o:le:9o",
    "mode": "list",
    "list": [
        {
            "id": "E03",
            "type": "loco",
            "color": "yellow"
        },
        {
            "address": 200,
            "type": "loco",
            "color": "red"
        },
        {
            "address": 10194,
            "type": "loco",
            "color": "green"
        },
        {
            "address": 10277,
            "type": "loco",
            "color": "brown"
        }
    ]
}

Please note that locos in the list can either be addressed by their Rocrail id or their Rocrail address. The color indicates what the LED of the PU shows when the loco is selected.

The following configuration contains another remote, also in list mode. The controller controls a couple of accessories. Most accessories use the standard buttons, some are overridden with other button assignments. The “remark” attributes have no semantical meaning and are just ment for explanation:

{
    "type": "PUController",
    "name": "PUC2",
    "address": "1e:90:le:9o:le:9o",
    "mode": "list",
    "list": [
        {
            "id": "sw11",
            "remark": "a simple switch",
            "type": "switch",
            "color": "red"
        },
        {
            "id": "sw12",
            "remark": "a triple switch",
            "type": "switch3",
            "color": "yellow"
        },
        {
            "id": "sw13",
            "remark": "a double slip switch",
            "type": "switch",
            "color": "orange"
        },
        {
            "id": "sg1+",
            "remark": "a signal",
            "type": "signal",
            "color": "green"
        },
        {
            "id": "decoupler1",
            "remark": "a decoupler defined as 'switch'",
            "type": "switch",
            "color": "magenta"
        },
        {
            "id": "decoupler2",
            "remark": "a decoupler defined as 'output'",
            "type": "output",
            "color": "purple"
        }
    ]
}

Accessories must be referenced by the Rocrail id. Please note that standard switches and double-slip-switches must be defined as type “switch”, and triple switches as “triple3”.

Free Mode

In this configuration mode, each of the seven buttons of a PU remote can be assigned to a specific functionality without restrictions.

Examples:

  • Increase (“inc”) or decrease (“dec”) the speed of a specific loco.
  • Stop (“stop”) a specific loco.
  • Set a specific loco function to on (“on”) or off (“off”), flip (“flip”) its state or activate it like pressing a push (“push”) buttons.
  • Flip a specific accessory or bring it into a distinct state (allowed commands see above).
  • Send system commands like pulling the emergency brake (“ebrake”) or switching the power back on (“go”).

There is just one thing that you can not do in free mode: navigate through a list of components that you want to control! Each button is assigned to a specific action on a specific component.

You can assign any number of control actions to a single button. This means that a single button can control multiple switches, signals etc. at the same time. For example, you could set a complex route over the layout that covers multiple switches through a railyard, and sets the entry signal to “green”, and all of that with a single press of a button.

Configuration examples in free mode

The following example represents a controller that controls two switches and two signals. One switch and one signal is controlled via flip command, the other one are controlling by setting a distanct state:

{
    "type": "PUController",
    "name": "PUC3",
    "address": "1e:90:le:9o:le:9o",
    "mode": "free",
    "buttons": [
        {
            "button": "A+",
            "type": "switch",
            "id": "sw11",
            "action": "straight"
        },
        {
            "button": "A-",
            "type": "switch",
            "id": "sw11",
            "action": "turnout"
        },
        {
            "button": "Ared",
            "type": "switch",
            "id": "sw12",
            "action": "flip"
        },
        {
            "button": "B+",
            "type": "signal",
            "id": "sg2-",
            "action": "green"
        },
        {
            "button": "Bred",
            "type": "signal",
            "id": "sg2-",
            "action": "red"
        },
        {
            "button": "B-",
            "type": "signal",
            "id": "sg2-",
            "action": "yellow"
        },
        {
            "button": "green",
            "type": "signal",
            "id": "sg1+",
            "action": "flip"
        }
    ]
}

The following example represents a controller for a single loco on Port A. Port B is used for the train light, emergency brake and a switch. The green buttons powers the layout on.

{
	"type": "PUController",
	"name": "PUC4",
	"address": "1e:90:le:9o:le:9o",
	"mode": "free",
	"buttons": [
		{
			"button": "A+",
			"type": "loco",
			"addr": 100,
			"action": "inc"
		},
		{
			"button": "A-",
			"type": "loco",
			"addr": 100,
			"action": "dec"
		},
		{
			"button": "Ared",
			"type": "loco",
			"addr": 100,
			"action": "stop"
		},
		{
			"button": "B+",
			"type": "loco",
			"addr": 100,
			"action": "fn1",
			"remark": "fn-actions can be 'on', 'off', 'push' and 'flip'",
			"fn-action": "flip"
		},
		{
			"button": "B-",
			"type": "switch",
			"id": "sw11",
			"action": "flip"
		},
		{
			"button": "Bred",
			"type": "system",
			"action": "ebrake"
		},
		{
			"button": "green",
			"type": "system",
			"action": "go"
		}
	]
}

A single button can be assigned to multiple actions, which are executed in the order in which they are defined in the configuration. This makes the free mode can extremely powerful way of configuring a remote. You can even set complex routes with multiple switches and signals with a single button press.