Wiring signals to an Arduino

Give your signals to an Arduino board: Locodex assigns the pins, checks what the board can carry, and gives you the pin sheet, a wiring diagram, the parts to buy and the sketch to upload.

Signalling: Arduino wiring & code turns the signals on your plan into a board you can build. Add an Arduino, give it its part of the plan, and Locodex assigns a pin to every lamp, detector and turnout, checks the pins, current and memory the board has, and writes the sketch. Upload it and the board runs its signals on its own, with no computer attached, using the same signal logic as the simulator.

It's Pro (free for everyone during the open beta). Placing signals, detection, the signal table and the simulator stay free.

It's signalling logic for a model railway, not a real interlocking: signals follow block occupancy and how the turnouts are set, with no route setting or locking. Solenoids and motors draw far more than a pin can give: the pin sheet never wires one straight to a pin, and nor should you.

Boards

#

The panel is on the Layout tab, under Signalling. Pick a board and press Add a board:

BoardFree pinsGood for
Arduino Uno17About four signals and their blocks on its own pins; many more with a shift register
Arduino Nano17The same as an Uno, smaller
Arduino Mega 256067A station's worth of signals, blocks and turnouts

D0 and D1 are the USB serial and are never used; D13 is left free too unless you untick Keep D13 free (the board's own LED blinks on it at reset). A layout can have several boards. Each board runs its own part of the plan: boards don't talk to each other, so a signal on one board can't see a block or a turnout another board reads. The checks tell you when that happens.

What a board runs

#
  • Signals it runs: click a signal to put it on the board (or take it off). A signal is on one board at a time. Add the other… puts every signal no board runs yet on this one.
  • Add what they need adds the detected blocks its signals protect and the turnouts their ways pass through. You can also read another block, or stop reading one.
  • Turnouts: for each one, how the board knows how it's set:
ChoiceWiring
Read its position (a contact)A contact on the turnout or its motor (a microswitch, a Tortoise's contacts) to a pin and to ground. Closed means the second road. The turnout is thrown some other way: by hand, or by DCC.
Servo, from a panel switchA toggle switch on your panel sets it; the board moves the servo slowly and lets go once it's there. Set the servo's angle for each road.
Stall motor on a relay, from a panel switchThe board switches a relay module, and the relay drives the motor.
Solenoid (twin coil) through a driver, from a panel switchThe board fires one coil for a quarter of a second through a MOSFET or relay driver, fed by a capacitor discharge unit.

A turnout no board reads is taken as set the way the plan shows it. A turnout with more than two roads (a three-way, a slip) can be read from two contacts, but not driven.

Lamps and driver chips

#

Say whether your signals are common cathode (the shared wire to ground) or common anode (the shared wire to 5 V), and the current through each lamp (5 mA is plenty for a model signal). The pin sheet gives the resistor for each lamp, sized so it never takes more.

A French cible has more lamps than a generic signal (up to seven: the carré's red, the green, the sémaphore's red, the yellow, the œilleton and the rappel's two yellows), each on its own pin or output. The pin sheet and the sketch name each one by what it's for (C1 carré red lamp, PIN_C1_OEILLETON), and a carré violet's violet lamp gets its resistor like a white one. The flashing aspects (feu jaune clignotant, feu rouge clignotant, ralentissement and rappel 60) are flashed by the board itself, once a second, with no extra wiring; the current budgets count a flashing lamp as lit.

When the lamps outgrow the pins, add a driver chip:

  • 74HC595 chain: 8 lamps per chip on just 3 pins, chained for more. Best at 6 mA a lamp or less.
  • PCA9685: a 16-channel board on the I2C pins, for servos or lamps.

Assigning the pins

#

Assign pins gives every connection a pin: detectors and contacts on the analog row first, lamps from D2 up, the shift register's three pins first of all. It's always the same for the same plan, and it never moves what's already assigned, so adding a signal doesn't rewire the rest. Re-assign all packs everything afresh, for instance after adding a driver chip.

Once the board is soldered, press Lock all: nothing will ever move those pins again. A pin you choose by hand in the pin sheet is locked too.

What it carries shows the pins used, each driver chip's outputs, the current through the board when the signals light the most lamps at once, and roughly how much memory the sketch needs.

The pin sheet, the wiring diagram and the parts

#
  • Pin sheet: which wire goes to which pin, in pin order, with each lamp's resistor and a wire colour to make it easy to check. Change any pin here, lock or unlock it, save it as CSV or print it. Below it: how to wire the power and the grounds, and what to watch for.
  • Wiring diagram: the board, a wire from each pin to its resistor and lamp, detector, contact, switch, servo or driver, and each chip's outputs. Black on white, to print and check your wiring against, or save as SVG.
  • Parts: the boards, chips, resistors by value, signals, detectors and turnout parts appear in the Bill of Materials, under the track.

The sketch

#

Sketch shows the code, file by file, to read, copy or download, and Download .zip gives you the whole folder. Unzip it, open the .ino in the Arduino IDE, choose your board under Tools › Board, pick the port and press Upload. A sketch with servos on the board's pins uses the Servo library, which comes with the Arduino IDE (with arduino-cli, install it).

What's in it:

FileWhat it is
….inoThe sketch: it includes the rest and runs it.
layout_config.hYour board's part of the plan: every pin, signal, block and turnout named as on the plan (PIN_S1_RED, BLOCK_B3), and the tables the signal logic runs. Generated: change the plan and download it again.
locodex_kernel.hThe signal logic, the same as the simulator's and tested against it.
locodex_io.h, locodex_runtime.hReading detectors and contacts, lighting lamps, throwing turnouts.

Every lamp lights in turn for a moment when the board starts, so a wiring mistake shows before the first train. A flashing lamp flashes once a second, timed from the board's clock while everything else carries on (the sketch never waits for it). Open the Serial Monitor at 115200 baud to see what the board sees: it starts with HELLO locodex-sig 1 1.1.0 and a config code (the same one as at the top of the sketch, so you can tell which version of your plan a board runs), then a line each time a block is occupied or cleared, a turnout moves or a signal changes.

Detectors go to a pin and to ground, and pull the pin to ground when they see a train. A block stays occupied for half a second after its detector last saw one (dirty wheels), three seconds for a reed switch, which only closes as the magnet passes. On DCC, use detectors with an opto-isolated output.

Checks

#
CheckWhat to do
Signals that aren't on a boardAdd them to one: they won't light.
A signal can't see a blockThe block is read by another board, or by none. Read it on this board too (the detector's output can go to both boards, grounds joined).
A board takes a turnout as set on the planAdd the turnout to the board, to read or drive it.
A signal can't see the next signalIt's on another board, so this one shows caution at best towards it.
A board needs more pinsAdd a 74HC595 chain or a PCA9685, use a Mega, or move some signals to a second board.
Connections with no pinAssign pins (or Re-assign all when they don't fit around the others).
A pin a connection can't useA pin the board doesn't have (after changing the kind of board), one reserved, or a detector on a driver chip, which only drives outputs.
Too much currentLower the lamp current, or move lamps onto a driver chip.
More than two servosGive them their own 5 V supply.
A block with no detectorChoose one in Signalling.

Without the license

#

After the beta, a layout's wiring stays in the layout. Opened without the license it's shown as saved, read-only: the boards, the pin sheet and the wiring diagram, but no sketch. See Core and pro features.