Welcome to MattzoBricks › Forums › MattzoLayoutController (MLC) › MLC with Port Extender 9685
- This topic has 5 replies, 2 voices, and was last updated 1 year, 8 months ago by Matthias Runte.
-
AuthorPosts
-
-
February 18, 2023 at 22:35 #5944Dave GParticipant
Hi all,
Apologies for the long first post but I promise I’ve read the website and forum posts again and again and I’m stuck!
My daughter and I have been building our Lego layout and we think that MattzoBricks is the perfect next step in our project.
We have been loving our first attempts at building an MLC (just the standard version) alongside RocRail and feel like we have the hang of the very basics.
My question is what am I doing wrong when I have added a port extender – a PCA9685 with just one switch for testing.
I am confident both the 8266 and 9685 are getting the correct voltage/current at around 5v, 2a. I don’t think either the 8266 or 9685 themselves are faulty as have tested on second (and third!) boards.
I know that mosquito and RocRail are communicating with the 8266 MLC and that this is sending a signal to the joined 9685 as I rigged up a testing light like Matthias did on his double slip switch example on the MLC General page. This LED lights when waiting for a command and then goes out when a command is received. Again, I’m fairly confident in this as when I map a switch port in RocRail that does not correspond to one in the VScode, the status LED connected to D0 alongside the 0E does not blink.
To make sure I hadn’t messed the code up too much, I then deleted my version and copied the conf_mega.h into the ‘my’ variant of the controller_config.h in case I had made any mistakes. I am thinking that the line that states [Servos connected to PCA9685 must be mapped in SWITCHPORT_PIN_PCA9685] suggests that I should be changing something somewhere else but I really don’t know where if so! I have mapped the pin types to 0x40 as well as checked the RR mapping address.
This is all very new to me so please go slow – I’m hoping it’s something really obvious that I’ve missed!
What an amazing project, thank you Matthias and team!!
Dave
-
February 20, 2023 at 20:30 #5947Matthias RunteKeymaster
Hi Dave,
great to have you here and thanks for the compliments.My suggestion is to try flipping a switch without the port extender first. These devices can be a bit tricky, and it is good to check if everything works fine just with the ESP8266 first, as you can sort our a lot of problem sources then. If you do not get it to work, my next move would be to try to control a light signal instead of a switch first, as playing around with LEDs comes with fewer electrical problem sources compared to controlling servos.
It is also a good idea to switch debugging on (network_config.h, const int LOGLEVEL_SERIAL = LOG_DEBUG;), and have the MLC connected to the USB port of your computer while debugging. You can see the serial log by pressing the little connector icon in the icon / status bar on the bottom of VSCode.
Good luck, sorry for my bad English and let us know how it goes. When you have nailed down the problem more specifically, we might be able to help you better.
Cheers,
Mattze -
February 27, 2023 at 19:36 #6050Matthias RunteKeymaster
Relaying a message from Dave:
I have the standard MLC working (no 9685) with switches, sensors and signals attached but I’m still having difficulty with the 9685 port extension version.
I can get four switch motors to successfully work with it (pin 0, 1, 2 and 3) but none on any other pin banks. Signals are also not working with the 9685. The debug shows that the switches are receiving the command from RocRail (I think!) and it is showing a connection to the pins but the servo connected to pin 7 (rr map 8) does not move. I have tried another servo motor to check if it is faulty and that wasn’t it.
Likewise, the signals show as if they’re receiving commands but they also seem to be trying to connect to ports other than that which I designated in the configuration code. I have two LEDs wired up to pins 4 and 5 (rr map 1 and 2) and they remain on fully despite aspect changing in RocRail.
I have pasted the debug console and my controller_config file too if you can lend an expert eye to see where I’m going wrong please!
DEBUG Console
* Executing task: C:\Users\dgord\.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
rl␀l r␂$␒ n␌␌␌ ␌l ␌b| ␂␇␒ r␒b ␌b␄ nn␂lnn b␌b␜p $b␎lrlp n ␂␌␌ ␌l␌ ␂␌␌␌b␌n n ␌ ␌␄b nn’l ␄l␂ ␒␒nn␌l
␂␎␂nr n␌␌bl␂p n␐␂␌␌r ␜␜b␌␄␂␌b␌n n␌␄␌b nn'␌␌l
␂ ␒␒nn␌l␂␎␂nr n␌␌b␄
␂␎r n␌␌b␄␂ ␂␌␌l $␌␂l
␂ n `␂
MattzoController booting…
Loaded mattzoControllerId from EEPROM: 22087
Connecting as MLC-22087 to Wifi GC
.
MattzoController setup completed.
Wifi connected. My IP address is 192.168.1.156.
(Re)connecting to MQTT 192.168.1.159…
MQTT connected, listening on topic [rocrail/service/command].
Sending MQTT message:
Sending MQTT message:
States of all physical sensors sent to MQTT.
Flipping switch index 3 to angle 88
Turning servo index 1 to angle 88
Attaching servo index 1 to PCA9685 PWM signal.
Flipping switch index 3 to angle 77
Turning servo index 1 to angle 77
Attaching servo index 1 to PCA9685 PWM signal.
Detached servo index 1 from PCA9685 PWM signal.
Flipping switch index 4 to angle 90
Turning servo index 2 to angle 90
Attaching servo index 2 to PCA9685 PWM signal.
Detached servo index 2 from PCA9685 PWM signal.
Flipping switch index 2 to angle 76
Turning servo index 0 to angle 76
Attaching servo index 0 to PCA9685 PWM signal.
Detached servo index 0 from PCA9685 PWM signal.
Flipping switch index 1 to angle 87
Turning servo index 3 to angle 87
Attaching servo index 3 to PCA9685 PWM signal.
Detached servo index 3 from PCA9685 PWM signal.
Flipping switch index 0 to angle 60
Turning servo index 7 to angle 60
WARNING: servo index 7 out of range!
Setting signal index 0 to aspect 1 (maps with rr port 2)
Setting signal LED index 0 of signal 0 to off
Setting signal LED index 1 of signal 0 to on
Setting signal index 0 to aspect 0 (maps with rr port 1)
Setting signal LED index 0 of signal 0 to on
Setting signal LED index 1 of signal 0 to offmy controller_config.h
// *********************
// COPYRIGHT AND LICENSE
// *********************// 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.// *****************
// PURPOSE AND USAGE
// *****************// MattzoLayoutController (MLC) example configuration file
// Usage: copy it onto the conf/my/controller_config.h file and adapted it to your needs
// Documentation: https://www.mattzobricks.com// This configuration is the default configuration for the MLC.
// It serves 4 switches, 1 standard light signal, and 2 sensors.// *******************************
// CONTROLLER WIRING CONFIGURATION
// *******************************// PCA9685 WIRING CONFIGURATION
// Infos for output port expander PCA9685
// Usage:
// – If a USE_PCA9685 port expander is connected to your ESP8266, set USE_PCA9685 to true. Else, it must be set to false.
// Wiring:
// – PCA9685 is usually connected to pins D1 (clock) and D2 (data) of the ESP8266.
// – VCC is sourced from V3V of the ESP8266.
// – V+ is sourced from VIN of the ESP8266
// — VIN should be between 5 and 6 Volts.
// — According to the documentation, the PCA9685 will also sustain 12V, but this is not recommended and we have not tested it.
// — We have tested run the board with standard USV voltage (4,65V) and it worked without problems.
// – Connecting GND is mandatory.
// – OE should also be connected. If pulled high, servo power is switched off. Good to preserve your servos. Cabling is usually easiest if pin D0 is used as OE.
// Chaining:
// – Both PCA9685 and the firmware support chaining.
// – Board 1 has the address 0x40, Board 2 0x41 etc.
// Servos:
// – Just connect the servos as designed. Servos connected to PCA9685 must be mapped in SWITCHPORT_PIN_PCA9685.
// Signals:
// – Connecting TrixBrix signals to the PCA9685 is somewhat tricky, because of the “common anode” (common plus terminal) of the signal LEDs.
// – The solution is to connect the middle wire (plus) to V3V of the ESP8266 (NOT the plus pins of the PCA9685 ports), and the outer wires to the PCA9685 pins.
// – It is important to remember the correct way of setting a pin on the PCA9685 to:
// — fully on: pwm.setPWM(port, 4096, 0);
// — fully off: pwm.setPWM(port, 0, 4096);
// – Generally, it is better practice to connect light signals via MCP23017 port extenders
// Additional reference: https://learn.adafruit.com/16-channel-pwm-servo-driver?view=all// PCA9685 port expander used?
#define USE_PCA9685 true// PCA9685 OE pin supported?
#define PCA9685_OE_PIN_INSTALLED false
const uint8_t PCA9685_OE_PIN = D0;// Number of chained PCA9685 port extenders
#define NUM_PCA9685s 1// MCP23017 WIRING CONFIGURATION
// Infos for I/O port expander MCP23017
// Usage:
// – If a MCP23017 I/O port expander is connected to your ESP8266, set USE_MCP23017 to true.
// Wiring:
// – SCL and SDA are usually connected to pins D1 (clock) and D2 (data) of the ESP8266.
// – VCC is sourced from V3V of the ESP8266.
// – GND is connected to GND of the ESP8266. Connecting GND is mandatory!
// – RESET is connected with an 10K resistor to VCC
// – Address ports A0, A1 and A2 according to the desired address (0x20, 0x21, …). All connected to GND means address 0x20.
// Ports:
// – The ports of the are numbered as follows:
// – A0..A7: 0..7
// – B0..B7: 8..15
// Chaining:
// – Both MCP23017 and the firmware support chaining.
// – Board 1 has the address 0x20, board 2 0x21 etc.
// – Up to 8 boards can be connected.
// Sensors:
// – Connecting sensors to the MCP23017 is simple.
// – Just connect one of of the cable pair to GND, the other one to one of the ports of the MCP23017.// MCP23017 port expander used?
#define USE_MCP23017 false// Number of chained MCP23017 port extenders
#define NUM_MCP23017s 1// SERVO WIRING CONFIGURATION
// Servos are used for motorizing switches and form signals
// Number of servos
#define NUM_SERVOS 5TServoConfiguration servoConfiguration[NUM_SERVOS] =
{
{
.pin = 7,
.pinType = 0x40,
.detachAfterUsage = true
},
{
.pin = 3,
.pinType = 0x40,
.detachAfterUsage = true
},
{
.pin = 0,
.pinType = 0x40,
.detachAfterUsage = true
},
{
.pin = 1,
.pinType = 0x40,
.detachAfterUsage = true
},
{
.pin = 2,
.pinType = 0x40,
.detachAfterUsage = true
}};
// LED WIRING CONFIGURATION
// LEDs are used in signals, level crossing lights or bascule bridge lights
// As an example, 2 LEDs are required for a light signal with 2 aspects// Number of LEDs
#define NUM_LEDS 2TLEDConfiguration ledConfiguration[NUM_LEDS] =
{
{
.pin = 4,
.pinType = 0x40
},
{
.pin = 5,
.pinType = 0x40
}
};// SENSOR WIRING CONFIGURATION
// Sensors are generally used to indicate that a train have reached a specific position on the layout
// Special forms are remote and virtual sensors (see below)// Number of sensors connected or connectable to the controller
#define NUM_SENSORS 2// A special form of a sensor is the “remote sensor”
// Remote sensors are not electrically connected to this controller, they are triggered via Rocrail commands.
// Remote sensors can be used for level crossings in Autonomous Mode.
// Set REMOTE_SENSORS_ENABLED to true to generally enable remote sensors.
// If you do not control a level crossing in Autonomous Mode with this controller, set to false!
#define REMOTE_SENSORS_ENABLED falseTSensorConfiguration sensorConfiguration[NUM_SENSORS] =
{
{
.pin = D6,
.pinType = LOCAL_SENSOR_PIN_TYPE,
.remoteMattzoControllerId = -1
},
{
.pin = D7,
.pinType = LOCAL_SENSOR_PIN_TYPE,
.remoteMattzoControllerId = -1
}
};// STATUS LED WIRING CONFIGURATION
// 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 = true;// ****************************
// LOGICAL OBJECT CONFIGURATION
// ****************************// SWITCH CONFIGURATION
// Number of switches
#define NUM_SWITCHES 5TSwitchConfiguration switchConfiguration[NUM_SWITCHES] =
{
{
.rocRailPort = 8,
.servoIndex = 7,
.servo2Index = -1,
.servo2Reverse = false,
.triggerSensors = false,
.sensorIndex = { -1, -1 }
},
{
.rocRailPort = 4,
.servoIndex = 3,
.servo2Index = -1,
.servo2Reverse = false,
.triggerSensors = false,
.sensorIndex = { -1, -1 }
},
{
.rocRailPort = 1,
.servoIndex = 0,
.servo2Index = -1,
.servo2Reverse = false,
.triggerSensors = false,
.sensorIndex = { -1, -1 }
},
{
.rocRailPort = 2,
.servoIndex = 1,
.servo2Index = -1,
.servo2Reverse = false,
.triggerSensors = false,
.sensorIndex = { -1, -1 }
},
{.rocRailPort = 3,
.servoIndex = 2,
.servo2Index = -1,
.servo2Reverse = false,
.triggerSensors = false,
.sensorIndex = { -1, -1 }
}
};// SIGNAL CONFIGURATION
// Number of signals
#define NUM_SIGNALS 1
// Maximum number of signal aspects (e.g. 2 for red/green, 3 for red/green/yellow etc.)
#define NUM_SIGNAL_ASPECTS 2
// Number of signal LEDs (usually equal to NUM_SIGNAL_ASPECTS)
#define NUM_SIGNAL_LEDS 2
// Maximum number of servos for form signals (e.g. one for the primary and another one for the secondary semaphore)
// If no form signals are used, just set to 0
#define NUM_SIGNAL_SERVOS 0TSignalConfiguration signalConfiguration[NUM_SIGNALS] =
{{
.aspectRocrailPort = {1, 2},
.aspectLEDPort = {4, 5},
.aspectLEDMapping = {
{true, false},
{false, true}},
.servoIndex = {},
.aspectServoAngle = {},
.overshootSensorIndex = -1
}
};// LEVEL CROSSING CONFIGURATION
// General switch for level crossing (false = no level crossing connected; true = level crossing connected)
#define LEVEL_CROSSING_CONNECTED false// Number of boom barrier servos configured for the level crossing
#define LC_NUM_BOOM_BARRIERS 4// Number of signals configured for the level crossing
#define LC_NUM_LEDS 4// Number of level crossing sensors
#define LC_NUM_SENSORS 4// Number of tracks leading over the level crossing
#define LC_NUM_TRACKS 2TLevelCrossingConfiguration levelCrossingConfiguration = {};
// BASCULE BRIDGE CONFIGURATION
// General switch for bascule bridge (false = no bridge connected; true = bridge connected)
#define BASCULE_BRIDGE_CONNECTED false// Number of bridge Leafs (equals number of bridge servos)
#define NUM_BASCULE_BRIDGE_LEAFS 0TBridgeConfiguration bridgeConfiguration = {};
// SPEEDOMETER CONFIGURATION
// General switch for speedometer (false = no speedometer connected; true = speedometer connected)
#define SPEEDOMETER_CONNECTED falseTSpeedometerConfiguration speedometerConfiguration = {};
// ****************
// NETWORK SETTINGS
// ****************// Trigger emergency brake upon disconnect
const bool TRIGGER_EBREAK_UPON_DISCONNECT = true;// WiFi Hostname
// Allowed characters: a-z, A-Z, 0-9. From 2nd character, hyphens (“-“) may also be used.
const char *MC_HOSTNAME = “MLC”;// Syslog application name
const char *SYSLOG_APP_NAME = “MLC”; -
February 27, 2023 at 19:37 #6051Matthias RunteKeymaster
Hi Dave,
it’s great that you pasted the debug console output and your config file.To fix the servo problem, please find this line:
.servoIndex = 7,
and replace the 7 with a 4.
.servoIndex = 4,
To fix the signals, you need to replace this line:
.aspectLEDPort = {4, 5},
so that it looks like this:
.aspectLEDPort = {0, 1},
The reason is that you need to refer from the logical component (switch, signal) to the zero-based index of the array of the physical component (servo, LED).
Hope this fixes your issues.
-
February 28, 2023 at 08:08 #6053Matthias RunteKeymaster
Another message from Dave:
Thanks Matthias, your suggestion solved the issue and your explanation also helped me to understand how the process works too – seems obvious now!
After making the necessary changes, happy to confirm that it works and I’ve put another switch servo and signal in too, just to check!
-
February 28, 2023 at 08:08 #6054Matthias RunteKeymaster
Happy to hear that!
-
-
AuthorPosts
- You must be logged in to reply to this topic.