Model Railway - DCC Command Station Using Arduino: : 3 Steps

Updated August 2018 - see new Instructable:https://www.instructables.com/id/Model-Railroad-DC...

Update 28th April 2016:Now 16 turnout / points control capability to Command Station. The turnouts T1 - T8 are available via 'B' keyThe turnouts T9 - T16 are available via 'C' key

Update 10th March 2016:

Now added 8 turnout / points control capability to Command Station. The Arduino code has been updated accordingly using the NMRA standard packet for turnouts (also based on a study of Lenz / Atlas Compact data packets for turnout control).

The turnouts T1 - T8 are available via 'B' key

See instructable on the data packet receiver circuit used and Arduino code required.

Update 18th Jan 2016:

I have added a current sense resistor (1k5 ohm) and capacitor (10 uf) to the circuit and amended the Arduino code to cut off power when a peak current of > 3200 mAmps is detected. The H-bridge spec states an output sense current of 377 uA per 1 Amp in the load.

The 1.5 k ohm resistor will deliver 0.565 volts per Amp on the analog pin 6. With 1023 steps on the analog input, this gives 0.565 * 1023 / 5 = 116 per Amp load.

A = 100 * (analogRead(AN_CURRENT)) / 116;A = A * 10; (to give result in milliamps)

The load current in milliamps is displayed on the TFT

The full 4x4 keyboard includes F1 to F8 functions and another 10 locos (1-19) through the '#' key (to add 10 to the numeric keys starting from loco 10).

The arduino code includes the NMRA standard for instruction bytes.

See link

http://www.nmra.org/sites/default/files/s-9.2.1_20...

(page 6 is of particular relevance)

The packets are arranged according to number of speed steps, long / short address and Function Group instructions.

All instruction bytes are preceded by a preamble of '1' bits 11111111 (or idle packet) followed by;

e.g. A 4 byte address 0 00000011 0 00111111 0 10000011 0 10111111

equates to loco 3, 128 speed steps, forward direction and speed step 3 (the end byte is the error check XOR)

e.g A 3 byte address 0 00000011 0 10010000 0 10110011

equates to loco 3, function group 1, FL lights on plus XOR byte ( a '0' bit separates each byte)

See enclosed demonstration video for loco 12.

The functions F1 - F8 are available via 'A' key, DIR ('*' key = direction) FL ('0' key = lights) and key '#' gives locos 10 to 19 on the numeric keypad. The 'D' key is now used for an 'Emergency STOP'.

Thanks to various providers on the web for sources of DCC information and Arduino code.

In particular, this project was inspired by Michael Blank and his 'Simple DCC - a command station'

http://www.oscale.net/en/simpledcc

4x4 Matrix Array 16 Key Membrane Switch Keypad (ebay) £1.75

2.2 inch 240x320 Serial SPI TFT LCD Display Module (ebay) £7.19

UNIVERSAL 12V 5A 60W POWER SUPPLY AC ADAPTER (ebay) £6.49

Nano V3.0 For Arduino with CH340G 5V 16M compatible ATmega328P (ebay) 2 x £3.30 = £6.60

Motor Driver Module LMD18200T for Arduino R3 (ebay) £6.99

Connectors, wire, vero board, potentiometer approx £3.50

Total £32.52

The basic command station without tft screen and 1 x nano would be £22.03

[Note : It is possible to add a memory card to the TFT display and amend code to display images of selected engines, although the library codes must be edited down to create more memory for the sketch. Current sketch size is at a maximum for the TFT Arduino Nano]

The original Arduino code by Michael Blank was for one engine, forward / reverse only with no function control, no keypad and no display.

I have modified the code to include 1 - 19 engines, a display screen, direction, lights, 8 functions, emergency stop and auto current limit.

The LMD18200T bridge can carry up to 3 amps which makes it suitable for all scales including G-scale (garden trains). The mains power supply and electronics are suitable for indoor use only unless you can make it all weather proof. I have the command station in the summer house with rail connecting wires running out through the wall to the track.

Tag » Arduino Dcc Train Controller