Skip to main content

Reply to "Layout Automation Using Layout Command Control, LCC, and ESP32"

I look forward to seeing how this one progresses.  

A couple of thoughts here:  First, if you go with the ESP32, there is little reason to use CAN bus in the project as you already have a powerful WiFi system in place.  My suggestion would be to write the software in a way that updates a 'data' page on a web server connected to, or hosted on, the computer, then all nodes check that page every 100ms or so for updates.  Someone much more skilled in web design than I am could probably figure out how to send push notifications to individual clients, but I don't know how to do that so just polling every 100ms seems easier, and is plenty fast enough for turning on and off lights and switch machines.  

Another thing to consider is a combination of the ESP32 and Arduino depending on the application.  The ESP32 is a fantastic device, but it works fundamentally different than a proper micro controller like an Arduino, and it may be easier to use the Arduino for some tasks. There's also the ESP8266 which is much less expensive, but has less capabilities.  In both ESP models, these are stack processors, and the more you have them doing, the worse they are at it.  Timings can be affected when you go to fetch web data and the like, because they can only actually do one thing at a time, as opposed to a uP that can keep something happening in the background while processing a new command.  

If you're planning to run wires from one controller to all your switches, one Arduino Mega2560 ($10) will give you 15 PWM I/O's that can be used to control servos, and 54 GPIOs if you can get by with relays or dome other on/off device on the output( triacs FETs, etc).  Pre-made boards with 16 10 amp relays can be had for less than $15.  

on the other hand, if you want to have each switch machine able to be wireless aside from track power, you're better off with the ESP8266 here, as it will process simple tasks quite well and costs about 1/4 of what an ESP32 does.  (about $2 each)  The ESP8266 doesn't have hardware PWM, but it will support software implementation. It has one ADC, so with these functions you should be able to make it work to control a servo for a switch machine.

  Lets look at your list of needed devices and I'll offer suggestions:  1) 20 x LED controller and driver, 2) 20 x turnout control with a servo motor, LED control and frog power controller, 3) 24 x block detector, 5) 20 x accessory controller,  6) 6 x RFID controller.

The suggestions here are going for low cost over ease of assembly.  for example using two Arduino pro mini at $2 each instead of just 1 Mega2560 at $10.  I'm also not including things like wire or mounting materials.  I assume you can figure that part of it out.  In practice, I'd recommend using one Mega, or even a Leonardo with shift registers or I2C GPIO chips and combining several things onto one uP, but here's as individual systems:

The LED controllers are dependent on how many LEDs you are planning to run off of each channel.  If it's only a couple, you can use a simple transistor connected to the micro controller of your choice and it will be dirt cheap.  The pn2222a is a common part costing 2 or 3 cents each and will easily handle 300-400 mA of current without breaking a sweat.  That's enough for about 20 standard LEDs.  On the other hand, if you're looking to power strings of strip lights, or large blocks with hundreds of LEDs on each channel, the cheapest, easy method is probably to just use off the shelf, 16 channel relay boards for about $15 each.  All told for 20 channel at 10 amps each, you need 2 pro mini's linked over I2C, 1 16 channel relay board and a 4 channel relay board, thats a total cost of about $25.  $35 will get you 32 channels.  

For the turnout controllers, using servos, you'll need a PWM channel for each servo.  While it could be done in software on GPIO pins, the easiest way to do this is with the Mega2560 with 15 PWM channels each. Pretty much you need 2 Mega2560's and a transistor fro each output.  so about $22 will get you 30 channels.  As a side note, you can combine the LED controllers and Switch controllers and use just the 2 Mega2560's here for a total of about $45 for 20 LEDs and 30 switches. The hook up would be a PWM pin feeding a transistor, which in turn feeds the servo, and a pair of GPIO pins feeding transistors to power the direction LEDs.  That leaves 26 IO pins free on each Mega 2560 to be used for I2C between them and LED control. Powering the frog adds in the expense of a relay to the mix, so that's $15 for every 8 turnouts, and the relay can be triggered off the same GPIO pin that powers the LEDs for indicators.  

Block detection depends how you want to do it.  If you're going with an isolated rail method, simply using the train's wheels to bridge an isolated rail, all you need is an opto-coupler for each block, a GPIO pin on a uP, and an offset power supply.  all told for 24 channels you'r looking at about $15 in parts, less if we manage to combine the functionality with some of the other devices.  If you want to use optical sensors  you'll add about $5 per channel.  I can't think of the guy's name right now, but someone even did a proof of concept about a year or so back and wrote up a nice post on it, using a computer using a camera and image procession for block detection.  

The Accessory controller is identical to the LED controller.  

For RFID, I have little direct experience, however you can expect you'll need an RFID sensor for each node, and an I2C or SPI bus free on a uP to read them.  I don't see why it would cost more than $5 per channel.  

Putting it all together, you have a need for 80 Digital outputs (20 LED, 20 Accessory, 40 turnout indicator/frog power) 20 Analog outputs, and 24 inputs (block detectors), plus a number of I2C or SPI connected RFID readers.  I would do this with 2 Mega2560's linked together over I2C, which would give you most of the IO you need. You can make up the extra with an I2C I/O expander, shift registers, or a third Mega2560.  It all depends how much you want to deal with add on components. Going the expensive route of 3 Mega2560's you're looking at something around $120 in parts to do everything you want, with room to expand in the future.  

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653