Ansicht von 5 Antwort-Themen
  • Autor
    Beiträge
    • #8519
      Andreas BrockmeyerAndreas Brockmeyer
      Teilnehmer

      Hallo zusammen,

      Ich bin neu hier und habe ein paar Fragen.

      Als erstes zu meiner Person:
      ich baue seit ich denken kann mit Lego und habe vor ein paar Jahren damit angefangen die alte Lego 9 Volt Eisenbahn aus den 1990iger Jahren meines Sohnes wieder aufzubauen. Angefangen habe ich mit Zukauf von Schienen und den damaligen Zügen. Inzwischen baue ich meine Züge selbst. Ein Teil der Züge wird über das 9 Volt System mit Trafo/Steuerpult von Lego und ein Teil über China-PF gesteuert. Seit ca. 3 Jahren bin ich in Rente und habe nun beim Stöbern im Netz “Mattzobricks” entdeckt. Ich war sofort Feuer und Flamme für die Idee meine Loks mit dem Computer zu steuern. Zumal ich diese Überlegung schon einmal hatte. Ich wollte es damals über eine Digitalzentrale zu realisieren. Dies scheiterte aber wie so oft ein wenig am “Taschengeld”.

      Mein Ziel ist im ersten Schritt alle Lokomotiven mit Controllern auszustatten, die es erlauben neben Regelung der Geschwindigkeit und Fahrtrichtung das Licht ein- und auszuschalten. Alles Weitere ist erst einmal Zukunftsmusik.

      Ein etwas älteres Laptop (Win10) und eine ausrangierte Fritz!Box sind vorhanden. Alles weiter Erforderliche habe ich anhand der Materialliste eingekauft und einfach angefangen.

      Ich gehöre zu der Kategorie Mensch “interessierter Laie” oder wie Ihr es formuliert „with very little specific knowledge about those things“ (den Status kann man irgendwann bestimmt einmal ändern) und habe nicht viel Ahnung von Elektronik. Also hat es ein wenig gedauert bis ich etwas Brauchbares zustande bekommen habe. Aber nun funktioniert es – zum Teil wenigstens.

      So jetzt zu meinen Fragen/Problemen.

      Ich habe Rocrail und Mosqitto installiert und nach Anleitung konfiguriert sowie einen Testaufbau auf einem Breadboard erstellt.

      Als Grundlage habe ich die Schaltung aus dem Bereich https://mattzobricks.com/de/automation/train-automation/mtc4pf verwendet. Den Code habe ich aus der Datei „controler_config.h“ entnommen Ihn angepasst und um die Lichtsteuerung aus der Datei “MTC4PF_conv_MAE.h“ ergänzt/angepasst.

      Die Motorsteuerung funktioniert inzwischen einwandfrei.
      Die Lichtschaltung leider nicht.

      Nun experimentiere ich seit Tagen herum. Habe alle Anleitungen nochmals studiert und das Forum rauf-und runtergelesen. Leider ohne Erkenntnis. Das Forumsmitglied Stefan Krebber hatte in 2023 im Allgemeinen Bereich, so habe ich den Forenbeitrag interpretiert, wohl ein gleiches/ähnliches Problem. Er hat den Fehler gefunden aber die Lösung leider für sich behalten.Schade.

      Nun stehe ich vor dem Problem, dass die Beleuchtung meiner Testlok „dunkel“ ist. Damit das nicht so bleibt bitte ich um Hilfe.

      Welchen Fehler habe ich im System? Was muss am Code korrigiert werden? Was muss ggf. in Rocrail ergänzt/geändert werden?

      Viele Grüsse aus dem schönen Schaumburger Land in Niedersachsen

      und vielen Dank für Eure Hilfe im Voraus

      P.S. Gibt es vielleicht jemanden in meine örtlichen Umfeld ( ist natürlich eine Frage der Entfernung), dem ich mal über die Schulter schauen kann?

      Dies ist der Code, den ich erstellt habe:

      #include “MTC4PF.h”

      // Author: Dr. Matthias Runte
      // Copyright 2020 by Dr. Matthias Runte
      // License:
      // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
      // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
      // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

      // This file is the configuration file for the firmware
      // You need to adapt it to the specific requirements of the desired behaviour of the controller
      // The file contains default values for the standard wiring layout of the MattzoLayoutController
      // Check the examples in the “examples” directory for more inspiring creations

      // ************************************************
      // Example file for a simple train with MTC4PF mini
      // ************************************************

      // *****
      // LOCOS
      // *****

      // Number of locos (aka. MattzoLocos) controlled by this controller
      const int NUM_LOCOS = 1;

      // List of MattzoLocos
      // The parameters have the following meaning:
      // – locoName: name of the loco as setup in Rocrail
      // – locoAddress: address of the loco as setup in Rocrail
      // – accelerationInterval: time interval for acceleration / braking (default: 100 ms)
      // – accelerateStep: power increment for each acceleration step
      // – brakeStep: : power decrement for each braking step
      MattzoLocoConfiguration* getMattzoLocoConfiguration() {
      static MattzoLocoConfiguration locoConf[NUM_LOCOS];

      locoConf[0] = {
      .locoName = “BR24”,
      .locoAddress = 9990,
      .accelerationInterval = 100,
      .accelerateStep = 2,
      .brakeStep = 10
      };

      return locoConf;
      }

      // *************
      // MOTOR SHIELDS
      // *************
      // Number of motor shields connected to this controller
      const int NUM_MOTORSHIELDS = 1;

      // List of motor shields that are controlled by this controller
      // The parameters have the following meaning:
      // – locoAddress: loco that this motor shields is attached to
      // – motorShieldType: motor shield type
      // – L298N_enA, L298N_enB: PWM signal pin for motor A / B, if L298N is used.
      // – in1..in4: pin for motor direction control for motor shields L298N and L9110 (in1: forward motor A, in2: reverse motor A, in3: forward motor B, in4: reverse motor B).
      // – minArduinoPower: minimum power setting for Arduino based motor shields. You might need to adapt this to your specific shield and motor. 200 might be a good value for a start.
      // – maxArduinoPower: maximum power setting for Arduino based motor shields (max. 1023). You might need to adapt this to your specific shield and motor. 400 might be a good value for a start.
      // – configMotorA: turning direction of motor A (1 = forward, -1 = backward, 0 = unused). In case of LEGO IR Receiver 8884, this is the motor connected to the red port.
      // – configMotorB: same for motor B; if IR receiver: blue port
      // – irChannel: if a LEGO IR Receiver 8884 is used, the selected channel of the receiver. May be 0, 1, 2 or 3. If the loco uses multiple IR receivers on different channels, additional motor shields for the loco are required.
      MattzoMotorShieldConfiguration* getMattzoMotorShieldConfiguration() {
      static MattzoMotorShieldConfiguration msConf[NUM_MOTORSHIELDS];

      msConf[0] = {
      .locoAddress = 9990,
      .motorShieldType = MotorShieldType::L9110,
      .L298N_enA = 0,
      .L298N_enB = 0,
      .in1 = D3,
      .in2 = D4,
      .in3 = 0,
      .in4 = 0,
      .minArduinoPower = 0,
      .maxArduinoPower = 255,
      .configMotorA = 1,
      .configMotorB = 0,
      .irChannel = -1
      };

      return msConf;
      }

      // *************************
      // TRAIN LIGHT CONFIGURATION
      // *************************

      // Number of train lights controlled by this controller
      #define NUM_TRAIN_LIGHTS 2

      TTrainLightConfiguration trainLightConfiguration[NUM_TRAIN_LIGHTS] =
      {
      {
      // D1
      .trainLightType = TrainLightType::ESP_OUTPUT_PIN,
      .pin = D1,
      .motorShieldIndex = 0, // has no meaning
      .motorPortIndex = 0, // has no meaning
      .powerLevelOff = 0,
      .powerLevelOn = 300
      },
      {
      // D2
      .trainLightType = TrainLightType::ESP_OUTPUT_PIN,
      .pin = D2,
      .motorShieldIndex = 0, // has no meaning
      .motorPortIndex = 0, // has no meaning
      .powerLevelOff = 0,
      .powerLevelOn = 300
      },
      };

      // ******************************
      // FUNCTION MAPPING CONFIGURATION
      // ******************************

      // Rocrail functions are used to MANUALLY switch train lights on and off

      // Number of function mappings
      #define NUM_FUNCTION_MAPPINGS 4

      TLocoFunctionMappingConfiguration locoFunctionMappingConfiguration[NUM_FUNCTION_MAPPINGS] =
      {
      {
      .locoAddress = 9990,
      .fnNo = 1,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      .locoAddress = 9990,
      .fnNo = 1,
      .fnOnOff = false,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      .locoAddress = 9990,
      .fnNo = 2,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      .locoAddress = 9990,
      .fnNo = 2,
      .fnOnOff = false,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },
      };

      // *********************************
      // TRAIN LIGHT TRIGGER CONFIGURATION
      // *********************************

      // Triggers are used to AUTOMATICALLY switch train lights on and off

      // Number of train light triggers as defined just below
      #define NUM_TRAIN_LIGHT_TRIGGERS 0

      TTrainLightTriggerConfiguration trainLightTriggerConfiguration[NUM_TRAIN_LIGHT_TRIGGERS] = {};

      // ************************
      // CONTROLLER CONFIGURATION
      // ************************

      // Configuration for motorshield type Lego IR Receiver 8884
      const uint8_t IR_LED_PIN=D5; // pin on which the IR LED is installed that controls all attached Lego IR Receiver 8884s.

      // Digital output pin to monitor controller operation (typically a LED)
      // Set to false if no status LED is installed
      const bool STATUS_LED_PIN_INSTALLED = true;
      // If installed, the pin controlling the status LED
      const uint8_t STATUS_LED_PIN = D8;
      // If installed, set to true to flip high/low state of the status led pin
      const bool STATUS_LED_REVERSE = false;
      // Power level of the status LED (0..1023)
      // Recommended max. power levels: white: 800, blue: 600, green: 500, yellow: 350, red: 300
      const int STATUS_LED_POWER = 300;

      // Report battery level
      #define REPORT_BATTERYLEVEL false // set to true or false to allow or omit battery level reports
      #define SEND_BATTERYLEVEL_INTERVAL 60000 // interval for sending battery level in milliseconds
      #define BATTERY_PIN A0
      const int VOLTAGE_MULTIPLIER = 20000 / 5000 – 1; // Rbottom = 5 kOhm; Rtop = 20 kOhm; => voltage split factor
      #define MAX_AI_VOLTAGE 5100 // maximum analog input voltage on pin A0. Usually 5000 = 5V = 5000mV. Can be slightly adapted to correct small deviations

      // ****************
      // NETWORK SETTINGS
      // ****************

      // Trigger emergency brake upon disconnect
      const bool TRIGGER_EBREAK_UPON_DISCONNECT=true;

      // WiFi Hostname
      // Hostnames must start with a-z, A-Z, 0-9. From 2nd character, hyphens (“-“) may also be used
      const char* MC_HOSTNAME = “MTC4PF-BR24”;

      // Syslog application name
      const char* SYSLOG_APP_NAME = “MTC4PF-BR24”;

    • #8520
      Matthias RunteMatthias Runte
      Administrator

      Die Konfiguration sieht auf den ersten Blick nicht schlecht aus. Kannst Du mal den Controller an den Rechner anschließen, F1 oder F2 in Rocrail drücken und das Serial Log posten? Kommen die FN-Events durch? Sonst teste mal bitte, ob die LEDs funktionieren und richte angeschlossen sind (z.B. mit einem einfachen, angepassten Arduino Blink-Sketch).

      • #8521
        Andreas BrockmeyerAndreas Brockmeyer
        Teilnehmer

        Hallo Matthias
        vielen Dank für die schnelle Antwort.
        Die LEDS sind offensichtlich i.O.
        Habe den Controler per USB an das Notebook auf dem Rocrail läuft angeschlossen. F1 und F2 gedrückt.
        Lach mich bitte jetzt nicht aus. Ich bin wirklich Laie. Wie finde ich das Seral Log?

    • #8522
      Matthias RunteMatthias Runte
      Administrator

      https://mattzobricks.com/automation/controllers/general -> “The Serial Monitor”

      Der Abschnitt ist etwas veraltet, da wir die Arduino IDE nicht mehr verwenden. In Visual Studio (genauer: PlatformIO) ist auch ein Serial Monitor. Dazu ganz unten auf das Stecker-Symbol klicken (Tooltip: PlatformIO: Serial Monitor).

      • #8523
        Andreas BrockmeyerAndreas Brockmeyer
        Teilnehmer

        Hallo Matthias
        Vielen Dank für Deine Geduld.
        Im Serial Monitor der Arduino IDE sehe ich nur Hieroglyphen.
        In VS-Code steht folgendes:

        * Task wird im Ordner MTC4PF ausgeführt: C:\Users\reyem\.platformio\penv\Scripts\platformio.exe device monitor

        — Terminal on COM3 | 115200 8-N-1
        — Available filters and text transformations: colorize, debug, default, direct, esp8266_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
        — More details at https://bit.ly/pio-monitor-filters
        — Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
        ��␃�␛�o�r��o|�␄l␌�␌l ␃␜c�␛␂␄�|␂r�␂l�o�␄�o�␃␄d`␂��{�d�$␒�␄␌␌�
        MattzoController booting…
        Loaded mattzoControllerId from EEPROM: 47685
        Connecting as MTC4PF-Lok1 to Wifi LegoLoco
        MattzoController setup completed.
        stopping all locos
        Setting train speed 0 (power: 0) for motor shield index 0
        setMotorShieldPower() called with msi=0, mpi=0, desiredPower=0
        Wifi connected. My IP address is 192.168.178.21.
        (Re)connecting to MQTT 192.168.178.20…
        MQTT connected, listening on topic [rocrail/service/command].
        No action found for loco address 9990, fn2, state=0
        No action found for loco address 9990, fn1, state=1
        No action found for loco address 9990, fn1, state=0
        No action found for loco address 9990, fn2, state=1

    • #8524
      Matthias RunteMatthias Runte
      Administrator

      Wunderbar. Dein Controller empfängt die Button-Klicks auf F1 und F2, aber er findet kein Mapping zu den LEDs auf D1 und D2.

      Bitte:
      1. Schalte mal in der network_config.h den debug mode für das serial log ein (const int LOGLEVEL_SERIAL = LOG_INFO;). Was gibt das Serial Log jetzt aus?
      2. Prüfe bitte einmal, ob die controller_config.h Datei, die wie gesagt aus meiner Sicht eigentlich gut aussieht, wirklich im richtigen Verzeichnis liegt, so dass der Compiler sie beim Kompilieren auch findet und verwendet.

      • #8525
        Andreas BrockmeyerAndreas Brockmeyer
        Teilnehmer

        Hallo Matthias
        zu 1.
        der debug mode für das serial log sieht für mich aktiv aus. Ich habe im Vergleich zu Deiner controler_config.h Datei an diesen Einstellungen nichts verändert. Oder muss ich da noch weitere Eingaben machen?.

        die network_config.h Datei sieht so aus.
        ———————————
        #include “Syslog.h”

        // MattzoController Network Configuration
        // Author: Dr. Matthias Runte
        // Copyright 2020 by Dr. Matthias Runte
        // License:
        // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

        // This file contains the network configuration for the firmware
        // You need to adapt it to your specific network environment

        // *************
        // WiFi settings
        // *************

        // The SSID of your WiFi network
        const char* WIFI_SSID = “LegoLoco”;

        // The passphrase of your WiFi network
        const char* WIFI_PASSWORD = “66574790903040715323”;

        // *************
        // MQTT settings
        // *************

        // The IP address or hostname of the host on which your MQTT broker (e.g. mosquitto) is running.
        const char* MQTT_BROKER_IP = “192.168.178.20”;
        const int MQTT_BROKER_PORT = 1883;

        // MQTT keep alive interval (in seconds)
        const int MQTT_KEEP_ALIVE_INTERVAL = 10;

        // ************
        // Log settings
        // ************
        // The log levels are defined in Syslog.h of the Syslog library:
        // LOG_EMERG 0 /* system is unusable */
        // LOG_ALERT 1 /* action must be taken immediately */
        // LOG_CRIT 2 /* critical conditions */
        // LOG_ERR 3 /* error conditions */
        // LOG_WARNING 4 /* warning conditions */
        // LOG_NOTICE 5 /* normal but significant condition */
        // LOG_INFO 6 /* informational */
        // LOG_DEBUG 7 /* debug-level messages */
        // Log level for serial output. Only message with a priority of the log level or greater will be logged.

        const int LOGLEVEL_SERIAL = LOG_INFO;
        // Log level for syslog output. Only message with a priority of the log level or greater will be logged.
        const int LOGLEVEL_SYSLOG = LOG_INFO;
        // Set to true if syslog shall be enabled
        const bool SYSLOG_ENABLED = false;
        // IP address or hostname of the syslog server
        const char* SYSLOG_SERVER = MQTT_BROKER_IP;
        // Port of the syslog server
        const int SYSLOG_PORT = 514;

        // ************
        // OTA settings
        // ************

        // Password for over-the-air firmware updates
        // PLEASE CHANGE THE PASSWORD AND KEEP IT SECRET FROM EVIL PLAYMOBIL FANS!
        const char* OTA_PASSWORD = “reyemkcorb”;

        ———————————-

        zu 2.
        Meine MTC4PF_conf_BR24.h (eigentlich nur eine angepasste Kopie Deiner controller_config.h Datei) und network_config.h Datei liegen beide im Verzeichnis “my”

    • #8526
      Matthias RunteMatthias Runte
      Administrator

      1. (falls noch relevant)
      In der Datei “network_config.h” bitte die Zeile:

      const int LOGLEVEL_SERIAL = LOG_INFO;

      ändern in:

      const int LOGLEVEL_SERIAL = LOG_DEBUG;

      Ich denke, wir haben’s aber auch schon… denn:

      2.
      Die Controller-Konfigurationsdatei muss “controller_config.h” heißen und im “my” Verzeichnis liegen. Wenn das nicht so ist: lösch mal die bisherige und benenne die Datei “MTC4PF_conf_BR24.h” um in “controller_config.h”. Ich denke, dass es dann funktionieren sollte.

      • #8527
        Andreas BrockmeyerAndreas Brockmeyer
        Teilnehmer

        Hallo Matthias

        Daumen hoch ! Alles funktioniert. Du hast einen “interesierten Laien” und “blutigen Anfänger” glücklich gemacht. Jetzt kann ich meinen Testaufbau mal “zusammenlöten” und in die Lok einbauen. Die Geschwindigkeit muss ich noch neu einstellen. Mit den bisherigen Werte läuft er nicht mehr richtig. Das mache ich aber erst, wenn er in der Lok ist und diese fährt.

        Eine fachliche Frage habe ich aber doch noch. Warum darf ich die controller_config.h nicht in MTC4PF_conf_BR24.h umbenennen. Dann könnte ich sofort erkennen zu welcher Lok der Controller gehört. Deine Beispieldateien heissen doch auch anders.

        Unabhängig davon habe ich in den letzten Tagen viel dazugelernt. Ich hoffe, dass ich darauf aufbauen kann. Ich weiß ja jetzt, dass man hier im Forum von Dir die nötige Unterstützung erhält(brauche ich sicherlich irgendwann noch einmal).

        Vielen Dank nochmals.

        Viele Grüsse aus dem schönen Schaumburger Land in Niedersachsen

    • #8529
      Matthias RunteMatthias Runte
      Administrator

      Das liegt einfach an unserem Code. Siehe Datei “main.cpp” irgendwo in einem MTC4PF Unterverzeichnis. Die Dateinamen sind dort hartkodiert:

      #include “../conf/my/controller_config.h”
      #include “../conf/my/network_config.h”

      Ich habe ganz viele Lokomotiven, die alle unterschiedliche Konfigurationsdateien haben. Die liegen alle mit unterschiedlichen Dateinamen bei mir im “my” Verzeichnis. Diejenige, die ich gerade auf einen Controller aufspielen will, kopiere ich jeweils über die controller_config.h Datei und starte den Kompiler. Kann aber jeder machen wie er möchte, da gibt es sicherlich unterschiedliche Wege, die alle zum Ziel führen.

      Wir haben die weitere Abstraktion der Konfiguration vom Code projektiert. Ziel ist eine Webkonfiguration, so dass für die Konfiguration und Umkonfiguration die Firmware nicht mehr kompilieren muss. Er Controller muss nicht einmal mehr an den Computer angeschlossen sein, um die Konfiguration zu ändern. Uns fehlt aber derzeit die Zeit, das mal anzupacken.

      Noch viel Erfolg bei Deinen weiteren Bemühungen!

      • #8530
        Andreas BrockmeyerAndreas Brockmeyer
        Teilnehmer

        klingt einleuchtend. So werde ich es dann auch machen.

Ansicht von 5 Antwort-Themen
  • Du musst angemeldet sein, um auf dieses Thema antworten zu können.