Additional LCN Components

In previous posts I introduced the concept of the Layout Control Node, and described the basic components of a standard LCN. In this post I’ll introduce a few peripheral boards that greatly expand the reach and utility of a basic LCN.

What’s Missing?

Ports.

Model railroad hobbyists need two kinds of ports:

  • Digital Ports. These are ports used for digital (on or off) inputs and outputs. In input mode, digital ports read buttons, switches or other digital switching devices. In output mode, digital ports are the basic port type used for lighting (panel indicators, signals, layout lighting), small motors, and relays. Although most analog ports can be used as digital ports, I have other uses for analog ports so I do not generally use them digitally.
  • PWM Ports. A subset of digital ports, these produce a variable PWM signal. PWM produces a wave form that is on for part of the cycle and off for the rest. PWM devices are controlled by varying the relative on and off portions of the PWM wave. PWM is used for servos, for speed control of small motors and for lighting effects.

Everyone who works with Arduino or compatible microprocessors eventually runs into the twin limitations of Atmel microcontrollers: the number and variety of ports available, and the limited power handling capabilities of the microcontrollers.

Port counts vary by model. For the NANO (using the Atmel 328P processor), you have 13 digital ports, about half of which can be used for PWM (pulse width modulation). Plus you have 7 analog ports, 6 of which can be used as a digital port. However, if you use USB at all, you start down 2 digital ports.

If you are building an LCN along the lines suggested, then the radio costs you 5 pins: 3 shared SPI pins (D11, D12, D13) plus two pins used exclusively by the radio.

In any case, with USB serial and a radio active, only 6 digital pins remain, plus the analog pins. We’ll use two of the analog pins next.

Power to the Ports!

The solution to the pin shortage, some will tell you, is to use a MEGA! Gets a belly laugh out of me every time as I watch another one fall victim to high port count with no power to run anything.

All Atmel microcontrollers have the same current limitations: 200 mA max chip current, 20 mA max continuous current through ports allowing short term current draws up to 40 mA. But do the math; No more than 10 ports can be at full current at any given time; and if any port spikes over 20 when that is happening, the microprocessor will fry.

PWM Ports

One consequence is that you cannot safely run more than two servos using board power because they draw a lot of current. So if you want to use more than two servos for any purpose, you’ll need an external solution.

The best PWM port solution is the PCA9685 driver board, a chain-able board supporting 16 PWM ports per board at the cost of two analog ports (on a NANO). It’s a great trade.

PCA9685 PWM Controller

I’ve previously written about how to use these boards. What makes these the optimum PWM solution is

  • Each board is independently powered; board chains can share power, but you can choose to always provide independent power (which is what I recommend). PCA9685 boards are designed to handle high load devices like servos.
  • Code overhead on the microcontroller is minimal; most of the work is done by the PCA9685 chip.
  • PCA9685 boards communicate via I2C [2 wire interface], requiring two specific pins — on the NANO, pins A4 and A5.
  • The boards are readily available for about $5 each or less.

Accordingly, LCNs should rely on these for PWM ports.

The Analog Ports

If you are keeping track, you know we have 6 digital ports and 5 analog ports left. We could get 10 digital ports and one analog-only port out of that mix, but that still doesn’t give us much to work with.

If you want to do current-based block occupancy detection — who wouldn’t if its easy to do, and any good signal system will require it — then those analog ports are the resource you will need. Want to know how to do that? Here are some key posts: Block Occupancy Detection for DC and DCC, Part 1,Block Occupancy Detection for DC and DCC, Part 2, Block Occupancy Detection for DC and DCC, Part 3, Block Occupancy Detection for DC and DCC, Part 4 and High Density DCC Block Detection.

Digital Ports

The six remaining digital ports are a slim resource unless we can multiply them. Not only is multiplication possible, it can be done in a way that produces up to 256 input ports AND 256 output ports, plus the ability to distribute those ports physically around the layout. At the cost of 6 digital pins, its another great trade!

How is it done? The simplest and most economical way is to use a type of integrated circuit called a “shift register.” Shift registers are a staple of the Arduino world: see, for example, Serial to Parallel Shifting-Out with a 74HC595, and Parallel to Serial Shifting-In with a CD4021BE.

Five years ago I hand built my first shift register boards, and blogged about it in Adding Signals to the Test Loop and Adding Signals to the Test Loop, Part 2. In those posts you’ll see the value of using digital port boards even on a tiny test layout.

I think you’ll also see from the earlier blog posts that hand-creating boards using these IC’s is somewhat painful. So I set out to see “how high is up” if I wanted to create a printed circuit board (PCB) and have some produced. Given my layout plans, I could easily justify a couple dozen output boards, if not more.

My Solution? Have PCB’s Made!

Having PCB’s made takes care of the wiring problem and ensures board consistency (hard to do with hand made boards). The easiest way to prototype is with “through hole” parts that are easy to manually solder. Small quantities of parts are easy to obtain (I use Digikey), though the cost per item is relatively high when only buying a few.

Back then I discovered a Shenzen, China company PCBway that specializes in PCB prototyping and low volume PCB production. Their core specialization is small batch PC board manufacturing, with very fast turn- arounds on small runs (a week to 10 days from order to delivery in the US). They also do full automated assembly and other services. I have a new project in progress with them and will be writing more about that in a future post.

Its beyond the scope of this post to explain the process of creating a PCB. For those who want to explore this avenue, a few pointers:

  • You’ll need PCB design program that can produce Gerber files. A good choice for beginners is Fritzing. A lot of professional designers use Autodesk’s Eagle which is available in a free edition.
  • Plan to spend many hours learning the tools before you can produce anything useful. Good tutorials are readily available online.
  • Mistakes are expensive so triple check your work to make sure your circuit is complete and will function as intended. There’s always some math involved, so validate it to make sure you have selected the right parts.

A more recent video update shows the boards I made in action running layout lighting, signals and crossings:

Can’t I Buy Something?

Yes.

You can buy something designed and manufactured by a model railroader — me — that is exactly what you need. I’m bringing up a separate site with the line of products you are looking for. The first available products are digital input and output boards (includes an Arduino library that simplifies use) as described in this and other posts.

DNOU8 for digital output ports. The new duinoNodes are stackable with pin headers and include other improvements over my original design. Currently in production and available in about 30 days.

Stop by the Lew’s Duino Gear site at beaglebay.com/duinogear/ to see what is available now and what will be available in the coming months.

Coming next.

I’m way behind — as far as I’m concerned, 2020 never happened (talk about wishful thinking) — and am determined to catch up. So stay tuned.

Leave a Reply

Your email address will not be published. Required fields are marked *