{"id":1213,"date":"2020-12-02T21:12:54","date_gmt":"2020-12-02T21:12:54","guid":{"rendered":"http:\/\/mattzobricks.com\/?page_id=1213"},"modified":"2022-12-27T13:29:53","modified_gmt":"2022-12-27T12:29:53","slug":"general","status":"publish","type":"page","link":"https:\/\/mattzobricks.com\/de\/automation\/controllers\/general","title":{"rendered":"General Section"},"content":{"rendered":"\n<p>Please read this section carefully and completely before you start building your first MattzoController.<\/p>\n<p>The electrical wiring and the firmware of the different MattzoController types are different, but all controllers also have strong similarities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MattzoController in general<\/h2>\n\n\n\n<p>This section applies to all types of MattzoControllers.<\/p>\n\n\n\n<p>In this section, some common features of all kinds of the MattzoController are described. The different types of MattzoControllers are described in greater detail in the subsequent sections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">General considerations<\/h2>\n\n\n\n<p>First you need to build the controller, download the firmware, do some network and wiring configuration in the code, and then upload the firmware to the controller.<\/p>\n\n\n\n<p>To complete these tasks successfully, it is helpful if you have played around with microcontrollers before. It is even more helpful if you have basic understanding of computer networks and computer programming.<\/p>\n\n\n\n<p>Nevertheless, we know of many people who successfully managed to build and set-up MattzoControllers with very little specific knowledge about those things, and brought their LEGO train layout to a whole new level.<\/p>\n\n\n\n<p>The Mattzobricks community is growing every day, and we are proud about each new layout that was automated with the Mattzobricks Train Automation System.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building the different controller types<\/h2>\n\n\n\n<p>Instructions how to build the different controllers can be found in the controller-specific sections.<\/p>\n\n\n\n<p>If you have a 3d printer, you may be interested in the stl files to print out some nice <a href=\"https:\/\/mattzobricks.com\/controllers\/casing\" type=\"page\" id=\"2071\">cases<\/a> for the controllers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Uploading the firmware<\/h2>\n\n\n\n<p>Previous versions of the MattzoController firmware needed to be compiled and uploaded with the Arduino IDE.<\/p>\n\n\n\n<p>In 2022, we have migrated all of the firmware packages to a new platform (VSCode with the platformIO plug-in). The source code is also now publically available in Mattzobricks&#8217; MattzoController github repository.<\/p>\n\n\n\n<p>Information about getting and uploading the firmware can be found on the <a href=\"https:\/\/mattzobricks.com\/controllers\/firmware\" data-type=\"page\" data-id=\"5633\">firmware<\/a> page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WiFi setup<\/h2>\n\n\n\n<p>The MattzoController tries to connect to WIFI on start-up. The SSID and WIFI passphrase must be set in the network configuration file before you upload the firmware in order to enable the controller to establish the connection.<\/p>\n\n\n\n<p>If you have installed the optional status LED, the LED flashes during the WiFi connection process (0.1 seconds on, 0.9 seconds off). After a successful connect, the LED turns blinking (0.5 seconds on, 0.5 seconds off) to indicate it tries to connect to the MQTT broker.<\/p>\n\n\n<p><!-- \/wp:post-content --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>MQTT<\/h2>\n<h3>Setting up MQTT<\/h3>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>After establishing a WIFI connection, the controler connects to the MQTT broker.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>Download and install a MQTT broker and start it somewhere in your local network, e.g. on the computer on which Rocrail is running. The most common MQTT broker is the free &#8220;mosquitto&#8221; software, which can be downloaded from <a href=\"https:\/\/mosquitto.org\/\">https:\/\/mosquitto.org<\/a>.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>The IP address of the MQTT broker must also be set in your network configuration file.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>Mosquitto needs no special configuration in version 1.x. Just start it by running mosquitto.exe.<\/p>\n<p>Please be aware that your computer may have <strong>multiple network adapters<\/strong>, e.g. one for Ethernet (LAN) and another one for WiFi. It is important that mosquitto is listening on the WiFi network adapter. If you want to keep things simple, deactivate all network adapters that you do not need or &#8211; even simpler &#8211; pull out the network cable before starting mosquitto.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>Important: <\/strong>From mosquitto version 2.0 and above, mosquitto needs a configuration file in order to allow connections from clients that do run on the same machine as mosquitto itself &#8211; like the MattzoControllers. The configuration file should be named mosquitto.conf and should be in the mosquitto installation directory. The file needs to contain the following lines:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:preformatted --><\/p>\n<pre class=\"wp-block-preformatted\">allow_anonymous true<br \/>listener 1883<\/pre>\n<p><!-- \/wp:preformatted --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>You can now start mosquitto with the following command:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:preformatted --><\/p>\n<pre class=\"wp-block-preformatted\">mosquitto -c mosquitto.conf<\/pre>\n<p><!-- \/wp:preformatted --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>If you use Microsoft Windows 10, another option is to use the mosquitto service, which is automatically installed on your machine if you have installed mosquitto 2.0 with the mosquitto installation program. Navigate to the Windows Services, start the service and set the start-up type to &#8220;automatic&#8221;. Remember to set-up the mosquitto.conf file exactly as described above!<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>If you have installed the optional status LED, the LED blinks (0.5 seconds on, 0.5 seconds off) to indicate it tries to connect to the MQTT broker. After a successful connection, the LED is turned off.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<h3>Fetching the MattzoControllerID via MQTT<\/h3>\n<p>When a MattzoController starts for the first time, it automatically creates a <strong>MattzoControllerID<\/strong>.<\/p>\n<p>The MattzoControllerID is required for the MLC, as it must be used as the Rocrail base address of all components that you connect to the controller.<\/p>\n<p>After the controller has connected to the MQTT broker, the MattzoControllerID can be identified by monitoring the MQTT messages on the MQTT broker. To inspect the MQTT message, you must run the MQTT broker in a mode in which it logs out the MQTT messages. This is often called the &#8220;verbose&#8221; mode. If mosquitto is used as MQTT broker, the verbose mode can be started in MS Windows. Stop the service, open a command line window, navigate to the mosquitto installation directory and type:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:preformatted --><\/p>\n<pre id=\"block-8f78a0bb-0792-4db9-8e15-04c8a27ed551\" class=\"wp-block-preformatted\">mosquitto -v<\/pre>\n<p><!-- \/wp:preformatted --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>If you use mosquitto 2.0+, the command would be:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:preformatted --><\/p>\n<pre class=\"wp-block-preformatted\">mosquitto -c mosquitto.conf -v<\/pre>\n<pre class=\"wp-block-preformatted\">\u00a0<\/pre>\n<p><!-- \/wp:preformatted --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>Important<\/strong>: The verbose mode is good for detecting the MattzoControllerID, and for testing and debugging. <strong>Do not use verbose mode<\/strong> when you operate large and complex layouts with a large number of switches, sensors, lights, trains and MattzoControllers, because the option may significantly slow down the communication between the components. This may lead to overshooting of trains after they pass sensors or other undesired behaviour of the your rolling and fixed stock.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>Emergency Brake<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>MattzoControllers send last will messages to the MQTT broker upon disconnection, if they are critical to your railway operation. A controller must be considered &#8220;critical&#8221; if it controls one or more of the following components:<\/p>\n<ul>\n<li>switches,<\/li>\n<li>sensors,<\/li>\n<li>bascule bridges,<\/li>\n<li>turn tables,<\/li>\n<li>trains.<\/li>\n<\/ul>\n<p>The following components are usually not critically, as they simply beautify your layout, but do not lead to consecutive problems in case of their failure:<\/p>\n<ul>\n<li>signals,<\/li>\n<li>level crossings,<\/li>\n<li>speed controllers.<\/li>\n<\/ul>\n<p>Last will messages trigger the <strong>emergency brake<\/strong> for all MattzoTrainControllers, i.e. all trains stop if a critical MattzoController disconnects from the MQTT broker. This helps to prevent larger crashes on the layout.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>You can also trigger the emergency brake directly from Rocrail: Either press the &#8220;Power off&#8221; button (the light bulb), or the &#8220;Emergency Brake&#8221; (the red dot). This way, a ghost train can trigger an emergency brake situation, which is quite handy to prevent larger crashes. To set this up, you need to enable the feature &#8220;Power off at ghost train&#8221; in the Rocrail settings.<\/p>\n<p>Shutting down Rocrail will also trigger the emergency brake.<\/p>\n<p>An emergency brake situation can be noted by two things:<\/p>\n<ol>\n<li>No trains are moving any more<\/li>\n<li>All train lights are blinking.<\/li>\n<\/ol>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>The emergency brake situation remains until you have reset it. To reset, you need to virtually switch the &#8220;power&#8221; in Rocrail off and on again:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":1481,\"sizeSlug\":\"large\",\"linkDestination\":\"none\"} --><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"739\" class=\"wp-image-1481\" src=\"http:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/release_ebreak.png\" alt=\"\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/release_ebreak.png 865w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/release_ebreak-300x256.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/release_ebreak-768x656.png 768w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>The Serial Monitor<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>On first boot, the controller generates a random number called &#8220;MattzoControllerID&#8221;. This id is an integer value between 1 and 65000. The MattzoControllerID is stored in the long-term memory of the micro controller and reloaded on subsequent boots.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>The controller prints the MattzoControllerId to serial on boot. You can inspect the information when you connect the controller via USB to your PC, start the serial monitor of the Arduino IDE (Ctrl + Shift + M) and reset the controller.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":1214,\"sizeSlug\":\"large\"} --><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"659\" class=\"wp-image-1214\" src=\"http:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/Serial-Monitor-1024x659.png\" alt=\"\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/Serial-Monitor-1024x659.png 1024w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/Serial-Monitor-300x193.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/Serial-Monitor-768x494.png 768w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/12\/Serial-Monitor.png 1426w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/>\n<figcaption>Arduino IDE <em>Serial Monitor<\/em> with Boot information of a MattzoController. The MattzoControllerID is 9990.<\/figcaption>\n<\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>Tip: it&#8217;s also a good idea to have the controller connected to the serial monitor when trying to solve problems. Even better it to use the built-in syslog capability of the MattzoControllers. To use this feature, you need to enable and set it up in MattzoController_Network_Configuration.h.<\/p>\n<p>If you use the MTC4BT: there is also a very good serial monitor in Visual Studio Code \/ Platform.io.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>Rocrail Setup<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>Download and install Rocview on your computer.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>Required settings:<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:list --><\/p>\n<ul>\n<li>Tab &#8220;Service&#8221;\n<ul>\n<li>Rocrail Properties (menu File \/ Rocrail Properties)\n<ul>\n<li>MQTT Service\n<ul>\n<li>Hostname: IP address of the MQTT broker (e.g. localhost)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><!-- \/wp:list --><\/p>\n<p><!-- wp:image {\"id\":707,\"sizeSlug\":\"large\"} --><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"730\" class=\"wp-image-707\" src=\"http:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-1.png\" alt=\"\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-1.png 940w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-1-300x233.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-1-768x596.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:list --><\/p>\n<ul>\n<li>Tab &#8220;Controller&#8221;\n<ul>\n<li>Add the &#8220;virtual&#8221; controller.<\/li>\n<li>Rename it to &#8220;vcs-1&#8221; or similar.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><!-- \/wp:list --><\/p>\n<p><!-- wp:image {\"id\":708,\"sizeSlug\":\"large\"} --><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"935\" height=\"728\" class=\"wp-image-708\" src=\"http:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-2.png\" alt=\"\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-2.png 935w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-2-300x234.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/06\/Rocrail-config-general-2-768x598.png 768w\" sizes=\"auto, (max-width: 935px) 100vw, 935px\" \/><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>Problem Fighting<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:list --><\/p>\n<ul>\n<li>If Rocrail does not receive sensor events from the MattzoController, you should first check if the controller has booted correctly. If this is not the case, it may help to disconnect LEDs or sensors from the micro controller and try again.<\/li>\n<li>Then you should check if the controller has successfully connected to WIFI. Make sure that you have sufficient WIFI coverage at the desired location of the controller. Rebooting the controller (something multiple times) may also help, especially on ESP-32 boards.<\/li>\n<li>Check if the controller has successfully connected to MQTT. If you use mosquitto, it may help to subscribe to the MQTT broker with the command line &#8220;mosquitto_sub -t # -v&#8221; and check if there are incoming messages from the controller at all. Make sure you enable anonymous inbound connections if using mosquitto 2.0 or above as described in the MQTT section!<\/li>\n<li>Check if Rocrail is configured correctly.<\/li>\n<\/ul>\n<p><!-- \/wp:list --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>Tips and Tricks<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:list --><\/p>\n<ul>\n<li>Make sure that all network nodes have permanent and sufficient WIFI reception!<\/li>\n<li>Make sure that the controllers have sufficient power supply. This applies especially to the MattzoSwitchController, but in general also to the other controller types!<\/li>\n<li>Reduce anything that could cause lags and delays on your computer, e.g.:\n<ul>\n<li>Switch off &#8220;Trace&#8221; in Rocrail settings.<\/li>\n<\/ul>\n<ul>\n<li>Do not run mosquitto in verbose mode when actually operating real trains.<\/li>\n<li>Switch off desktop background slide shows that load complex pictures.<\/li>\n<li>Switch off complex screen savers.<\/li>\n<li>Stop clients like Dropbox, OneDrive, iCloud or other cloud upload\/download software. They demand significant processing and network ressources on your computer and may come to live arbitrarily.<\/li>\n<li>Switch off syslog and too verbose logging in the MattzoController network configuration. The maximum log level in MLC, MTC4PF and MTC4PU should be LOG_INFO.<\/li>\n<\/ul>\n<\/li>\n<li>If you not attending your layout, <strong>power down all MattzoSwitchControllers<\/strong> for security reasons. If a switch motor is trying to turn to a position that it can not achieve, it will block, overheat and eventually break. MattzoSwitchControllers are trying to turn the servo motor as they are told from Rocrail. It is important to note that a simple configuration error can cause the switch motor to overheat! <strong>PLEASE TAKE THIS WARNING SERIOUS<\/strong>. I have reports of a user who literally BURNED off an ESP-8266 micro controller. With &#8220;burn&#8221; I mean: it went on flames! Okay okay, the guy connection the controller to a car battery, but be careful anyway!<\/li>\n<\/ul>\n<p><!-- \/wp:list --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:heading {\"level\":3} --><\/p>\n<h2>How to contribute<\/h2>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>The code is managed as a git repository on Github. Maintenance and enhanvements are mainly done by Mattze and other members of the MattzoBricks core development team.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>If you would like to join the MattzoBricks core development team, send an e-mail to info@mattzobricks.com.<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>We think about setting the git repository to <strong>public<\/strong>, maybe from firmware version 1.0.<\/p>\n<p><!-- \/wp:paragraph --><\/p>","protected":false},"excerpt":{"rendered":"<p>Please read this section carefully and completely before you start building your first MattzoController. The electrical wiring and the firmware of the different MattzoController types are different, but all controllers also have strong similarities. MattzoController in general This section applies to all types of MattzoControllers. In this section, some common [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":636,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-1213","page","type-page","status-publish","hentry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"de","enabled_languages":["en","de"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"de":{"title":false,"content":false,"excerpt":false}}},"_links":{"self":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/comments?post=1213"}],"version-history":[{"count":44,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1213\/revisions"}],"predecessor-version":[{"id":5665,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1213\/revisions\/5665"}],"up":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/636"}],"wp:attachment":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/media?parent=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}