Viewing 2 reply threads
  • Author
    Posts
    • #5219
      Todd BowersTodd Bowers
      Participant

      I set up multicolored LED’s under 0.4 firmware on one of my trains and was able to use the Function buttons in RocRail to turn on either red, blue or green and use the automatic lights while running. I updated to 0.5.1 and now I can only get F1 to light. When I checked to Serial Monitor, F1 shows pwm of 1023 (max), but F2 and F3 only will be 0 pwm when triggered. How can I fix this setting? Below is a copy of the Serial Monitor:

      Parsing XML successful
      <fn> node found. Processing fn message…
      function id: L7938
      addr: 7938
      Consuming message for train L7938 (7938)
      fnchanged: 1
      Function PIN Id: 0
      fnchangedstate (raw): true
      fnchangedstate: true
      Flipping function 1 to 1
      Setting PWM value of pin 16 to 1023
      Received MQTT message [rocrail/service/command]: <fn shift=”false” longclick=”false” group=”1″ fnchanged=”1″ fndesc=”F1″

      Parsing XML successful
      <fn> node found. Processing fn message…
      function id: L7938
      addr: 7938
      Consuming message for train L7938 (7938)
      fnchanged: 2
      Function PIN Id: 1
      fnchangedstate (raw): true
      fnchangedstate: true
      Flipping function 2 to 1
      Setting PWM value of pin 5 to 0
      Received MQTT message [rocrail/service/command]: <fn shift=”false” longclick=”false” group=”1″ fnchanged=”2″ fndesc=”F2″

      Todd

    • #5224
      Todd BowersTodd Bowers
      Participant

      I realized my error. I was using the wrong configuration file.

    • #5869
      Razvan AnghelRazvan Anghel
      Participant

      Hello everyone.

      In the last past days i’m struggling to config train light, but no success.
      I have following config:
      – hardware – MTC4PF with battery (ESP 8266 12E, and motor shield L298N)
      – two led (white and red) with common plus terminal. I soldered minus terminal of white to minus of wihte, for red the same
      – pin D0 to common minus white
      – pin D2 to common minus red
      – D3, D4 to L298N motor shield motor A
      – motor connected to PF motor A
      When train direction is in reverse red light is running normal (white is OFF). When train direction is FW or stop condition both light are ON.
      When hit F1 both light are ON, on F2 only red is ON.

      What i’m doing wrong?

      The config is this:

      // *****
      // 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] = (MattzoLocoConfiguration){
      .locoName = “BR103”,
      .locoAddress = 3,
      .accelerationInterval = 100,
      .accelerateStep = 5,
      .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
      // – maxArduinoPower: maximum power setting for Arduino based motor shields (max. 1023)
      // – 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];

      // Type of motor shield directly wired to the controller.
      // (The different motor shield types are defined in MTC4PF.ino)
      // Set to MotorShieldType::NONE if only virtual motor shields are used!
      const MotorShieldType MOTORSHIELD_TYPE = MotorShieldType::L9110;

      msConf[0] = (MattzoMotorShieldConfiguration){
      .locoAddress = 3,
      .motorShieldType = MotorShieldType::L9110,
      .L298N_enA = 0,
      .L298N_enB = 0,
      .in1 = D3,
      .in2 = D4,
      .in3 = 0,
      .in4 = 0,
      .minArduinoPower = MIN_ARDUINO_POWER,
      .maxArduinoPower = MAX_ARDUINO_POWER,
      .configMotorA = 1,
      .configMotorB = 0,
      .irChannel = -1
      };

      return msConf;
      }

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

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

      // List of train lights including their configuration
      struct TrainLightConfiguration {
      // Train light type. Either some light that is directly wired to the ESP, or a light connected to a Power Functions motor port
      TrainLightType trainLightType;
      // If light is directly wired to the ESP, the output pin; else: unused (set to -1)
      uint8_t pin;
      // If light in connected to motor shield: index of the motor shield. Usually 0 (the first and only one). Else: unused (set to -1)
      int motorShieldIndex;
      // If light in connected to motor shield: port A: 0; port B: 1. Else: unused (set to -1)
      // ATTENTION: if a light is connected to a motor port, the corresponding configMotorA / configMotorB parameter in the motorshield configuration must be 0!
      int motorPortIndex;
      // light intensity (0..MAX_ARDUINO_POWER) if light is switched off. Usually = 0.
      int powerLevelOff;
      // light intensity (0..MAX_ARDUINO_POWER) if light is switched on. Full bright = MAX_ARDUINO_POWER = 1023.
      int powerLevelOn;
      } trainLightConfiguration[NUM_TRAIN_LIGHTS] =
      {
      {
      // 0: head light / white
      .trainLightType = TrainLightType::ESP_OUTPUT_PIN,
      .pin = D0,
      .motorShieldIndex = 0,
      .motorPortIndex = -1,
      .powerLevelOff = 0,
      .powerLevelOn = MAX_ARDUINO_POWER,
      },
      {
      // 1: head light / red
      .trainLightType = TrainLightType::ESP_OUTPUT_PIN,
      .pin = D2,
      .motorShieldIndex = 0,
      .motorPortIndex = -1,
      .powerLevelOff = 0,
      .powerLevelOn = 850,
      },
      };

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

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

      // Number of function mappings
      #define NUM_FUNCTION_MAPPINGS 6

      // List of function mappings
      struct LocoFunctionMappingConfiguration {
      int locoAddress;
      uint8_t fnNo;
      bool fnOnOff;
      int trainLightIndex;
      TrainLightStatus trainLightStatus;
      } locoFunctionMappingConfiguration[NUM_FUNCTION_MAPPINGS] =
      {
      // fn1: forward mode. head lights red
      {
      // head lights white off
      .locoAddress = 3,
      .fnNo = 1,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red on
      .locoAddress = 3,
      .fnNo = 1,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::ON
      },

      // fn2: backwards mode. head lights white
      {
      // head lights white on
      .locoAddress = 3,
      .fnNo = 2,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      // head lights red off
      .locoAddress = 3,
      .fnNo = 2,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },

      // fn3: head lights off
      {
      // head lights white off
      .locoAddress = 3,
      .fnNo = 3,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red off
      .locoAddress = 3,
      .fnNo = 3,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },
      };

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

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

      // Number of function mappings
      #define NUM_FUNCTION_MAPPINGS 6

      // List of function mappings
      struct LocoFunctionMappingConfiguration {
      int locoAddress;
      uint8_t fnNo;
      bool fnOnOff;
      int trainLightIndex;
      TrainLightStatus trainLightStatus;
      } locoFunctionMappingConfiguration[NUM_FUNCTION_MAPPINGS] =
      {
      // fn1: forward mode. head lights red
      {
      // head lights white off
      .locoAddress = 3,
      .fnNo = 1,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red on
      .locoAddress = 3,
      .fnNo = 1,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::ON
      },

      // fn2: backwards mode. head lights white
      {
      // head lights white on
      .locoAddress = 3,
      .fnNo = 2,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      // head lights red off
      .locoAddress = 3,
      .fnNo = 2,
      .fnOnOff = true,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },

      // fn3: head lights off
      {
      // head lights white off
      .locoAddress = 3,
      .fnNo = 3,
      .fnOnOff = true,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red off
      .locoAddress = 3,
      .fnNo = 3,
      .fnOnOff = true,
      .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 6

      // List of train light triggers
      struct TrainLightTriggerConfiguration {
      int locoAddress; // set to 0 to indicate “all locos”
      LightEventType lightEventType;
      int trainLightIndex;
      TrainLightStatus trainLightStatus;
      } trainLightTriggerConfiguration[NUM_TRAIN_LIGHT_TRIGGERS] =
      {
      // forward mode. head lights red
      {
      // head lights white off
      .locoAddress = 3,
      .lightEventType = LightEventType::FORWARD,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red on
      .locoAddress = 3,
      .lightEventType = LightEventType::FORWARD,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::ON
      },

      // backward mode. head lights white
      {
      // head lights white on
      .locoAddress = 3,
      .lightEventType = LightEventType::REVERSE,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      // head lights red off
      .locoAddress = 3,
      .lightEventType = LightEventType::REVERSE,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },

      // this section may be commented out to prevent the head and rear lights from being switched off upon stop
      // stop: head lights off
      {
      // head lights white off
      .locoAddress = 3,
      .lightEventType = LightEventType::STOP,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red off
      .locoAddress = 3,
      .lightEventType = LightEventType::STOP,
      .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 6

      // List of train light triggers
      struct TrainLightTriggerConfiguration {
      int locoAddress; // set to 0 to indicate “all locos”
      LightEventType lightEventType;
      int trainLightIndex;
      TrainLightStatus trainLightStatus;
      } trainLightTriggerConfiguration[NUM_TRAIN_LIGHT_TRIGGERS] =
      {
      // forward mode. head lights red
      {
      // head lights white off
      .locoAddress = 3,
      .lightEventType = LightEventType::FORWARD,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red on
      .locoAddress = 3,
      .lightEventType = LightEventType::FORWARD,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::ON
      },

      // backward mode. head lights white
      {
      // head lights white on
      .locoAddress = 3,
      .lightEventType = LightEventType::REVERSE,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::ON
      },
      {
      // head lights red off
      .locoAddress = 3,
      .lightEventType = LightEventType::REVERSE,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },

      // this section may be commented out to prevent the head and rear lights from being switched off upon stop
      // stop: head lights off
      {
      // head lights white off
      .locoAddress = 3,
      .lightEventType = LightEventType::STOP,
      .trainLightIndex = 0,
      .trainLightStatus = TrainLightStatus::OFF
      },
      {
      // head lights red off
      .locoAddress = 3,
      .lightEventType = LightEventType::STOP,
      .trainLightIndex = 1,
      .trainLightStatus = TrainLightStatus::OFF
      },
      };

Viewing 2 reply threads
  • You must be logged in to reply to this topic.